-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/cgo: use --no-gc-sections if available #53028
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
Conversation
This PR (HEAD: b9ef800) has been imported to Gerrit for code review. Please visit https://go-review.googlesource.com/c/go/+/407814 to see it. Tip: You can toggle comments from me using the |
Message from Motiejus Jakštys: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/407814. |
Message from Bryan Mills: Patch Set 1: Run-TryBot+1 Code-Review+1 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/407814. |
Message from Gopher Robot: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/407814. |
Message from Gopher Robot: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/407814. |
Message from Cherry Mui: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/407814. |
Message from Gopher Robot: Patch Set 1: TryBot-Result-1 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/407814. |
Message from Ian Lance Taylor: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/407814. |
b9ef800
to
9e1d5b2
Compare
This PR (HEAD: 9e1d5b2) has been imported to Gerrit for code review. Please visit https://go-review.googlesource.com/c/go/+/407814 to see it. Tip: You can toggle comments from me using the |
Message from Motiejus Jakštys: Patch Set 1: (2 comments) Please don’t reply on this GitHub thread. Visit golang.org/cl/407814. |
Message from Bryan Mills: Patch Set 2: Run-TryBot+1 Code-Review+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/407814. |
Message from Gopher Robot: Patch Set 2: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/407814. |
Message from Gopher Robot: Patch Set 2: TryBot-Result+1 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/407814. |
Message from Cherry Mui: Patch Set 2: Code-Review+2 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/407814. |
zig cc passes `--gc-sections` to the underlying linker, which then causes undefined symbol errors when compiling with cgo but without C code. Add `-Wl,--no-gc-sections` to make it work with zig cc. Minimal example: **main.go** package main import _ "runtime/cgo" func main() {} Run (works after the patch, doesn't work before): CC="zig cc" go build main.go Among the existing code, `src/runtime/testdata/testprognet` fails to build: src/runtime/testdata/testprognet$ CC="zig cc" go build . net(.text): relocation target __errno_location not defined net(.text): relocation target getaddrinfo not defined net(.text): relocation target freeaddrinfo not defined net(.text): relocation target gai_strerror not defined runtime/cgo(.text): relocation target stderr not defined runtime/cgo(.text): relocation target fwrite not defined runtime/cgo(.text): relocation target vfprintf not defined runtime/cgo(.text): relocation target fputc not defined runtime/cgo(.text): relocation target abort not defined runtime/cgo(.text): relocation target pthread_create not defined runtime/cgo(.text): relocation target nanosleep not defined runtime/cgo(.text): relocation target pthread_detach not defined runtime/cgo(.text): relocation target stderr not defined runtime/cgo(.text): relocation target strerror not defined runtime/cgo(.text): relocation target fprintf not defined runtime/cgo(.text): relocation target abort not defined runtime/cgo(.text): relocation target pthread_mutex_lock not defined runtime/cgo(.text): relocation target pthread_cond_wait not defined runtime/cgo(.text): relocation target pthread_mutex_unlock not defined runtime/cgo(.text): relocation target pthread_cond_broadcast not defined runtime/cgo(.text): relocation target malloc not defined With the patch both examples build as expected. @ianlancetaylor suggested: > It would be fine with me if somebody wants to send a cgo patch that passes -Wl,--no-gc-sections, with a fallback if that option is not supported. ... and this is what we are doing. Tested with zig 0.10.0-dev.2252+a4369918b This is a continuation of CL 405414: the original one broke AIX and iOS builds. To fix that, added `unknown option` to the list of strings under lookup. Fixes golang#52690
9e1d5b2
to
86f227a
Compare
This PR (HEAD: 86f227a) has been imported to Gerrit for code review. Please visit https://go-review.googlesource.com/c/go/+/407814 to see it. Tip: You can toggle comments from me using the |
Message from Motiejus Jakštys: Patch Set 2: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/407814. |
Message from Ian Lance Taylor: Patch Set 3: Run-TryBot+1 Auto-Submit+1 Code-Review+1 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/407814. |
Message from Gopher Robot: Patch Set 3: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/407814. |
Message from Gopher Robot: Patch Set 3: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/407814. |
Message from Gopher Robot: Patch Set 3: TryBot-Result-1 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/407814. |
zig cc passes `--gc-sections` to the underlying linker, which then causes undefined symbol errors when compiling with cgo but without C code. Add `-Wl,--no-gc-sections` to make it work with zig cc. Minimal example: **main.go** package main import _ "runtime/cgo" func main() {} Run (works after the patch, doesn't work before): CC="zig cc" go build main.go Among the existing code, `src/runtime/testdata/testprognet` fails to build: src/runtime/testdata/testprognet$ CC="zig cc" go build . net(.text): relocation target __errno_location not defined net(.text): relocation target getaddrinfo not defined net(.text): relocation target freeaddrinfo not defined net(.text): relocation target gai_strerror not defined runtime/cgo(.text): relocation target stderr not defined runtime/cgo(.text): relocation target fwrite not defined runtime/cgo(.text): relocation target vfprintf not defined runtime/cgo(.text): relocation target fputc not defined runtime/cgo(.text): relocation target abort not defined runtime/cgo(.text): relocation target pthread_create not defined runtime/cgo(.text): relocation target nanosleep not defined runtime/cgo(.text): relocation target pthread_detach not defined runtime/cgo(.text): relocation target stderr not defined runtime/cgo(.text): relocation target strerror not defined runtime/cgo(.text): relocation target fprintf not defined runtime/cgo(.text): relocation target abort not defined runtime/cgo(.text): relocation target pthread_mutex_lock not defined runtime/cgo(.text): relocation target pthread_cond_wait not defined runtime/cgo(.text): relocation target pthread_mutex_unlock not defined runtime/cgo(.text): relocation target pthread_cond_broadcast not defined runtime/cgo(.text): relocation target malloc not defined With the patch both examples build as expected. @ianlancetaylor suggested: > It would be fine with me if somebody wants to send a cgo patch that passes -Wl,--no-gc-sections, with a fallback if that option is not supported. ... and this is what we are doing. Tested with zig 0.10.0-dev.2252+a4369918b This is a continuation of CL 405414: the original one broke AIX and iOS builds. To fix that, added `unknown option` to the list of strings under lookup. Fixes #52690 Change-Id: Id6743e1e759a02627b0fc6d2ac89bb69b706d04c GitHub-Last-Rev: 86f227a GitHub-Pull-Request: #53028 Reviewed-on: https://go-review.googlesource.com/c/go/+/407814 Reviewed-by: Cherry Mui <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]>
This PR is being closed because golang.org/cl/407814 has been merged. |
zig cc passes
--gc-sections
to the underlying linker, which thencauses undefined symbol errors when compiling with cgo but without C
code. Add
-Wl,--no-gc-sections
to make it work with zig cc. Minimalexample:
main.go
Run (works after the patch, doesn't work before):
Among the existing code,
src/runtime/testdata/testprognet
fails tobuild:
With the patch both examples build as expected.
@ianlancetaylor suggested:
... and this is what we are doing. Tested with zig
0.10.0-dev.2252+a4369918b
This is a continuation of CL 405414: the original one broke AIX and iOS
builds. To fix that, added
unknown option
to the list of stringsunder lookup.
Fixes #52690