]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: refactor usage of SymLocalentry helper functions
authorPaul E. Murphy <murp@ibm.com>
Mon, 19 Sep 2022 21:48:49 +0000 (16:48 -0500)
committerPaul Murphy <murp@ibm.com>
Tue, 27 Sep 2022 17:29:05 +0000 (17:29 +0000)
PPC64 ELFv2 uses the st_other field of a symbol to specify an offset
from the global entry point to its local entry point. Similarly, some
values (i.e 1) may also require additional linker support which is
missing today.

For now, generate an error if we encounter unsupported local entry
values on PPC64, and update the Localentry values to use bytes, not
32b instruction words.

Similarly, ELFv2 1.5 also updates the wording of values 2-6. They
now map to a specific number of bytes.

Change-Id: Id1b71c3b0fea982bdcfb7eac91d9f93e04ae43f9
Reviewed-on: https://go-review.googlesource.com/c/go/+/431876
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Paul Murphy <murp@ibm.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
src/cmd/link/internal/loadelf/ldelf.go
src/cmd/link/internal/loader/loader.go
src/cmd/link/internal/ppc64/asm.go

index 74f7cb15a0fb8e66980ea564ccbbb6b25e82b4a0..da02223212c0f3f1a8fc06c831c25c98f9250a92 100644 (file)
@@ -634,10 +634,16 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
 
                if elf.Machine(elfobj.machine) == elf.EM_PPC64 {
                        flag := int(elfsym.other) >> 5
-                       if 2 <= flag && flag <= 6 {
-                               l.SetSymLocalentry(s, 1<<uint(flag-2))
-                       } else if flag == 7 {
+                       switch flag {
+                       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())
+                       case 7:
                                return errorf("%s: invalid sym.other 0x%x", sb.Name(), elfsym.other)
+                       default:
+                               l.SetSymLocalentry(s, 4<<uint(flag-2))
                        }
                }
        }
index c2baa20d8d20ec7c4e29370e84f223aaea0d8746..40ad950fe509904a8a48cb60c3a36914944ed857 100644 (file)
@@ -1562,13 +1562,12 @@ func (l *Loader) SetSymPkg(i Sym, pkg string) {
        l.symPkg[i] = pkg
 }
 
-// SymLocalentry returns the "local entry" value for the specified
-// symbol.
+// SymLocalentry returns an offset in bytes of the "local entry" of a symbol.
 func (l *Loader) SymLocalentry(i Sym) uint8 {
        return l.localentry[i]
 }
 
-// SetSymLocalentry sets the "local entry" attribute for a symbol.
+// SetSymLocalentry sets the "local entry" offset attribute for a symbol.
 func (l *Loader) SetSymLocalentry(i Sym, value uint8) {
        // reject bad symbols
        if i >= Sym(len(l.objSyms)) || i == 0 {
index 21bc430e04e45846ade59e3060cbc103d51cecdc..70d2cf3f0b106bfe3e2049e5f114cd58a10c3b1c 100644 (file)
@@ -380,7 +380,7 @@ func addelfdynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s lo
                // callee. Hence, we need to go to the local entry
                // point.  (If we don't do this, the callee will try
                // to use r12 to compute r2.)
-               su.SetRelocAdd(rIdx, r.Add()+int64(ldr.SymLocalentry(targ))*4)
+               su.SetRelocAdd(rIdx, r.Add()+int64(ldr.SymLocalentry(targ)))
 
                if targType == sym.SDYNIMPORT {
                        // Should have been handled in elfsetupplt