Skip to content

Commit a22540f

Browse files
committed
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 golang#73591 [1]: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/87aecf601722171c570120a46003be3c17ad3108/riscv-elf.adoc?plain=1#L1448
1 parent 93fb2c9 commit a22540f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/cmd/link/internal/loadelf/ldelf.go

+8
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,14 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
602602
// See https://sourceware.org/bugzilla/show_bug.cgi?id=21809
603603
continue
604604
}
605+
606+
if arch.Family == sys.RISCV64 &&
607+
(strings.HasPrefix(elfsym.name, "$d") || strings.HasPrefix(elfsym.name, "$x")) {
608+
// Ignore RISC-V mapping symbols, which
609+
// are similar to ARM64's case.
610+
// See issue 73591.
611+
continue
612+
}
605613
}
606614

607615
if strings.HasPrefix(elfsym.name, ".Linfo_string") {

0 commit comments

Comments
 (0)