-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/link: fails to link package having a .syso file when using external linker #33139
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
Change https://golang.org/cl/186417 mentions this issue: |
Emmm, if this fails, I wonder why cmd/go/testdata/script/cgo_syso_issue29253.txt works... |
#29253 is different because of Cgo and the
Relocations for package
Dissassembly for Cgo wrapper before relocations (from within the Go object file cited above), where you can clearly see the
Disassembly of final executable, after relocations (filtered):
|
Thanks. The difference is that in cmd/go/testdata/script/cgo_syso_issue29253.txt, the symbol in the syso is only referenced from C code, not Go code (including Go assembly). Here the symbol in the syso is directly called from Go assembly. In general, calling external functions directly from Go (including Go assembly) is discouraged. But I'm not sure we want to reject it here, given that internal linking works. But it is also possible that this is not a "supported" feature so we don't fix. As a workaround, you can force internal linking by passing |
This kind of direct access is not only advertised on the Go Wiki since 2014, but is an extraordinarily useful feature for executing performance-critical code that is not written in Go, and where the overhead of using cgo is to be avoided where possible. Yes -- internal linking works, but so does external linking with a
Sadly that is not a valid workaround:
|
Change https://golang.org/cl/198177 mentions this issue: |
This reverts CL 186417. Reason for revert: Broke darwin (10_14), linux (ppc), aix (ppc) Updates #33139 Change-Id: I8bf3c817a96a0e57e45754a097cea7062b2fcdfd Reviewed-on: https://go-review.googlesource.com/c/go/+/198177 Run-TryBot: Andrew Bonventre <andybons@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
Change https://golang.org/cl/198798 mentions this issue: |
Being able to inclue a .syso file in a package is great. A Go program using that package works well when that program is linked using the internal linker. Link is however broken when the that program is linked using the external linker, for example, because the Go program also uses cgo.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
This affects all go versions, including tip (at the time of submission).
What operating system and processor architecture are you using (
go env
)?This affects all GOOS/GOARCH pairs. I have tried it on darwin/amd64 and linux/amd64.
go env
OutputWhat did you do?
-ldflags='-linkmode=external'
, or by using cgo in the main package, where the external linker is then required.)Sample project follows...
Directory structure
To build the
test.syso
file on Linux using gcc,syso/asm/Makefile
syso/asm/test_darwin.s
syso/asm/test_linux.s
syso/test.go
syso/test.s
cmd/internal/main.go
cmd/external/main.go
What did you expect to see?
cmd/internal/main.go
(using internal link) andcmd/external/main.go
(using external link).What did you see instead?
cmd/internal/main.go
.cmd/external/main.go
with errorrelocation target XXX not defined
for each referenced global symbol in the imported package .syso, for example:The text was updated successfully, but these errors were encountered: