aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorJan Beulich <jbeulich@suse.com>2021-04-26 10:41:35 +0200
committerJan Beulich <jbeulich@suse.com>2021-04-26 10:41:35 +0200
commita7664973b24a242cd9ea17deb5eaf503065fc0bd (patch)
tree4022b58da916ab136085e8e19bbaf812e438a678 /bfd
parent8fb8824599f37a726685197a1728e92bc7a953e5 (diff)
downloadgdb-a7664973b24a242cd9ea17deb5eaf503065fc0bd.zip
gdb-a7664973b24a242cd9ea17deb5eaf503065fc0bd.tar.gz
gdb-a7664973b24a242cd9ea17deb5eaf503065fc0bd.tar.bz2
x86: correct overflow checking for 16-bit PC-relative relocs
The only insn requiring a truly 16-bit PC-relative relocation outside of 16-bit mode is XBEGIN (with an operand size override). For it, the relocation generated should behave similar to 8- and (for 64-bit) 32-bit PC-relatives ones, i.e. be checked for a signed value to fit the field. This same mode is also correct for 16-bit code. Outside of 16-bit code, branches with operand size overrides act in a truly PC-relative way only when living in the low 32k of address space, as they truncate rIP to 16 bits. This can't be expressed by a PC-relative relocation. Putting in place a new testcase, I'd like to note that the two existing ones (pcrel16 and pcrel16abs) appear to be pretty pointless: They don't expect any error despite supposedly checking for overflow, and in fact there can't possibly be any error for the - former since gas doesn't emit any relocation in the first place there, - latter because the way the relocation gets expressed by gas doesn't allow the linker to notice the overflow; it should be detected by gas if at all, but see above (an error would be reported here for x86-64 afaict, but this test doesn't get re-used there).
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog7
-rw-r--r--bfd/elf32-i386.c2
-rw-r--r--bfd/elf64-x86-64.c2
3 files changed, 9 insertions, 2 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 701357c..45397ef 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,10 @@
+2021-04-26 Jan Beulich <jbeulich@suse.com>
+
+ * elf32-i386.c (elf_howto_table): Switch R_386_PC16 to
+ complain_overflow_signed.
+ * elf64-x86-64.c (x86_64_elf_howto_table): Switch R_X86_64_PC16
+ to complain_overflow_signed.
+
2021-04-23 Eric Botcazou <ebotcazou@adacore.com>
* elf.c (special_sections_p): Add .persistent.bss.
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index dee5352..ffe7644 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -93,7 +93,7 @@ static reloc_howto_type elf_howto_table[]=
HOWTO(R_386_16, 0, 1, 16, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_386_16",
true, 0xffff, 0xffff, false),
- HOWTO(R_386_PC16, 0, 1, 16, true, 0, complain_overflow_bitfield,
+ HOWTO(R_386_PC16, 0, 1, 16, true, 0, complain_overflow_signed,
bfd_elf_generic_reloc, "R_386_PC16",
true, 0xffff, 0xffff, true),
HOWTO(R_386_8, 0, 0, 8, false, 0, complain_overflow_bitfield,
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 1204b29..840555c 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -82,7 +82,7 @@ static reloc_howto_type x86_64_elf_howto_table[] =
false),
HOWTO(R_X86_64_16, 0, 1, 16, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_X86_64_16", false, 0xffff, 0xffff, false),
- HOWTO(R_X86_64_PC16,0, 1, 16, true, 0, complain_overflow_bitfield,
+ HOWTO(R_X86_64_PC16, 0, 1, 16, true, 0, complain_overflow_signed,
bfd_elf_generic_reloc, "R_X86_64_PC16", false, 0xffff, 0xffff, true),
HOWTO(R_X86_64_8, 0, 0, 8, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_X86_64_8", false, 0xff, 0xff, false),