-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/link: linker produces invalid binaries on FreeBSD when cgo is used and linkflag -X passed twice #23273
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
Comments
This reproduces on linux amd64 with go 1.9.2 as well, here's a minimal version: package main
// int x = 42;
import "C"
var test string
func main() {
println(test)
} The relevant code is this, I think: go/src/cmd/link/internal/ld/data.go Lines 1097 to 1119 in 5476967
When called multiple times with the same symbol name, the second call will append the string value to main.test.str, as can be seen from objdump. objdump -t test.ok (single -X arg):
objdump -t test (two -X args):
Also the recorded address of main.test is made to no longer point to main.test.str, but to some inaccessible address, which triggers the panic. |
Change https://golang.org/cl/85835 mentions this issue: |
golang.org/cl/86915 will fix this. |
Change https://golang.org/cl/86915 mentions this issue: |
tl;dr: generated binary segfaults on init if both 1) uses cgo and 2) -X is passed twice in
-ldflags
go version
)?yes
go env
)?Using the following file
test.go
:I ran:
If I either remove the cgo usage in
test.go
or remove the duplicate-X
flag in the link flags, the problem goes away and the program runs successfully.The text was updated successfully, but these errors were encountered: