cmd/link: ignore mapping symbols on riscv64

Specified in RISC-V ELF psABI[1], mapping symbols are symbols starting
with "$d" or "$x" with STT_NOTYPE, STB_LOCAL and zero sizes, indicating
boundaries between code and data in the same section.

Let's simply ignore them as they're only markers instead of real symbols.
This fixes linking errors like

	sym#63 ("$d"): ignoring symbol in section 4 (".riscv.attributes") (type 0)

when using CGO together with Clang and internal linker, which are caused
by unnecessary (but technically correct) mapping symbols created by LLVM
for various sections.

[1]: 87aecf6017/riscv-elf.adoc?plain=1#L1448

Fixes #73516

Change-Id: I02ca90c100ba8a38733fe3b8b8403836b44a3dd1
GitHub-Last-Rev: d7842ceafb
GitHub-Pull-Request: golang/go#73592
Reviewed-on: https://go-review.googlesource.com/c/go/+/669675
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Meng Zhuo <mengzhuo1203@gmail.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
Yao Zi 2025-05-09 15:09:39 +00:00 committed by Meng Zhuo
parent 1e436ba668
commit a2fbb50322
1 changed files with 8 additions and 0 deletions

View File

@ -602,6 +602,14 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
// See https://sourceware.org/bugzilla/show_bug.cgi?id=21809
continue
}
if arch.Family == sys.RISCV64 &&
(strings.HasPrefix(elfsym.name, "$d") || strings.HasPrefix(elfsym.name, "$x")) {
// Ignore RISC-V mapping symbols, which
// are similar to ARM64's case.
// See issue 73591.
continue
}
}
if strings.HasPrefix(elfsym.name, ".Linfo_string") {