From c6117e8f05a55dad96b5d36cd04702b5424eab5a Mon Sep 17 00:00:00 2001 From: limeidan Date: Wed, 17 Apr 2024 11:29:13 +0800 Subject: [PATCH] cmd/link: pass architecture to isPLTCall 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 LUCI-TryBot-Result: Go LUCI Reviewed-by: Cherry Mui Reviewed-by: Dmitri Shuralyov Reviewed-by: abner chenc Auto-Submit: abner chenc --- src/cmd/link/internal/ld/data.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cmd/link/internal/ld/data.go b/src/cmd/link/internal/ld/data.go index b18dc6993b..0f1289cccc 100644 --- a/src/cmd/link/internal/ld/data.go +++ b/src/cmd/link/internal/ld/data.go @@ -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. -- 2.48.1