-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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/cgo: internal linker's implicit dependency on gcc_s #59735
Comments
cc @golang/compiler |
I think the internal linker knows about libgcc but it doesn't know about the existence of glibc (for one, one may use other libc implementations). It only sees glibc if there is a dynamic reference somewhere. Otherwise I think it doesn't even know to link against glibc, so the symbol remains undefined.
The short answer is no. The main purpose of internal linking is to support linking standard library packages that uses cgo (e.g. the net package, the race detector). It is already not the default link mode if any other cgo code is involved. We keep the support of the internal linking mode (probably a little beyond the standard library packages) but we don't put a lot effort in supporting C linking in general in the Go linker. I'd recommend using external linking mode when cgo is involved. Thanks. |
Is there a particular use case for internal linking that ought to be supported? |
I am working on #59666: this is one of the two known unit test failures when running Go unit tests with
The unit test compiles the following: https://github.com/golang/go/blob/go1.20.3/misc/cgo/test/test.go#L1506-L1528 with My goal, again, is to make all tests with |
It's fine to skip testing misc/cgo/test with -linkmode=internal in cases where it doesn't currently work. Offhand I'm not sure of the best way to detect the use of |
Thanks for your response, I will see if I can remove/disable the unit test for |
There is a precedent with Alpine: Lines 826 to 828 in 7c47a6b
I can do the same with |
What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Analysis
The resulting linker line when executed with
zig cc
is this:Looking at
_cgo_.o
:Comparing to
_cgo_.o
produced byCC=clang-16
(omitting the linker line for brevity):As we can see, the Zig internal linker has a problem linking this symbol when a specific DSO version is not requested.
Why does it work with clang/gcc?
In both cases (plain clang-16 and zig cc) nothing in the Go compiler line necessitates a versioned
memset
. The only symbol that is requesting memset is_x017.o
:However, in the working case, the
-lgcc_s
is also in the linker line. Which is asking for a versionedmemset
:... which results
_cgo_.o
to have a versioned relocation (is that the correct term?), which then Go internal linker is able to process.Summary
memset
.memset@GLIBC_2.2.5
because of a transitive dependency to-lgcc_s
._cgo_.o
does not request a versionedmemset
, it is not able to link the file, resulting inrelocation target memset not defined
.Questions:
The text was updated successfully, but these errors were encountered: