Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/link: -X fails with periods #21206

Closed
sigmonsays opened this issue Jul 28, 2017 · 5 comments
Closed

cmd/link: -X fails with periods #21206

sigmonsays opened this issue Jul 28, 2017 · 5 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@sigmonsays
Copy link

what used to work in go 1.7.3 no longer works in go 1.8

What version of Go are you using (go version)?

go version go1.8.3 linux/amd64

What operating system and processor architecture are you using (go env)?

$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/sig/gopath"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build896116486=/tmp/go-build"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

run test_golink.sh (see below for script)

What did you expect to see?

"Version = 1.0.0"

What did you see instead?

"Version = dev"

test_golink.sh script

$ cat test_golink.sh

rm -rf gopath
mkdir gopath
cd gopath
export GOPATH=$HOME/gopath
mkdir -p src/mypackage.git/hello

cat << EOF > src/mypackage.git/config.go
package mypackage
var Version = "dev"
EOF

cat << EOF > src/mypackage.git/hello/main.go
package main

import (
"fmt"
"mypackage.git"
)

func main() {
fmt.Printf("version = %s\n", mypackage.Version)
}
EOF

go clean -i mypackage.git
go install -ldflags "-X mypackage%2egit.Version=1.0.0" mypackage.git mypackage.git/hello
go install mypackage.git/hello
./bin/hello

@ianlancetaylor
Copy link
Contributor

What is the output of go tool nm bin/hello | grep Version ?

@bradfitz bradfitz added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Jul 28, 2017
@bradfitz bradfitz added this to the Go1.10 milestone Jul 28, 2017
@hirochachacha
Copy link
Contributor

Replace "%2e" with ".", then your problem will be solved.

@sigmonsays
Copy link
Author

$ go tool nm bin/hello | grep Version
  4fa4e0 D mypackage%2egit.Version
  4b0a48 R mypackage%2egit.Version.str
  4fa510 D runtime.buildVersion
  516ba8 D runtime.processorVersionInfo

@sigmonsays
Copy link
Author

It seems like replacing %2e with . works but I dont understand why. I can see how it works logically but am not sure if this is expected behavior given the ambiguity.

@ianlancetaylor
Copy link
Contributor

This changed in 1.8 because of #16710. The new approach seems better, so I don't see any reason to revert to the old one. This should probably have been in the 1.8 release notes, but I guess we forgot.

Closing because I don't think there is anything to do.

@golang golang locked and limited conversation to collaborators Aug 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants