[1/4] x86: don't request useless overflow checking

Message ID db540b2b-b647-e62a-080f-30c4faf1c5e6@suse.com
State New
Headers show
Series
  • x86: assorted relocation handling related adjustments (part III)
Related show

Commit Message

Claudiu Zissulescu via Binutils April 29, 2021, 9:58 a.m.
Relocations with a bitsize matching the architecture's address width
can't usefully use an overflow checking approach other than "dont" or
"signed": All others involve perhaps complex calculations in
_bfd_relocate_contents() (or, not as severe, in bfd_check_overflow())
without ever finding anything to complain about - because of the address
width masking applied. Avoid this unnecessary overhead and switch all
such reloc types to "dont".

Note that "signed" checking with rela relocations (i.e. x86-64 here) is
only going to be useful if the addend actually got passed to
_bfd_relocate_contents() (and maybe others) instead of bogusly adding in
prior section contents (which apparently is assumed to be zero, and
hence again no overflow would ever be detected). See
https://sourceware.org/pipermail/binutils/2021-April/116164.html.

bfd/
2021-04-XX  Jan Beulich  <jbeulich@suse.com>

	* elf32-i386.c (elf_howto_table): Switch all 32-bit relocs to
	complain_overflow_dont.
	* elf64-x86-64.c (x86_64_elf_howto_table): Switch all 64-bit
	relocs to complain_overflow_dont.

Patch

--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -33,34 +33,34 @@  static reloc_howto_type elf_howto_table[
   HOWTO(R_386_NONE, 0, 3, 0, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_386_NONE",
 	true, 0x00000000, 0x00000000, false),
-  HOWTO(R_386_32, 0, 2, 32, false, 0, complain_overflow_bitfield,
+  HOWTO(R_386_32, 0, 2, 32, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_386_32",
 	true, 0xffffffff, 0xffffffff, false),
-  HOWTO(R_386_PC32, 0, 2, 32, true, 0, complain_overflow_bitfield,
+  HOWTO(R_386_PC32, 0, 2, 32, true, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_386_PC32",
 	true, 0xffffffff, 0xffffffff, true),
-  HOWTO(R_386_GOT32, 0, 2, 32, false, 0, complain_overflow_bitfield,
+  HOWTO(R_386_GOT32, 0, 2, 32, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_386_GOT32",
 	true, 0xffffffff, 0xffffffff, false),
-  HOWTO(R_386_PLT32, 0, 2, 32, true, 0, complain_overflow_bitfield,
+  HOWTO(R_386_PLT32, 0, 2, 32, true, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_386_PLT32",
 	true, 0xffffffff, 0xffffffff, true),
-  HOWTO(R_386_COPY, 0, 2, 32, false, 0, complain_overflow_bitfield,
+  HOWTO(R_386_COPY, 0, 2, 32, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_386_COPY",
 	true, 0xffffffff, 0xffffffff, false),
-  HOWTO(R_386_GLOB_DAT, 0, 2, 32, false, 0, complain_overflow_bitfield,
+  HOWTO(R_386_GLOB_DAT, 0, 2, 32, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_386_GLOB_DAT",
 	true, 0xffffffff, 0xffffffff, false),
-  HOWTO(R_386_JUMP_SLOT, 0, 2, 32, false, 0, complain_overflow_bitfield,
+  HOWTO(R_386_JUMP_SLOT, 0, 2, 32, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_386_JUMP_SLOT",
 	true, 0xffffffff, 0xffffffff, false),
-  HOWTO(R_386_RELATIVE, 0, 2, 32, false, 0, complain_overflow_bitfield,
+  HOWTO(R_386_RELATIVE, 0, 2, 32, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_386_RELATIVE",
 	true, 0xffffffff, 0xffffffff, false),
-  HOWTO(R_386_GOTOFF, 0, 2, 32, false, 0, complain_overflow_bitfield,
+  HOWTO(R_386_GOTOFF, 0, 2, 32, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_386_GOTOFF",
 	true, 0xffffffff, 0xffffffff, false),
-  HOWTO(R_386_GOTPC, 0, 2, 32, true, 0, complain_overflow_bitfield,
+  HOWTO(R_386_GOTPC, 0, 2, 32, true, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_386_GOTPC",
 	true, 0xffffffff, 0xffffffff, true),
 
@@ -72,22 +72,22 @@  static reloc_howto_type elf_howto_table[
 #define R_386_ext_offset (R_386_TLS_TPOFF - R_386_standard)
 
   /* These relocs are a GNU extension.  */
-  HOWTO(R_386_TLS_TPOFF, 0, 2, 32, false, 0, complain_overflow_bitfield,
+  HOWTO(R_386_TLS_TPOFF, 0, 2, 32, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_386_TLS_TPOFF",
 	true, 0xffffffff, 0xffffffff, false),
-  HOWTO(R_386_TLS_IE, 0, 2, 32, false, 0, complain_overflow_bitfield,
+  HOWTO(R_386_TLS_IE, 0, 2, 32, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_386_TLS_IE",
 	true, 0xffffffff, 0xffffffff, false),
-  HOWTO(R_386_TLS_GOTIE, 0, 2, 32, false, 0, complain_overflow_bitfield,
+  HOWTO(R_386_TLS_GOTIE, 0, 2, 32, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_386_TLS_GOTIE",
 	true, 0xffffffff, 0xffffffff, false),
-  HOWTO(R_386_TLS_LE, 0, 2, 32, false, 0, complain_overflow_bitfield,
+  HOWTO(R_386_TLS_LE, 0, 2, 32, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_386_TLS_LE",
 	true, 0xffffffff, 0xffffffff, false),
-  HOWTO(R_386_TLS_GD, 0, 2, 32, false, 0, complain_overflow_bitfield,
+  HOWTO(R_386_TLS_GD, 0, 2, 32, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_386_TLS_GD",
 	true, 0xffffffff, 0xffffffff, false),
-  HOWTO(R_386_TLS_LDM, 0, 2, 32, false, 0, complain_overflow_bitfield,
+  HOWTO(R_386_TLS_LDM, 0, 2, 32, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_386_TLS_LDM",
 	true, 0xffffffff, 0xffffffff, false),
   HOWTO(R_386_16, 0, 1, 16, false, 0, complain_overflow_bitfield,
@@ -106,40 +106,40 @@  static reloc_howto_type elf_howto_table[
 #define R_386_ext (R_386_PC8 + 1 - R_386_ext_offset)
 #define R_386_tls_offset (R_386_TLS_LDO_32 - R_386_ext)
   /* These are common with Solaris TLS implementation.  */
-  HOWTO(R_386_TLS_LDO_32, 0, 2, 32, false, 0, complain_overflow_bitfield,
+  HOWTO(R_386_TLS_LDO_32, 0, 2, 32, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_386_TLS_LDO_32",
 	true, 0xffffffff, 0xffffffff, false),
-  HOWTO(R_386_TLS_IE_32, 0, 2, 32, false, 0, complain_overflow_bitfield,
+  HOWTO(R_386_TLS_IE_32, 0, 2, 32, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_386_TLS_IE_32",
 	true, 0xffffffff, 0xffffffff, false),
-  HOWTO(R_386_TLS_LE_32, 0, 2, 32, false, 0, complain_overflow_bitfield,
+  HOWTO(R_386_TLS_LE_32, 0, 2, 32, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_386_TLS_LE_32",
 	true, 0xffffffff, 0xffffffff, false),
-  HOWTO(R_386_TLS_DTPMOD32, 0, 2, 32, false, 0, complain_overflow_bitfield,
+  HOWTO(R_386_TLS_DTPMOD32, 0, 2, 32, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_386_TLS_DTPMOD32",
 	true, 0xffffffff, 0xffffffff, false),
-  HOWTO(R_386_TLS_DTPOFF32, 0, 2, 32, false, 0, complain_overflow_bitfield,
+  HOWTO(R_386_TLS_DTPOFF32, 0, 2, 32, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_386_TLS_DTPOFF32",
 	true, 0xffffffff, 0xffffffff, false),
-  HOWTO(R_386_TLS_TPOFF32, 0, 2, 32, false, 0, complain_overflow_bitfield,
+  HOWTO(R_386_TLS_TPOFF32, 0, 2, 32, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_386_TLS_TPOFF32",
 	true, 0xffffffff, 0xffffffff, false),
-  HOWTO(R_386_SIZE32, 0, 2, 32, false, 0, complain_overflow_unsigned,
+  HOWTO(R_386_SIZE32, 0, 2, 32, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_386_SIZE32",
 	true, 0xffffffff, 0xffffffff, false),
-  HOWTO(R_386_TLS_GOTDESC, 0, 2, 32, false, 0, complain_overflow_bitfield,
+  HOWTO(R_386_TLS_GOTDESC, 0, 2, 32, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_386_TLS_GOTDESC",
 	true, 0xffffffff, 0xffffffff, false),
   HOWTO(R_386_TLS_DESC_CALL, 0, 3, 0, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_386_TLS_DESC_CALL",
 	false, 0, 0, false),
-  HOWTO(R_386_TLS_DESC, 0, 2, 32, false, 0, complain_overflow_bitfield,
+  HOWTO(R_386_TLS_DESC, 0, 2, 32, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_386_TLS_DESC",
 	true, 0xffffffff, 0xffffffff, false),
-  HOWTO(R_386_IRELATIVE, 0, 2, 32, false, 0, complain_overflow_bitfield,
+  HOWTO(R_386_IRELATIVE, 0, 2, 32, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_386_IRELATIVE",
 	true, 0xffffffff, 0xffffffff, false),
-  HOWTO(R_386_GOT32X, 0, 2, 32, false, 0, complain_overflow_bitfield,
+  HOWTO(R_386_GOT32X, 0, 2, 32, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_386_GOT32X",
 	true, 0xffffffff, 0xffffffff, false),
 
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -47,7 +47,7 @@  static reloc_howto_type x86_64_elf_howto
   HOWTO(R_X86_64_NONE, 0, 3, 0, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_X86_64_NONE",	false, 0x00000000, 0x00000000,
 	false),
-  HOWTO(R_X86_64_64, 0, 4, 64, false, 0, complain_overflow_bitfield,
+  HOWTO(R_X86_64_64, 0, 4, 64, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_X86_64_64", false, MINUS_ONE, MINUS_ONE,
 	false),
   HOWTO(R_X86_64_PC32, 0, 2, 32, true, 0, complain_overflow_signed,
@@ -62,13 +62,13 @@  static reloc_howto_type x86_64_elf_howto
   HOWTO(R_X86_64_COPY, 0, 2, 32, false, 0, complain_overflow_bitfield,
 	bfd_elf_generic_reloc, "R_X86_64_COPY", false, 0xffffffff, 0xffffffff,
 	false),
-  HOWTO(R_X86_64_GLOB_DAT, 0, 4, 64, false, 0, complain_overflow_bitfield,
+  HOWTO(R_X86_64_GLOB_DAT, 0, 4, 64, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_X86_64_GLOB_DAT", false, MINUS_ONE,
 	MINUS_ONE, false),
-  HOWTO(R_X86_64_JUMP_SLOT, 0, 4, 64, false, 0, complain_overflow_bitfield,
+  HOWTO(R_X86_64_JUMP_SLOT, 0, 4, 64, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_X86_64_JUMP_SLOT", false, MINUS_ONE,
 	MINUS_ONE, false),
-  HOWTO(R_X86_64_RELATIVE, 0, 4, 64, false, 0, complain_overflow_bitfield,
+  HOWTO(R_X86_64_RELATIVE, 0, 4, 64, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_X86_64_RELATIVE", false, MINUS_ONE,
 	MINUS_ONE, false),
   HOWTO(R_X86_64_GOTPCREL, 0, 2, 32, true, 0, complain_overflow_signed,
@@ -88,13 +88,13 @@  static reloc_howto_type x86_64_elf_howto
 	bfd_elf_generic_reloc, "R_X86_64_8", false, 0xff, 0xff, false),
   HOWTO(R_X86_64_PC8, 0, 0, 8, true, 0, complain_overflow_signed,
 	bfd_elf_generic_reloc, "R_X86_64_PC8", false, 0xff, 0xff, true),
-  HOWTO(R_X86_64_DTPMOD64, 0, 4, 64, false, 0, complain_overflow_bitfield,
+  HOWTO(R_X86_64_DTPMOD64, 0, 4, 64, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_X86_64_DTPMOD64", false, MINUS_ONE,
 	MINUS_ONE, false),
-  HOWTO(R_X86_64_DTPOFF64, 0, 4, 64, false, 0, complain_overflow_bitfield,
+  HOWTO(R_X86_64_DTPOFF64, 0, 4, 64, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_X86_64_DTPOFF64", false, MINUS_ONE,
 	MINUS_ONE, false),
-  HOWTO(R_X86_64_TPOFF64, 0, 4, 64, false, 0, complain_overflow_bitfield,
+  HOWTO(R_X86_64_TPOFF64, 0, 4, 64, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_X86_64_TPOFF64", false, MINUS_ONE,
 	MINUS_ONE, false),
   HOWTO(R_X86_64_TLSGD, 0, 2, 32, true, 0, complain_overflow_signed,
@@ -112,10 +112,10 @@  static reloc_howto_type x86_64_elf_howto
   HOWTO(R_X86_64_TPOFF32, 0, 2, 32, false, 0, complain_overflow_signed,
 	bfd_elf_generic_reloc, "R_X86_64_TPOFF32", false, 0xffffffff,
 	0xffffffff, false),
-  HOWTO(R_X86_64_PC64, 0, 4, 64, true, 0, complain_overflow_bitfield,
+  HOWTO(R_X86_64_PC64, 0, 4, 64, true, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_X86_64_PC64", false, MINUS_ONE, MINUS_ONE,
 	true),
-  HOWTO(R_X86_64_GOTOFF64, 0, 4, 64, false, 0, complain_overflow_bitfield,
+  HOWTO(R_X86_64_GOTOFF64, 0, 4, 64, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_X86_64_GOTOFF64",
 	false, MINUS_ONE, MINUS_ONE, false),
   HOWTO(R_X86_64_GOTPC32, 0, 2, 32, true, 0, complain_overflow_signed,
@@ -139,7 +139,7 @@  static reloc_howto_type x86_64_elf_howto
   HOWTO(R_X86_64_SIZE32, 0, 2, 32, false, 0, complain_overflow_unsigned,
 	bfd_elf_generic_reloc, "R_X86_64_SIZE32", false, 0xffffffff, 0xffffffff,
 	false),
-  HOWTO(R_X86_64_SIZE64, 0, 4, 64, false, 0, complain_overflow_unsigned,
+  HOWTO(R_X86_64_SIZE64, 0, 4, 64, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_X86_64_SIZE64", false, MINUS_ONE, MINUS_ONE,
 	false),
   HOWTO(R_X86_64_GOTPC32_TLSDESC, 0, 2, 32, true, 0,
@@ -151,13 +151,13 @@  static reloc_howto_type x86_64_elf_howto
 	"R_X86_64_TLSDESC_CALL",
 	false, 0, 0, false),
   HOWTO(R_X86_64_TLSDESC, 0, 4, 64, false, 0,
-	complain_overflow_bitfield, bfd_elf_generic_reloc,
+	complain_overflow_dont, bfd_elf_generic_reloc,
 	"R_X86_64_TLSDESC",
 	false, MINUS_ONE, MINUS_ONE, false),
-  HOWTO(R_X86_64_IRELATIVE, 0, 4, 64, false, 0, complain_overflow_bitfield,
+  HOWTO(R_X86_64_IRELATIVE, 0, 4, 64, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_X86_64_IRELATIVE", false, MINUS_ONE,
 	MINUS_ONE, false),
-  HOWTO(R_X86_64_RELATIVE64, 0, 4, 64, false, 0, complain_overflow_bitfield,
+  HOWTO(R_X86_64_RELATIVE64, 0, 4, 64, false, 0, complain_overflow_dont,
 	bfd_elf_generic_reloc, "R_X86_64_RELATIVE64", false, MINUS_ONE,
 	MINUS_ONE, false),
   HOWTO(R_X86_64_PC32_BND, 0, 2, 32, true, 0, complain_overflow_signed,