]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: clean up some relocation handling
authorCherry Mui <cherryyz@google.com>
Thu, 8 Jun 2023 17:23:39 +0000 (13:23 -0400)
committerCherry Mui <cherryyz@google.com>
Thu, 20 Jul 2023 19:41:53 +0000 (19:41 +0000)
We don't use R_PCREL for calls to dynamic symbols (we use R_CALL
instead). Don't handle R_PCREL as a call.

We don't use R_CALL on ARM64 (we use R_CALLARM64 instead).

Remove those cases, which we don't expect to see.

Change-Id: Idd99022a8eeb65750ffc2936ffdccf8bb0405e30
Reviewed-on: https://go-review.googlesource.com/c/go/+/501859
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
src/cmd/link/internal/amd64/asm.go
src/cmd/link/internal/arm64/asm.go

index c4134262c5aa8510b5a053aa060cf595de2845d6..7082c839eecaec075803ac1b8628f91506a91ea0 100644 (file)
@@ -245,13 +245,25 @@ func adddynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s loade
        r = relocs.At(rIdx)
 
        switch r.Type() {
-       case objabi.R_CALL,
-               objabi.R_PCREL:
+       case objabi.R_CALL:
                if targType != sym.SDYNIMPORT {
                        // nothing to do, the relocation will be laid out in reloc
                        return true
                }
-               if r.Type() == objabi.R_PCREL && ldr.SymType(s) == sym.STEXT && target.IsDarwin() {
+               if target.IsExternal() {
+                       // External linker will do this relocation.
+                       return true
+               }
+               // Internal linking, for both ELF and Mach-O.
+               // Build a PLT entry and change the relocation target to that entry.
+               addpltsym(target, ldr, syms, targ)
+               su := ldr.MakeSymbolUpdater(s)
+               su.SetRelocSym(rIdx, syms.PLT)
+               su.SetRelocAdd(rIdx, int64(ldr.SymPlt(targ)))
+               return true
+
+       case objabi.R_PCREL:
+               if targType == sym.SDYNIMPORT && ldr.SymType(s) == sym.STEXT && target.IsDarwin() {
                        // Loading the address of a dynamic symbol. Rewrite to use GOT.
                        // turn LEAQ symbol address to MOVQ of GOT entry
                        if r.Add() != 0 {
@@ -272,19 +284,7 @@ func adddynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s loade
                                return true
                        }
                        ldr.Errorf(s, "unexpected R_PCREL reloc for dynamic symbol %s: not preceded by LEAQ instruction", ldr.SymName(targ))
-                       return false
-               }
-               if target.IsExternal() {
-                       // External linker will do this relocation.
-                       return true
                }
-               // Internal linking, for both ELF and Mach-O.
-               // Build a PLT entry and change the relocation target to that entry.
-               addpltsym(target, ldr, syms, targ)
-               su := ldr.MakeSymbolUpdater(s)
-               su.SetRelocSym(rIdx, syms.PLT)
-               su.SetRelocAdd(rIdx, int64(ldr.SymPlt(targ)))
-               return true
 
        case objabi.R_ADDR:
                if ldr.SymType(s) == sym.STEXT && target.IsElf() {
index e3fc1c4dd4cb4be0746f8ada6c53b5434363541e..f2a2b32232149c9527805492692a00dcf25e6398 100644 (file)
@@ -284,9 +284,7 @@ func adddynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s loade
        r = relocs.At(rIdx)
 
        switch r.Type() {
-       case objabi.R_CALL,
-               objabi.R_PCREL,
-               objabi.R_CALLARM64:
+       case objabi.R_CALLARM64:
                if targType != sym.SDYNIMPORT {
                        // nothing to do, the relocation will be laid out in reloc
                        return true