fix(asm): add cross-package GOOBJ resolution for riscv64, loong64, arm64

Assisted-by: MiMo V2.5 Pro
This commit is contained in:
2026-08-21 00:35:21 +02:00
parent cc50035375
commit ae550cc05a
4 changed files with 58 additions and 9 deletions
+8 -3
View File
@@ -16,6 +16,7 @@ const (
// AArch64 relocation types (the ELF psABI).
rArm64PrelPgHi21 = 275 // R_AARCH64_ADR_PREL_PG_HI21 (ADRP page)
rArm64AddAbsLo12NC = 277 // R_AARCH64_ADD_ABS_LO12_NC (ADD/STR/LDR page offset)
rArm64Call26 = 283 // R_AARCH64_CALL26 (BL instruction)
)
// ELFAARCH64Object returns the image as an ELF64 relocatable object file for
@@ -94,10 +95,14 @@ func (img *Image) ELFAARCH64Object() ([]byte, error) {
if !ok {
return nil, fmt.Errorf("relocation references unknown symbol %q", r.Name)
}
typ := uint32(rArm64PrelPgHi21)
if r.Kind == RelArm64Addr && r.Off%4 == 4 {
// The second instruction in an ADRP pair uses ADD_ABS_LO12_NC.
var typ uint32
switch {
case r.Kind == RelArm64Branch:
typ = rArm64Call26
case r.Kind == RelArm64Addr && r.Off%4 == 4:
typ = rArm64AddAbsLo12NC
default:
typ = rArm64PrelPgHi21
}
relas = append(relas, elfRela{
off: uint64(fn.Offset + r.Off),