[PATCH 2/3] ld/PE: ignore R_*_ABS / R_*_NONE

Jan Beulich jbeulich@suse.com
Fri Nov 6 11:12:18 GMT 2026


... rather than erroring on them. They can be used for various interesting
purposes.
---
Question is whether ->bitsize alone would be sufficient to regard a reloc
type as "not altering the binary".

The situation for Arm is difficult: Different sources look to have
different views on what the specific relocation types mean (and hence
whether there is an ABS/NONE one).

--- a/ld/pe-dll.c
+++ b/ld/pe-dll.c
@@ -1724,6 +1724,9 @@ generate_reloc (bfd *abfd, struct bfd_li
 		  switch BITS_AND_SHIFT (relocs[i]->howto->bitsize,
 					 relocs[i]->howto->rightshift)
 		    {
+		    case BITS_AND_SHIFT (0, 0):
+		      /* Skip relocations not altering the binary.   */
+		      break;
 #ifdef pe_use_plus
 		    case BITS_AND_SHIFT (64, 0):
 		      reloc_data[total_relocs].type = IMAGE_REL_BASED_DIR64;
--- a/ld/testsuite/ld-pe/pe.exp
+++ b/ld/testsuite/ld-pe/pe.exp
@@ -151,6 +151,7 @@ run_dump_test "reloc"
 run_dump_test "reloc2a"
 run_dump_test "reloc2b"
 run_dump_test "reloc2c"
+run_dump_test "reloc-none"
 
 run_dump_test "weakdef-1"
 
--- /dev/null
+++ b/ld/testsuite/ld-pe/reloc-none.d
@@ -0,0 +1,16 @@
+#name: PE BFD_RELOC_NONE handling
+#ld: --enable-reloc-section
+#objdump: -p
+#source: reloc-none.s
+#source: reloc-none2.s
+#notarget: arm*-*-* ia64-*-* loongarch*-*-* riscv*-*-*
+#xfail: aarch64-*-* i?86-*-* mcore-*-* sh-*-*
+
+.*:     file format .*
+
+#...
+PE File Base Relocations.*
+Virtual Address: .* Number of fixups 2
+[ 	]*reloc    0 offset   10 .* (LOW|HIGHLOW|DIR64)
+[ 	]*reloc    1 offset    0 .* ABSOLUTE
+#pass
--- /dev/null
+++ b/ld/testsuite/ld-pe/reloc-none.s
@@ -0,0 +1,12 @@
+	.text
+	.global _start
+_start:
+	.nop
+
+	.data
+	.reloc ., BFD_RELOC_NONE, _start
+	.long 0
+	.reloc ., BFD_RELOC_NONE, sym
+	.long 0
+	.reloc ., BFD_RELOC_NONE, .
+	.long 0
--- /dev/null
+++ b/ld/testsuite/ld-pe/reloc-none2.s
@@ -0,0 +1,6 @@
+	.global sym
+sym:
+	.nop
+
+	.data
+	.dc.a sym



More information about the Binutils mailing list