[binutils-gdb] ld/PE: ignore R_*_ABS / R_*_NONE
Jan Beulich
jbeulich@sourceware.org
Fri Nov 13 13:16:59 GMT 2026
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=036fd0ebe0c35c168f126e273a1bdf9d58a7c571
commit 036fd0ebe0c35c168f126e273a1bdf9d58a7c571
Author: Jan Beulich <jbeulich@suse.com>
Date: Fri Nov 13 14:15:22 2026 +0100
ld/PE: ignore R_*_ABS / R_*_NONE
... rather than erroring on them. They can be used for various interesting
purposes.
Diff:
---
ld/pe-dll.c | 3 +++
ld/testsuite/ld-pe/pe.exp | 1 +
ld/testsuite/ld-pe/reloc-none.d | 16 ++++++++++++++++
ld/testsuite/ld-pe/reloc-none.s | 12 ++++++++++++
ld/testsuite/ld-pe/reloc-none2.s | 6 ++++++
5 files changed, 38 insertions(+)
diff --git a/ld/pe-dll.c b/ld/pe-dll.c
index 4ff3ea0ff20..2f9cbe345a8 100644
--- a/ld/pe-dll.c
+++ b/ld/pe-dll.c
@@ -1724,6 +1724,9 @@ generate_reloc (bfd *abfd, struct bfd_link_info *info)
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;
diff --git a/ld/testsuite/ld-pe/pe.exp b/ld/testsuite/ld-pe/pe.exp
index 53b04bb6757..22b000956ec 100644
--- 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"
diff --git a/ld/testsuite/ld-pe/reloc-none.d b/ld/testsuite/ld-pe/reloc-none.d
new file mode 100644
index 00000000000..e33a3541e1d
--- /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
diff --git a/ld/testsuite/ld-pe/reloc-none.s b/ld/testsuite/ld-pe/reloc-none.s
new file mode 100644
index 00000000000..ce6ce8f2bd6
--- /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
diff --git a/ld/testsuite/ld-pe/reloc-none2.s b/ld/testsuite/ld-pe/reloc-none2.s
new file mode 100644
index 00000000000..39b9dee5047
--- /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-cvs
mailing list