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

Comments

Projects
None yet
5 participants
@sigmonsays
Copy link

commented Jul 28, 2017

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

This comment has been minimized.

Copy link
Contributor

commented Jul 28, 2017

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

@hirochachacha

This comment has been minimized.

Copy link
Contributor

commented Jul 29, 2017

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

@sigmonsays

This comment has been minimized.

Copy link
Author

commented Aug 21, 2017

$ 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

This comment has been minimized.

Copy link
Author

commented Aug 21, 2017

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

This comment has been minimized.

Copy link
Contributor

commented Aug 25, 2017

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.
You can’t perform that action at this time.