Skip to content

Commit

Permalink
WIP - try to find the source of the missing epilogue
Browse files Browse the repository at this point in the history
  • Loading branch information
Anonymous committed Jul 30, 2023
1 parent 10fbf63 commit c398d9b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ld.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func (linker *Linker) addSymbol(name string, globalSymPtr map[string]uintptr) (s
objsym.Reloc[i].EpilogueOffset = len(linker.code) - symbol.Offset
objsym.Reloc[i].EpilogueSize = maxExtraInstructionBytesADRPLDST
linker.code = append(linker.code, createArchNops(linker.Arch, maxExtraInstructionBytesADRPLDST)...)
case reloctype.R_CALLARM64:
case reloctype.R_CALLARM64, reloctype.R_CALLARM:
objsym.Reloc[i].EpilogueOffset = alignof(len(linker.code)-symbol.Offset, PtrSize)
objsym.Reloc[i].EpilogueSize = maxExtraInstructionBytesCALLARM64
alignment := alignof(len(linker.code)-symbol.Offset, PtrSize) - (len(linker.code) - symbol.Offset)
Expand Down
6 changes: 3 additions & 3 deletions relocate.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func (linker *Linker) relocatePCREL(addr uintptr, loc obj.Reloc, segment *segmen
return err
}

func (linker *Linker) relocateCALLARM(addr uintptr, loc obj.Reloc, segment *segment) error {
func (linker *Linker) relocateCALLARM(addr uintptr, sym *obj.Sym, loc obj.Reloc, segment *segment) error {
byteorder := linker.Arch.ByteOrder
add := loc.Add
if loc.Type == reloctype.R_CALLARM {
Expand All @@ -280,7 +280,7 @@ func (linker *Linker) relocateCALLARM(addr uintptr, loc obj.Reloc, segment *segm
offset := (int(addr) + add - (segment.codeBase + loc.Offset)) / 4
if offset > 0x7FFFFF || offset < -0x800000 || (linker.options.ForceTestRelocationEpilogues && loc.EpilogueSize > 0) {
if loc.EpilogueSize == 0 {
return fmt.Errorf("relocation epilogue not available but got a >24-bit CALLARM reloc with offset %d: %s", offset, loc.Sym.Name)
return fmt.Errorf("relocation epilogue not available but got a >24-bit CALLARM (%s) reloc with offset %d: %s from %s (kind %s)", objabi.RelocType(loc.Type), offset, loc.Sym.Name, sym.Name, objabi.SymKind(sym.Kind))
}
off := uint32(epilogueOffset-loc.Offset) / 4
if loc.Type == reloctype.R_CALLARM {
Expand Down Expand Up @@ -404,7 +404,7 @@ func (linker *Linker) relocate(codeModule *CodeModule, symbolMap map[string]uint
}
err = linker.relocatePCREL(addr, loc, segment, relocByte, addrBase)
case reloctype.R_CALLARM, reloctype.R_CALLARM64, reloctype.R_CALLARM64 | reloctype.R_WEAK:
err = linker.relocateCALLARM(addr, loc, segment)
err = linker.relocateCALLARM(addr, symbol, loc, segment)
case reloctype.R_ADDRARM64, reloctype.R_ARM64_PCREL_LDST8, reloctype.R_ARM64_PCREL_LDST16, reloctype.R_ARM64_PCREL_LDST32, reloctype.R_ARM64_PCREL_LDST64, reloctype.R_ARM64_GOTPCREL:
if symbol.Kind != symkind.STEXT {
err = fmt.Errorf("impossible! Sym: %s is not in code segment! (kind %s)\n", sym.Name, objabi.SymKind(sym.Kind))
Expand Down

0 comments on commit c398d9b

Please sign in to comment.