]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: pass architecture to isPLTCall
authorlimeidan <limeidan@loongson.cn>
Wed, 17 Apr 2024 03:29:13 +0000 (11:29 +0800)
committerGopher Robot <gobot@golang.org>
Sat, 27 Jul 2024 14:02:24 +0000 (14:02 +0000)
The relocation number of each architecture starts from 0. objabi.ElfRelocOffset
+ objabi.RelocType(xxx) cannot uniquely represent a relocation, so the new
argument 'arch' was added to help identify relocation.

Change-Id: Ic8121dbfd1a4f31f279d50ffdc9c932ce3066efd
Reviewed-on: https://go-review.googlesource.com/c/go/+/580275
Commit-Queue: abner chenc <chenguoqi@loongson.cn>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: abner chenc <chenguoqi@loongson.cn>
Auto-Submit: abner chenc <chenguoqi@loongson.cn>

src/cmd/link/internal/ld/data.go

index b18dc6993bd16d2ad3b64f98c8f6fd607c140bae..0f1289cccc8404084c9aa93d1949620e7d2809cc 100644 (file)
@@ -114,7 +114,7 @@ func trampoline(ctxt *Link, s loader.Sym) {
        for ri := 0; ri < relocs.Count(); ri++ {
                r := relocs.At(ri)
                rt := r.Type()
-               if !rt.IsDirectCallOrJump() && !isPLTCall(rt) {
+               if !rt.IsDirectCallOrJump() && !isPLTCall(ctxt.Arch, rt) {
                        continue
                }
                rs := r.Sym()
@@ -146,19 +146,19 @@ func trampoline(ctxt *Link, s loader.Sym) {
 
 // whether rt is a (host object) relocation that will be turned into
 // a call to PLT.
-func isPLTCall(rt objabi.RelocType) bool {
+func isPLTCall(arch *sys.Arch, rt objabi.RelocType) bool {
        const pcrel = 1
-       switch rt {
+       switch uint32(arch.Family) | uint32(rt)<<8 {
        // ARM64
-       case objabi.ElfRelocOffset + objabi.RelocType(elf.R_AARCH64_CALL26),
-               objabi.ElfRelocOffset + objabi.RelocType(elf.R_AARCH64_JUMP26),
-               objabi.MachoRelocOffset + MACHO_ARM64_RELOC_BRANCH26*2 + pcrel:
+       case uint32(sys.ARM64) | uint32(objabi.ElfRelocOffset+objabi.RelocType(elf.R_AARCH64_CALL26))<<8,
+               uint32(sys.ARM64) | uint32(objabi.ElfRelocOffset+objabi.RelocType(elf.R_AARCH64_JUMP26))<<8,
+               uint32(sys.ARM64) | uint32(objabi.MachoRelocOffset+MACHO_ARM64_RELOC_BRANCH26*2+pcrel)<<8:
                return true
 
        // ARM
-       case objabi.ElfRelocOffset + objabi.RelocType(elf.R_ARM_CALL),
-               objabi.ElfRelocOffset + objabi.RelocType(elf.R_ARM_PC24),
-               objabi.ElfRelocOffset + objabi.RelocType(elf.R_ARM_JUMP24):
+       case uint32(sys.ARM) | uint32(objabi.ElfRelocOffset+objabi.RelocType(elf.R_ARM_CALL))<<8,
+               uint32(sys.ARM) | uint32(objabi.ElfRelocOffset+objabi.RelocType(elf.R_ARM_PC24))<<8,
+               uint32(sys.ARM) | uint32(objabi.ElfRelocOffset+objabi.RelocType(elf.R_ARM_JUMP24))<<8:
                return true
        }
        // TODO: other architectures.