aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2022-07-21 10:35:58 -0700
committerH.J. Lu <hjl.tools@gmail.com>2022-07-22 14:46:22 -0700
commit5c0b4ee406035917d0e50aa138194fab57ae6bf8 (patch)
tree80f3ce336e1b432a435ede51de3ab333d6dec002
parent19892fedb7b7e9129d76a0c48b26721d4973fb20 (diff)
downloadgdb-5c0b4ee406035917d0e50aa138194fab57ae6bf8.zip
gdb-5c0b4ee406035917d0e50aa138194fab57ae6bf8.tar.gz
gdb-5c0b4ee406035917d0e50aa138194fab57ae6bf8.tar.bz2
i386: Don't allow GOTOFF relocation against IFUNC symbol for PIC
We can't use the PLT entry as the function address for PIC since the PIC register may not be set up properly for indirect call. bfd/ PR ld/27998 * elf32-i386.c (elf_i386_relocate_section): Don't allow GOTOFF relocation against IFUNC symbol for PIC. ld/ PR ld/27998 * testsuite/ld-i386/pr27998a.d: Replace -shared with -e bar. * testsuite/ld-i386/pr27998b.d: Expect a linker error. * testsuite/ld-ifunc/ifunc-2-i386-now.d: Updated. * testsuite/ld-ifunc/ifunc-2-local-i386-now.d: Likewise. * testsuite/ld-ifunc/ifunc-2-i386.s: Replace @GOTOFF with @GOT. * testsuite/ld-ifunc/ifunc-2-local-i386.s: Likewise. (cherry picked from commit 8f29211c3f0a6335c17e0a90396c146facf6dba4)
-rw-r--r--bfd/elf32-i386.c5
-rw-r--r--ld/testsuite/ld-i386/pr27998a.d2
-rw-r--r--ld/testsuite/ld-i386/pr27998b.d6
-rw-r--r--ld/testsuite/ld-ifunc/ifunc-2-i386-now.d2
-rw-r--r--ld/testsuite/ld-ifunc/ifunc-2-i386.s2
-rw-r--r--ld/testsuite/ld-ifunc/ifunc-2-local-i386-now.d2
-rw-r--r--ld/testsuite/ld-ifunc/ifunc-2-local-i386.s2
7 files changed, 11 insertions, 10 deletions
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index 94a23bf..6666871 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -2461,6 +2461,11 @@ elf_i386_relocate_section (bfd *output_bfd,
goto do_relocation;
case R_386_GOTOFF:
+ /* NB: We can't use the PLT entry as the function address
+ for PIC since the PIC register may not be set up
+ properly for indirect call. */
+ if (bfd_link_pic (info))
+ goto bad_ifunc_reloc;
relocation -= (gotplt->output_section->vma
+ gotplt->output_offset);
goto do_relocation;
diff --git a/ld/testsuite/ld-i386/pr27998a.d b/ld/testsuite/ld-i386/pr27998a.d
index ca3c920..a801973 100644
--- a/ld/testsuite/ld-i386/pr27998a.d
+++ b/ld/testsuite/ld-i386/pr27998a.d
@@ -1,5 +1,5 @@
#as: --32
-#ld: -shared -melf_i386
+#ld: -e bar -melf_i386
#readelf: -r --wide
Relocation section '.rel.plt' at offset 0x[0-9a-f]+ contains 1 entry:
diff --git a/ld/testsuite/ld-i386/pr27998b.d b/ld/testsuite/ld-i386/pr27998b.d
index ca3c920..8f81edb 100644
--- a/ld/testsuite/ld-i386/pr27998b.d
+++ b/ld/testsuite/ld-i386/pr27998b.d
@@ -1,7 +1,3 @@
#as: --32
#ld: -shared -melf_i386
-#readelf: -r --wide
-
-Relocation section '.rel.plt' at offset 0x[0-9a-f]+ contains 1 entry:
- Offset Info Type Sym. Value Symbol's Name
-[0-9a-f]+ +[0-9a-f]+ +R_386_IRELATIVE +
+#error: relocation R_386_GOTOFF against STT_GNU_IFUNC symbol `foo' isn't supported
diff --git a/ld/testsuite/ld-ifunc/ifunc-2-i386-now.d b/ld/testsuite/ld-ifunc/ifunc-2-i386-now.d
index aae24b2..3a744d1 100644
--- a/ld/testsuite/ld-ifunc/ifunc-2-i386-now.d
+++ b/ld/testsuite/ld-ifunc/ifunc-2-i386-now.d
@@ -31,6 +31,6 @@ Disassembly of section .text:
+[a-f0-9]+: 5b pop %ebx
+[a-f0-9]+: 81 c3 9e 10 00 00 add \$0x109e,%ebx
+[a-f0-9]+: e8 de ff ff ff call 100 <\*ABS\*@plt>
- +[a-f0-9]+: 8d 83 4c ef ff ff lea -0x10b4\(%ebx\),%eax
+ +[a-f0-9]+: 8b 83 0c 00 00 00 mov 0xc\(%ebx\),%eax
+[a-f0-9]+: c3 ret
#pass
diff --git a/ld/testsuite/ld-ifunc/ifunc-2-i386.s b/ld/testsuite/ld-ifunc/ifunc-2-i386.s
index e84d6b7..1acf684 100644
--- a/ld/testsuite/ld-ifunc/ifunc-2-i386.s
+++ b/ld/testsuite/ld-ifunc/ifunc-2-i386.s
@@ -16,6 +16,6 @@ bar:
popl %ebx
addl $_GLOBAL_OFFSET_TABLE_+[.-.L6], %ebx
call __GI_foo@PLT
- leal __GI_foo@GOTOFF(%ebx), %eax
+ movl __GI_foo@GOT(%ebx), %eax
ret
.size bar, .-bar
diff --git a/ld/testsuite/ld-ifunc/ifunc-2-local-i386-now.d b/ld/testsuite/ld-ifunc/ifunc-2-local-i386-now.d
index 86083c1..739058b 100644
--- a/ld/testsuite/ld-ifunc/ifunc-2-local-i386-now.d
+++ b/ld/testsuite/ld-ifunc/ifunc-2-local-i386-now.d
@@ -31,6 +31,6 @@ Disassembly of section .text:
+[a-f0-9]+: 5b pop %ebx
+[a-f0-9]+: 81 c3 9e 10 00 00 add \$0x109e,%ebx
+[a-f0-9]+: e8 de ff ff ff call f0 <\*ABS\*@plt>
- +[a-f0-9]+: 8d 83 4c ef ff ff lea -0x10b4\(%ebx\),%eax
+ +[a-f0-9]+: 8b 83 0c 00 00 00 mov 0xc\(%ebx\),%eax
+[a-f0-9]+: c3 ret
#pass
diff --git a/ld/testsuite/ld-ifunc/ifunc-2-local-i386.s b/ld/testsuite/ld-ifunc/ifunc-2-local-i386.s
index a69e060..54e0e17 100644
--- a/ld/testsuite/ld-ifunc/ifunc-2-local-i386.s
+++ b/ld/testsuite/ld-ifunc/ifunc-2-local-i386.s
@@ -13,6 +13,6 @@ bar:
popl %ebx
addl $_GLOBAL_OFFSET_TABLE_+[.-.L6], %ebx
call __GI_foo@PLT
- leal __GI_foo@GOTOFF(%ebx), %eax
+ movl __GI_foo@GOT(%ebx), %eax
ret
.size bar, .-bar