aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2022-02-07 15:22:19 -0800
committerH.J. Lu <hjl.tools@gmail.com>2022-02-07 16:13:51 -0800
commit7c4b20b9583d0d9c99e0793fd98ed0aaef2af729 (patch)
tree06fc8152f9c253301ed6f3e8bc8dc6874ba17d9a
parent5f62caec8175cf80a29f2bcab2c5077cbfae8c89 (diff)
downloadbinutils-7c4b20b9583d0d9c99e0793fd98ed0aaef2af729.zip
binutils-7c4b20b9583d0d9c99e0793fd98ed0aaef2af729.tar.gz
binutils-7c4b20b9583d0d9c99e0793fd98ed0aaef2af729.tar.bz2
i386: Allow GOT32 relocations against ABS symbols
GOT32 relocations are allowed since absolute value + addend is stored in the GOT slot. Tested on glibc 2.35 build with GCC 11.2 and -Os. bfd/ PR ld/28870 * elfxx-x86.c (_bfd_elf_x86_valid_reloc_p): Also allow GOT32 relocations. ld/ PR ld/28870 * testsuite/ld-i386/i386.exp: Run pr28870. * testsuite/ld-i386/pr28870.d: New file. * testsuite/ld-i386/pr28870.s: Likewise. (cherry picked from commit 30a954525f4e53a9cd50a1a8a6f201c7cf6595c7)
-rw-r--r--bfd/elfxx-x86.c10
-rw-r--r--ld/testsuite/ld-i386/i386.exp1
-rw-r--r--ld/testsuite/ld-i386/pr28870.d10
-rw-r--r--ld/testsuite/ld-i386/pr28870.s6
4 files changed, 23 insertions, 4 deletions
diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
index 088f6e5..6f8d342 100644
--- a/bfd/elfxx-x86.c
+++ b/bfd/elfxx-x86.c
@@ -933,9 +933,9 @@ _bfd_elf_x86_valid_reloc_p (asection *input_section,
irel = *rel;
/* Only allow relocations against absolute symbol, which can be
- resolved as absolute value + addend. GOTPCREL relocations
- are allowed since absolute value + addend is stored in the
- GOT slot. */
+ resolved as absolute value + addend. GOTPCREL and GOT32
+ relocations are allowed since absolute value + addend is
+ stored in the GOT slot. */
if (bed->target_id == X86_64_ELF_DATA)
{
r_type &= ~R_X86_64_converted_reloc_bit;
@@ -956,7 +956,9 @@ _bfd_elf_x86_valid_reloc_p (asection *input_section,
else
valid_p = (r_type == R_386_32
|| r_type == R_386_16
- || r_type == R_386_8);
+ || r_type == R_386_8
+ || r_type == R_386_GOT32
+ || r_type == R_386_GOT32X);
if (valid_p)
*no_dynreloc_p = true;
diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
index ceb6000..68ea023 100644
--- a/ld/testsuite/ld-i386/i386.exp
+++ b/ld/testsuite/ld-i386/i386.exp
@@ -493,6 +493,7 @@ run_dump_test "property-x86-isa3"
run_dump_test "property-x86-isa4"
run_dump_test "pr26869"
run_dump_test "code16"
+run_dump_test "pr28870"
if { !([istarget "i?86-*-linux*"]
|| [istarget "i?86-*-gnu*"]
diff --git a/ld/testsuite/ld-i386/pr28870.d b/ld/testsuite/ld-i386/pr28870.d
new file mode 100644
index 0000000..8e9b9fb
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr28870.d
@@ -0,0 +1,10 @@
+#as: --32
+#ld: --no-dynamic-linker -m elf_i386 -pie
+#readelf: -s --wide
+
+#...
+Symbol table '.symtab' contains [0-9]+ entries:
+ Num: Value Size Type Bind Vis Ndx Name
+#...
+ +[a-f0-9]+: 00000002 0 NOTYPE LOCAL DEFAULT ABS foo
+#pass
diff --git a/ld/testsuite/ld-i386/pr28870.s b/ld/testsuite/ld-i386/pr28870.s
new file mode 100644
index 0000000..8e32047
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr28870.s
@@ -0,0 +1,6 @@
+ .text
+ .globl _start
+_start:
+ addl foo@GOT(%ebx), %eax
+ cmpl $0, foo@GOT(%ebx)
+foo = 2