-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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 doesn't work for vendored packages #19000
Labels
Comments
The name of the package, as seen by the linker when applying the -X flagis
the full path name realtive to GOPATH
…On Thu, 9 Feb 2017, 10:32 Adam Sunderland ***@***.***> wrote:
What version of Go are you using (go version)?
go version go1.7.3 linux/amd64
What operating system and processor architecture are you using (go env)?
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/iterion/dev/go"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0
-fdebug-prefix-map=/tmp/go-build201245685=/tmp/go-build
-gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="0"
What did you do?
Run this build command with github.com/iterion/remotepkg in the vendor
directory:
note: package above doesn't actually exist yet, but I can create it if
needed for demonstration purposes.
go build -a -installsuffix cgo -o test -ldflags "-X github.com/iterion/remotepkg.timestamp=`date <https://github.com/iterion/remotepkg.timestamp=date> -u '+%Y-%m-%d_%I:%M:%S%p'`" .
main.go
package main
import (
"github.com/iterion/remotepkg"
)
func main() {
remotepkg.PrintEnv()
}
remotepkg.go
package remotepkg
import (
"log"
)
var timestamp string
func PrintEnv() {
log.Println(timestamp)
}
What did you expect to see?
Expect ./test to print current time.
What did you see instead?
Nothing is printed.
If the remote package is not in the vendor dir but does exist in your
gopath in an expected place then the current time is correctly printed.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#19000>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAcA_mvXooFWVIGkbM9QJbEfiI4rKxUks5ralB2gaJpZM4L7gjB>
.
|
@davecheney thanks
which correctly prints Is there documentation for this anywhere (I struggled to find any aside from stackoverflow)? I'd be up for trying to update it. Closing this in the meantime as it seems there is no actual issue. |
Not that I know of I'm afraid, this is a side effect of the language way
vendoring is implemented
…On Thu, 9 Feb 2017, 10:57 Adam Sunderland ***@***.***> wrote:
@davecheney <https://github.com/davecheney> thanks
I tested this, given main.go is in github.com/iterion/test I changed
change it to
"-X github.com/iterion/test/vendor/github.com/iterion/remotepkg.timestamp=time"
which correctly prints time.
Is there documentation for this anywhere (I struggled to find any aside
from stackoverflow)? I'd be up for trying to update it.
Closing this in the meantime as it seems there is no actual issue.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#19000 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAAcA-LtUqhJYta0AYFb3YgkR8B25kFCks5ralZ9gaJpZM4L7gjB>
.
|
Ian updated the docs to suggest 'go tool nm' to find the correct symbol
name, but due to various corner cases, that docs change is rolled back.
In practice, though, you can still use the 'go tool nm' command to figure
out the correct symbol name.
Please see https://golang.org/cl/34791 for the corner cases and the
(reverted) docs on how to use "go tool nm".
|
minux
changed the title
Go ldflags -X doesn't work for vendored packages
cmd/link: -X doesn't work for vendored packages
Feb 9, 2017
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
What version of Go are you using (
go version
)?go version go1.7.3 linux/amd64
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/iterion/dev/go"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build201245685=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="0"
What did you do?
Run this build command with
github.com/iterion/remotepkg
in the vendor directory:note: package above doesn't actually exist yet, but I can create it if needed for demonstration purposes.
main.go
remotepkg.go
What did you expect to see?
Expect
./test
to print build time.What did you see instead?
Nothing is printed.
If the remote package is not in the vendor dir but does exist in your gopath in an expected place then the build time is correctly printed.
The text was updated successfully, but these errors were encountered: