-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/link: panic on riscv64 with CGO enabled due to empty container symbol #72840
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
Comments
cc @golang/riscv64 |
When you say "handling of certain symbols", is it possible to be more specific? |
@golang/compiler |
Reading the error message, it looks like the error is from loading a symbol from an empty section in a C object. Perhaps we should just ignore it, especially that it is not a loadable section. Perhaps we can ignore the entire debug sections from C object? @thanm do you know if we use the debug info from C objects in internal linking mode? I think we probably don't. (It may be a good thing to do for the future. But that needs a good amount of effort beyond just loading the symbols. If currently we load the symbols but not doing anything with them, we may as well not load them at all.) |
From looking at the code, it does appear that we're loading up |
I attempted the following build process and still failed with the same reason: git clone https://github.com/golang/go
cd go
git checkout go1.24.1
cd src
./all.bash It is worth noting that I am using the following versions of gcc --version
# gcc (GCC) 15.0.1 20250114 (Red Hat 15.0.1-0)
ar --version
# GNU ar version 2.43.50.20250106 Please let me know if any additional details are required. |
I've been able to reproduce the issue in a VM with the images here. I used the Fedora-Cloud-Base-Generic-42.20250403-8635a3a5bfcd.riscv64.qcow2 image. I booted the image, installed gcc-15 and the distro supplied version of go(go1.24rc1). I then cloned Go and built the master branch (ecc06f0). I was able to reproduce the issue with the following simple test case.
Adding some logs into ldelf.go I can see the panic seems to be caused by the presence of the symbol .Letext0 in the _cgo_export.o object file. IIUC correctly, the failure occurs because _cgo_export.o contains the symbol .Letext0 even though the size of its text section is 0. When I build the same reproducer on my VF2 which has gcc-13.3.0 the .Letext0 is not present in the _cgo_export.o file. Nor is it present when I build with go1.24rc1 on an X86 VM running Fedora 42 and gcc-15. It appears the .Letext0 symbol is present in the symbol table because it is referenced by a data directive in the assembly code generated by gcc-15, i.e., in the disassembly of _cgo_export.s I see
There is a comment in the code that generates the panic suggesting that the check might be too strict and could be relaxed. So I tried disabling the check locally. It fixed the panic but the link of my test program still failed due to unresolved symbols. I'll try to dig a little deeper to understand why that is. |
Here are the linker errors I'm getting
If I modify the existing check for riscvc64 and s390 to also skip symbols with a ".LVUS" prefix I'm able to link the simple test program above. I'll try a full test run with these two changes applied on Fedora42. |
To summarize, by
I'm able to get a clean test run of main on a Fedora42 riscv64 VM (with gcc-15). I can submit a patch but it's not clear to me whether removing the first check in Loader.AddInteriorSym is the correct thing to do. As a reminder, the symbol triggering this panic is .Letext0 in _cgo_export.o (b002/_x001.o) which has a text section of size 0. @cherrymui, @thanm any advice on how to proceed here? I still have the VM so if you need any further information, please let me know. |
This fails with a symbol error. Error reported upstream in golang/go#72840
This fails with a symbol error. Error reported upstream in golang/go#72840
This fails with a symbol error. Error reported upstream in golang/go#72840
A few updates. Unsurprisingly, I can build the test program shown above with
I've also uploaded two object files that contain the symbols that are upsetting the linker.
|
Change https://go.dev/cl/668275 mentions this issue: |
Please ignore that first patch. It's been abandoned. A new patch is coming shortly. |
Change https://go.dev/cl/668276 mentions this issue: |
Go version
go version go1.24.1 linux/riscv64
Output of
go env
in your module/workspace:What did you do?
Built Go (version 1.24.1) on a riscv64 system on Fedora 42 with CGO enabled. Ran the full Go check suite and also attempted a minimal reproduction by isolating tests in the
internal/poll
directory. In the minimal test setup, I removed others test files ininternal/poll
and only the test fileserror_linux_test.go
,error_stub_test.go
, anderror_test.go
remained. Furthermore, I experimented with a workaround by commenting out the following code inerror_test.go
:and trying to run
cd /builddir/build/BUILD/golang-1.24.1-build/go/src ./run.bash --no-rebuild -v -v -v -k internal/poll
What did you see happen?
The build fails during the linking phase with a panic. Key parts of the error log include:
This panic in the linker (
cmd/link/internal/loader.(*Loader).AddInteriorSym
) prevents the test suite from completing. The workaround of commenting out the code inerror_test.go
allowed the tests to pass, indicating that the issue might be related to the handling of certain symbols.And I also tried with CGO disabled(by set CGO_ENABLED=0), test complete successfully without panics.
full build log: http://openkoji.iscas.ac.cn/kojifiles/work/tasks/8787/7038787/build.log
golang spec file: https://src.fedoraproject.org/rpms/golang/blob/rawhide/f/golang.spec
What did you expect to see?
I expected the Go build and test suite to complete successfully without panics, even with CGO enabled on the riscv64 platform. The behavior should be consistent with other architectures where the build passes without the need to modify test files.
The text was updated successfully, but these errors were encountered: