]> Cypherpunks repositories - gostls13.git/commit
cmd/link: fix cgo on riscv64 when building with gcc-15
authorMark Ryan <markdryan@rivosinc.com>
Fri, 25 Apr 2025 15:23:49 +0000 (17:23 +0200)
committerGopher Robot <gobot@golang.org>
Wed, 30 Apr 2025 18:40:17 +0000 (11:40 -0700)
commit12e5efd71011fbb5816a1d815e91b5c865fa9a83
tree3a08eef47e6b5f0f60f2ad40bc079b98e7f03941
parent214b208e248d30a3b6c35a5ebf344cc2de3b9e3f
cmd/link: fix cgo on riscv64 when building with gcc-15

It's not currently possible to build cgo programs that are partially
compiled with gcc-15 on riscv64 using the internal linker. There are
two reasons for this.

1. When gcc-15 compiles _cgo_export.c, which contains no actual code,
   for a riscv64 target, it emits a label in the .text section called
   .Letext0. This label is referred to by another section, .debug_line,
   and an entry is generated in the symbol table for it. The Go linker
   panics when processing the .Letext0 symbol in _cgo_export.o, as it
   occurs in an empty section.
2. GCC-15 is generating additional debug symbols with the .LVUS
   prefix, e.g., .LVUS33, that need to be ignored.

We fix the issue by removing the check in
cmd/link/internal/loader/loader.go that panics if we encounter a
symbol in an empty section (the comments preceding this check suggest
it's safe to remove it) and by adding .LVUS to the list of symbol
prefixes to ignore.

Fixes #72840

Change-Id: I00658b6bdd01606dde1581b5bc2f42edfc37de82
Reviewed-on: https://go-review.googlesource.com/c/go/+/668276
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Joel Sing <joel@sing.id.au>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Reviewed-by: Meng Zhuo <mengzhuo1203@gmail.com>
src/cmd/link/internal/loadelf/ldelf.go
src/cmd/link/internal/loader/loader.go