[PATCH] aarch64: Set pcrel_off for COFF relocations

Jan Beulich jbeulich@suse.com
Tue Sep 2 06:13:28 GMT 2025


On 01.09.2025 23:17, Mark Harmstone wrote:
> On 01/09/2025 8.48 am, Jan Beulich wrote:
>> On 30.08.2025 19:17, Mark Harmstone wrote:
>>> The pcrel_off flag of reloc_howto_type specifies that "the displacement part
>>> of an instruction [is left] empty", which is the case for ELF and COFF files.
>>> This wasn't being set in bfd/coff-aarch64.c, with the result that when using
>>> ld with a linker script, bfd_perform_relocation was writing incorrect
>>> relocations.
>>
>> But is this correct for all relocations? I can see it being like this for
>> ones dealing with instruction fields, yet ones like ADDR64, ADDR32, REL32
>> etc (dealing with data items) may be different?
> 
> I just realized there's a typo in the patch name: it's pcrel_offset, not
> pcrel_off.
> 
>  From what I can see pcrel_offset is only checked when pc_relative is true,
> so ADDR64 and ADDR32 aren't affected. For REL32 it's not clear, there's no
> way of generating it with GAS so it's not tested.

There are likely more, though. Plus remember that any relocation can be
generated with .reloc.

> Three years on it's not clear to me why we have two ways of doing the same
> relocations in this file: the normal way in coff_pe_aarch64_relocate_section,
> and the HOWTOs for anything unusual. Five minutes after sending this patch
> I ran into another two issues in the same area, and I know trying to link
> ELF object files into a PE file is also dangerous.

It may feel dangerous right now, but on the x86 side we've been using it
in the main project I work on (Xen) to link EFI binaries. With various
workarounds of course, and with further known issue we merely happen to
not be (severely) affected by. The overall goal, I think, should be to
allow such linking as long as all relocations used can be properly dealt
with (PLT and GOT and alike of course don't exist as a concept in PE/COFF,
for example).

As to the two ways of linking - it is my understanding that the "native"
(COFF -> COFF or also ELF -> ELF) special cases exist for performance
reasons. And indeed, since in Xen we link both an ELF and a PE/COFF
binary, especially with debug info present the performance difference is
pretty noticeable.

Jan


More information about the Binutils mailing list