From d7842ceafb840c511cf0c36295c353698898d399 Mon Sep 17 00:00:00 2001 From: Yao Zi Date: Sat, 3 May 2025 08:37:30 +0000 Subject: [PATCH] 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. Fixes #73516 [1]: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/87aecf601722171c570120a46003be3c17ad3108/riscv-elf.adoc?plain=1#L1448 --- src/cmd/link/internal/loadelf/ldelf.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/cmd/link/internal/loadelf/ldelf.go b/src/cmd/link/internal/loadelf/ldelf.go index 9f251e746b79ad..c91fed50881540 100644 --- a/src/cmd/link/internal/loadelf/ldelf.go +++ b/src/cmd/link/internal/loadelf/ldelf.go @@ -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") {