From 3c46d8f5119475adbadb6141acd463b910c1747b Mon Sep 17 00:00:00 2001 From: "Paul E. Murphy" Date: Tue, 17 Jan 2023 11:33:28 -0600 Subject: [PATCH] cmd/link: load external ELF PPC64 objects which set st_other=1 This indicates the symbol does not use or preserve the TOC pointer in R2. Likewise, it does not have a distinct local entry point. This happens when gcc compiles an object with -mcpu=power10. Recycle the SymLocalentry field of a text symbol to pass through this hint as the bogus value 1 (A valid offset must be a multiple of 4 bytes), and update the usage to check and generate errors further into the linking process. This matches the behavior of st_other as used by ELFv2. Change-Id: Ic89ce17b57f400ab44213b21a3730a98c7cdf842 Reviewed-on: https://go-review.googlesource.com/c/go/+/490295 Run-TryBot: Paul Murphy Reviewed-by: Cherry Mui Reviewed-by: Dmitri Shuralyov TryBot-Result: Gopher Robot --- src/cmd/link/internal/loadelf/ldelf.go | 12 ++++++++++-- src/cmd/link/internal/loader/loader.go | 3 +++ src/cmd/link/internal/ppc64/asm.go | 12 ++++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/cmd/link/internal/loadelf/ldelf.go b/src/cmd/link/internal/loadelf/ldelf.go index c1bfec059d..77247b47f4 100644 --- a/src/cmd/link/internal/loadelf/ldelf.go +++ b/src/cmd/link/internal/loadelf/ldelf.go @@ -639,11 +639,15 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader, case 0: // No local entry. R2 is preserved. case 1: - // These require R2 be saved and restored by the caller. This isn't supported today. - return errorf("%s: unable to handle local entry type 1", sb.Name()) + // This is kind of a hack, but pass the hint about this symbol's + // usage of R2 (R2 is a caller-save register not a TOC pointer, and + // this function does not have a distinct local entry) by setting + // its SymLocalentry to 1. + l.SetSymLocalentry(s, 1) case 7: return errorf("%s: invalid sym.other 0x%x", sb.Name(), elfsym.other) default: + // Convert the word sized offset into bytes. l.SetSymLocalentry(s, 4<