-
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: can't dynamically import static CFString constants using the internal linker #71471
Comments
Change https://go.dev/cl/645235 mentions this issue: |
This is another instance of #61220. @cherrymui @ianlancetaylor you mentioned in there that go/src/crypto/x509/internal/macos/security.go Lines 72 to 80 in e81f715
(The types in macos/security.go are now unused and will be soon removed as part of CL 643277). |
I think we support data relocations (e.g. R_ADDR) to a dynamic import variable. So this is only a problem if you reference the variable (or address of it) directly from a function (including compiler-generated init function)? If you do something like
Would that work? Since
I'm also not sure I understand the linkname, and the different number of underscores... |
It does compile, but the variable doesn't point to the right location. I will investigate a bit more.
I also don't really understand why that's necessary. I took the linkname and the pointer mangling from the cgo generated code, which does something similar. Edit: I've removed the linkname from the reproducer, it is not necessary. |
I've simplified my reproducer to the following code: package main
// #cgo LDFLAGS: -framework CoreFoundation
// #include <CoreFoundation/CFString.h>
import "C"
//go:cgo_import_dynamic main.kCFErrorUnderlyingErrorKey kCFErrorUnderlyingErrorKey "/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation"
var kCFErrorUnderlyingErrorKey C.CFStringRef
func main() {
C.CFShow(C.CFTypeRef(kCFErrorUnderlyingErrorKey))
} With CL 645235 I managed to make it work if using |
Go version
go version devel go1.24-2b3b5305c6 Fri Jan 24 12:35:21 2025 +0100 darwin/arm64
Output of
go env
in your module/workspace:What did you do?
Execute the following code with
go run -ldflags=-linkmode=internal .
.Note that I'm using some C functions (
C.CFStringGetLength
andC.CFStringGetBytes
) to make the reproducer self-contained. What I really do is define all external functions usingcgo_import_dynamic
, which doesn't modify the failure described here.@golang/compiler
What did you see happen?
What did you expect to see?
The execution succeeds.
The text was updated successfully, but these errors were encountered: