[binutils-gdb] ix86: restrict use of GOT32X relocs
Jan Beulich
jbeulich@sourceware.org
Fri Feb 21 09:30:01 GMT 2025
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=5649b9dc865cba3a039cc55cc8f245872fb5a5cf
commit 5649b9dc865cba3a039cc55cc8f245872fb5a5cf
Author: Jan Beulich <jbeulich@suse.com>
Date: Fri Feb 21 10:26:59 2025 +0100
ix86: restrict use of GOT32X relocs
The ELF linker rejects use of this reloc type without a base register
for PIC code. Suppress its use by gas in such cases.
To keep things building for non-ELF, include the entire containing if()
in an #ifdef: All consumers of ->fx_tcbit* live in such conditionals as
well, hence there's no reason to keep the producer active.
Diff:
---
gas/config/tc-i386.c | 5 ++++-
ld/testsuite/ld-i386/i386.exp | 2 ++
ld/testsuite/ld-i386/load4c.d | 4 ++++
ld/testsuite/ld-i386/load5c.d | 4 ++++
4 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c
index d44efe80509..9adb96ff433 100644
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -12932,6 +12932,7 @@ output_disp (fragS *insn_start_frag, offsetT insn_start_off)
else if (object_64bit)
continue;
+#ifdef OBJ_ELF
/* Check for "call/jmp *mem", "push mem", "mov mem, %reg",
"movrs mem, %reg", "test %reg, mem" and "binop mem, %reg" where
binop is one of adc, add, and, cmp, or, sbb, sub, xor, or imul
@@ -12994,9 +12995,11 @@ output_disp (fragS *insn_start_frag, offsetT insn_start_off)
}
}
else if (generate_relax_relocations
- || (i.rm.mode == 0 && i.rm.regmem == 5))
+ ? (!shared || i.rm.mode != 0 || i.rm.regmem != 5)
+ : (!shared && i.rm.mode == 0 && i.rm.regmem == 5))
fixP->fx_tcbit2 = 1;
}
+#endif
}
}
}
diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
index dc91f6b2aed..8236b8fc0ac 100644
--- a/ld/testsuite/ld-i386/i386.exp
+++ b/ld/testsuite/ld-i386/i386.exp
@@ -369,8 +369,10 @@ run_dump_test "load2"
run_dump_test "load3"
run_dump_test "load4a"
run_dump_test "load4b"
+run_dump_test "load4c"
run_dump_test "load5a"
run_dump_test "load5b"
+run_dump_test "load5c"
run_dump_test "load6"
run_dump_test "load7"
run_dump_test "load8"
diff --git a/ld/testsuite/ld-i386/load4c.d b/ld/testsuite/ld-i386/load4c.d
new file mode 100644
index 00000000000..82573339b81
--- /dev/null
+++ b/ld/testsuite/ld-i386/load4c.d
@@ -0,0 +1,4 @@
+#source: load4.s
+#as: --32 -mshared -mrelax-relocations=yes
+#ld: -Bsymbolic -shared -melf_i386
+#error: direct GOT relocation R_386_GOT32 against `foo' without base register can not be used when making a shared object
diff --git a/ld/testsuite/ld-i386/load5c.d b/ld/testsuite/ld-i386/load5c.d
new file mode 100644
index 00000000000..3e787210137
--- /dev/null
+++ b/ld/testsuite/ld-i386/load5c.d
@@ -0,0 +1,4 @@
+#source: load5.s
+#as: --32 -mshared -mrelax-relocations=yes
+#ld: -Bsymbolic -shared -melf_i386
+#error: direct GOT relocation R_386_GOT32 against `foo' without base register can not be used when making a shared object
More information about the Binutils-cvs
mailing list