go: cmd/link: external linking does not link dynamic libraries without cgo
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.
$ godev test crypto/x509 -ldflags=-linkmode=external
# crypto/x509.test
/Users/valsorda/go/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
Undefined symbols for architecture x86_64:
"_CFArrayGetCount", referenced from:
_crypto/x509/internal/macos.x509_CFArrayGetCount_trampoline in go.o
"_CFArrayGetValueAtIndex", referenced from:
_crypto/x509/internal/macos.x509_CFArrayGetValueAtIndex_trampoline in go.o
"_CFDataGetBytePtr", referenced from:
_crypto/x509/internal/macos.x509_CFDataGetBytePtr_trampoline in go.o
"_CFDataGetLength", referenced from:
_crypto/x509/internal/macos.x509_CFDataGetLength_trampoline in go.o
"_CFDictionaryGetValueIfPresent", referenced from:
_crypto/x509/internal/macos.x509_CFDictionaryGetValueIfPresent_trampoline in go.o
"_CFEqual", referenced from:
_crypto/x509/internal/macos.x509_CFEqual_trampoline in go.o
"_CFNumberGetValue", referenced from:
_crypto/x509/internal/macos.x509_CFNumberGetValue_trampoline in go.o
"_CFRelease", referenced from:
_crypto/x509/internal/macos.x509_CFRelease_trampoline in go.o
"_CFStringCreateWithBytes", referenced from:
_crypto/x509/internal/macos.x509_CFStringCreateWithBytes_trampoline in go.o
"_SecItemExport", referenced from:
_crypto/x509/internal/macos.x509_SecItemExport_trampoline in go.o
"_SecPolicyCopyProperties", referenced from:
_crypto/x509/internal/macos.x509_SecPolicyCopyProperties_trampoline in go.o
"_SecTrustSettingsCopyCertificates", referenced from:
_crypto/x509/internal/macos.x509_SecTrustSettingsCopyCertificates_trampoline in go.o
"_SecTrustSettingsCopyTrustSettings", referenced from:
_crypto/x509/internal/macos.x509_SecTrustSettingsCopyTrustSettings_trampoline in go.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
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 via go:cgo_import_dynamic
.
See also https://golang.org/cl/248333. /cc @cherrymui @thanm @randall77
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15 (9 by maintainers)
Thanks. Yeah, we could make it a better and clearer error, or no-op.
@zchee the original issue is fixed. The fix was not elegant but unfortunately I couldn’t think of a better way. Closing. Thanks.
If you build a c-archive, when you link it into the final executable, try passing
-framework CoreFoundation -framework Security
flags to the C linker.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.
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”. https://github.com/shenron/x509-go-ffi