[PATCH] aarch64: Set pcrel_off for COFF relocations
Mark Harmstone
mark@harmstone.com
Sat Aug 30 17:17:38 GMT 2025
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.
This isn't an issue when using aarch64-w64-mingw32-ld in its normal
mode to create PE files, as relocation gets done in a different way
that doesn't use bfd_generic.
Minimal reproducer:
$ cat tmp1.s
.long 0x12345678
b foo
$ cat tmp2.s
.global foo
foo:
.long 0x9abcdef0
$ cat tmp.ld
OUTPUT_FORMAT("binary")
OUTPUT_ARCH("aarch64")
TARGET("pei-aarch64-little")
SECTIONS
{
.text : AT(text) {
text = .;
*(.text)
}
}
$ aarch64-w64-mingw32-as tmp1.s -o tmp1.o
$ aarch64-w64-mingw32-as tmp2.s -o tmp2.o
$ ld -T tmp.ld tmp1.o tmp2.o -o tmp
$ objdump -b binary -m aarch64 -D tmp
tmp: file format binary
Disassembly of section .data:
0000000000000000 <.data>:
0: 12345678 and w24, w19, #0xfffff003
4: 14000002 b 0xc // wrong, should be "b 0x8"
8: 9abcdef0 .inst 0x9abcdef0 ; undefined
* bfd/coff-aarch64.c (HOW): Pass true through to HOWTO for
pcrel_offset.
---
bfd/coff-aarch64.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/bfd/coff-aarch64.c b/bfd/coff-aarch64.c
index 48b8bfaf496..4861bf478ed 100644
--- a/bfd/coff-aarch64.c
+++ b/bfd/coff-aarch64.c
@@ -244,7 +244,7 @@ coff_aarch64_secrel_reloc (bfd *abfd,
#define HOWTO_INSTALL_ADDEND 1
#define HOW(type, right, size, bits, pcrel, left, ovf, func, mask) \
HOWTO (type, right, size, bits, pcrel, left, complain_overflow_##ovf, \
- coff_aarch64_##func, #type, true, mask, mask, false)
+ coff_aarch64_##func, #type, true, mask, mask, true)
static const reloc_howto_type arm64_reloc_howto_abs
= HOW (IMAGE_REL_ARM64_ABSOLUTE,
--
2.49.1
More information about the Binutils
mailing list