-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: external linking does not link dynamic libraries without cgo #42459
Comments
Thanks for reporting. I can reproduce on the current tip with I agree it is related to the LDFLAGS. One way is that you could add
to one of the non-cgo files (e.g. crypto/x509/internal/macos/corefoundation.go). (You have to do one flag a line, sorry.) cc @ianlancetaylor about using cgo_ldflag in non-cgo-generated files. (It is still limited to the standard library by the compiler.) |
Thank you for the workaround, the CL passed with that.
I assume this should be just temporary and we'll fix it in Go 1.17, or is
this a fundamental issue of the linking strategy?
|
I don't know there is anyway for the linker to add those flags automatically in general. (Another possibility is to pass them in the command line, as From Ideas welcome :) |
If we're going to use |
@iamoryanmoshe Can you explain how to update it? Update following code in noder.go? Thanks.
|
@FiloSottile @cherrymui Still repro? I can't so I think related |
Hello @zchee I don't know if it can help you, but I have the same problem when I try to call a cgo lib with a call to "crypto/x509". |
If you build a c-archive, when you link it into the final executable, try passing Since the final linking step is not controlled by the Go toolchain, unfortunately I don't think there is anything we could do to help. |
@zchee the original issue is fixed. The fix was not elegant but unfortunately I couldn't think of a better way. Closing. Thanks. |
I try to build but get an error that no such directory Security I used cmake target_link_options which makes -framework CoreFoundation -framework Security to become -framework CoreFoundation Security that makes that silly error. Solution is: target_link_options(target_name BEFORE PRIVATE "SHELL:-framework Security") |
Is this really fixed? I'm still able to reproduce the problem with Go 1.17.2 darwin/amd64. CGO_ENABLED=0 go test -c -ldflags=-d crypto/x509
|
@t0rr3sp3dr0 why do you pass the -d flag? This issue is not about the -d flag and it is expected that the -d flag won't work here. |
We have a service written in Go and it is statically built so it can run on any environment. Previously we were only building for Linux and that still works, but I tried to compile it on a Mac and found this problem. I know we don't have true static binaries on Mac, but shouldn't builtin packages of Go support this flag instead of causing a linking error? If that's unsupported on macOS, shouldn’t the flag be NOP or give the user a warning? |
Thanks. Yeah, we could make it a better and clearer error, or no-op. |
Change https://golang.org/cl/365658 mentions this issue: |
On platforms where we use libc for syscalls, we dynamically link with libc and therefore dynamic linking cannot be disabled. Exit early when -d is specified. Update #42459. Change-Id: I05abfe111df723b5ee512ceafef734e3804dd0a8 Reviewed-on: https://go-review.googlesource.com/c/go/+/365658 Trust: Cherry Mui <[email protected]> Run-TryBot: Cherry Mui <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Than McIntosh <[email protected]>
https://golang.org/cl/232397 removes the cgo implementation from crypto/x509, which was preserved just for test purposes.
In doing so it seems to have broken external linking.
https://storage.googleapis.com/go-build-log/14984eec/darwin-amd64-10_14_b0e9ceb1.log
I suppose the build was relying on the
#cgo LDFLAGS: -framework CoreFoundation -framework Security
line from the cgo file to bring in the dynamic libraries, even if it was not cgo to use them, as they were used viago:cgo_import_dynamic
.See also https://golang.org/cl/248333. /cc @cherrymui @thanm @randall77
The text was updated successfully, but these errors were encountered: