aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2011-08-01 23:04:23 +0000
committerH.J. Lu <hjl.tools@gmail.com>2011-08-01 23:04:23 +0000
commitd7921315bafbc6419613771c6ad075e3cf160a0e (patch)
tree6584835bb8a8d456e85f2b491657a2934aa16032 /bfd
parentc3f7b0e5a192ae55613bed418690637a3ebbc2c5 (diff)
downloadgdb-d7921315bafbc6419613771c6ad075e3cf160a0e.zip
gdb-d7921315bafbc6419613771c6ad075e3cf160a0e.tar.gz
gdb-d7921315bafbc6419613771c6ad075e3cf160a0e.tar.bz2
Check R_X86_64_32 overflow and allow R_X86_64_64 for x32.
bfd/ 2011-08-01 H.J. Lu <hongjiu.lu@intel.com> PR ld/13048 * archures.c (bfd_mach_i386_intel_syntax): New. (bfd_mach_i386_i8086): Updated. (bfd_mach_i386_i386): Likewise. (bfd_mach_x86_64): Likewise. (bfd_mach_x64_32): Likewise. (bfd_mach_i386_i386_intel_syntax): Likewise. (bfd_mach_x86_64_intel_syntax): Likewise. (bfd_mach_x64_32_intel_syntax): Likewise. (bfd_mach_l1om): Likewise. (bfd_mach_l1om_intel_syntax): Likewise. (bfd_mach_k1om): Likewise. (bfd_mach_k1om_intel_syntax): Likewise. * bfd-in2.h: Regenerated. * cpu-i386.c (bfd_i386_compatible): Check mach instead of bits_per_address. (bfd_x64_32_arch_intel_syntax): Set bits_per_address to 64. (bfd_x64_32_arch): Likewise. * elf64-x86-64.c: Include "libiberty.h". (x86_64_elf_howto_table): Append x32 R_X86_64_32. (elf_x86_64_rtype_to_howto): Support x32 R_X86_64_32. (elf_x86_64_reloc_type_lookup): Likewise. (elf_x86_64_reloc_name_lookup): Likewise. (elf_x86_64_relocate_section): Likewise. (elf_x86_64_check_relocs): Allow R_X86_64_64 relocations for x32. gas/ 2011-08-01 H.J. Lu <hongjiu.lu@intel.com> PR ld/13048 * config/tc-i386.c (handle_quad): Removed. (md_pseudo_table): Remove "quad". (tc_gen_reloc): Don't check BFD_RELOC_64 for disallow_64bit_reloc. (x86_dwarf2_addr_size): New. * config/tc-i386.h (x86_dwarf2_addr_size): New. (DWARF2_ADDR_SIZE): Likewise. gas/testsuite/ 2011-08-01 H.J. Lu <hongjiu.lu@intel.com> PR ld/13048 * gas/i386/ilp32/ilp32.exp: Don't run inval. * gas/i386/ilp32/inval.l: Removed. * gas/i386/ilp32/inval.s: Likewise. * gas/i386/ilp32/quad.d: Expect R_X86_64_64 instead of R_X86_64_32. * gas/i386/ilp32/x86-64-pcrel.s: Add tests for movabs. * gas/i386/ilp32/x86-64-pcrel.d: Updated. ld/testsuite/ 2011-08-01 H.J. Lu <hongjiu.lu@intel.com> PR ld/13048 * ld-x86-64/ilp32-6.d: New. * ld-x86-64/ilp32-6.s: Likewise. * ld-x86-64/ilp32-7.d: Likewise. * ld-x86-64/ilp32-7.s: Likewise. * ld-x86-64/ilp32-8.d: Likewise. * ld-x86-64/ilp32-8.s: Likewise. * ld-x86-64/ilp32-9.d: Likewise. * ld-x86-64/ilp32-9.s: Likewise. * ld-x86-64/x86-64.exp: Run ilp32-6, ilp32-7, ilp32-8 and ilp32-9. opcodes/ 2011-08-01 H.J. Lu <hongjiu.lu@intel.com> PR ld/13048 * i386-dis.c (print_insn): Optimize info->mach check.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog31
-rw-r--r--bfd/archures.c23
-rw-r--r--bfd/bfd-in2.h23
-rw-r--r--bfd/cpu-i386.c7
-rw-r--r--bfd/elf64-x86-64.c50
5 files changed, 92 insertions, 42 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 9a4b3f6..2ef3686 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,34 @@
+2011-08-01 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR ld/13048
+ * archures.c (bfd_mach_i386_intel_syntax): New.
+ (bfd_mach_i386_i8086): Updated.
+ (bfd_mach_i386_i386): Likewise.
+ (bfd_mach_x86_64): Likewise.
+ (bfd_mach_x64_32): Likewise.
+ (bfd_mach_i386_i386_intel_syntax): Likewise.
+ (bfd_mach_x86_64_intel_syntax): Likewise.
+ (bfd_mach_x64_32_intel_syntax): Likewise.
+ (bfd_mach_l1om): Likewise.
+ (bfd_mach_l1om_intel_syntax): Likewise.
+ (bfd_mach_k1om): Likewise.
+ (bfd_mach_k1om_intel_syntax): Likewise.
+
+ * bfd-in2.h: Regenerated.
+
+ * cpu-i386.c (bfd_i386_compatible): Check mach instead of
+ bits_per_address.
+ (bfd_x64_32_arch_intel_syntax): Set bits_per_address to 64.
+ (bfd_x64_32_arch): Likewise.
+
+ * elf64-x86-64.c: Include "libiberty.h".
+ (x86_64_elf_howto_table): Append x32 R_X86_64_32.
+ (elf_x86_64_rtype_to_howto): Support x32 R_X86_64_32.
+ (elf_x86_64_reloc_type_lookup): Likewise.
+ (elf_x86_64_reloc_name_lookup): Likewise.
+ (elf_x86_64_relocate_section): Likewise.
+ (elf_x86_64_check_relocs): Allow R_X86_64_64 relocations for x32.
+
2011-07-29 Maciej W. Rozycki <macro@codesourcery.com>
* elfxx-mips.c (check_br32): Fix return type.
diff --git a/bfd/archures.c b/bfd/archures.c
index 65682f2..44850e7 100644
--- a/bfd/archures.c
+++ b/bfd/archures.c
@@ -183,19 +183,20 @@ DESCRIPTION
.#define bfd_mach_mipsisa64r2 65
.#define bfd_mach_mips_micromips 96
. bfd_arch_i386, {* Intel 386 *}
-.#define bfd_mach_i386_i386 1
-.#define bfd_mach_i386_i8086 2
-.#define bfd_mach_i386_i386_intel_syntax 3
-.#define bfd_mach_x64_32 32
-.#define bfd_mach_x64_32_intel_syntax 33
-.#define bfd_mach_x86_64 64
-.#define bfd_mach_x86_64_intel_syntax 65
+.#define bfd_mach_i386_intel_syntax (1 << 0)
+.#define bfd_mach_i386_i8086 (1 << 1)
+.#define bfd_mach_i386_i386 (1 << 2)
+.#define bfd_mach_x86_64 (1 << 3)
+.#define bfd_mach_x64_32 (1 << 4)
+.#define bfd_mach_i386_i386_intel_syntax (bfd_mach_i386_i386 | bfd_mach_i386_intel_syntax)
+.#define bfd_mach_x86_64_intel_syntax (bfd_mach_x86_64 | bfd_mach_i386_intel_syntax)
+.#define bfd_mach_x64_32_intel_syntax (bfd_mach_x64_32 | bfd_mach_i386_intel_syntax)
. bfd_arch_l1om, {* Intel L1OM *}
-.#define bfd_mach_l1om 66
-.#define bfd_mach_l1om_intel_syntax 67
+.#define bfd_mach_l1om (1 << 5)
+.#define bfd_mach_l1om_intel_syntax (bfd_mach_l1om | bfd_mach_i386_intel_syntax)
. bfd_arch_k1om, {* Intel K1OM *}
-.#define bfd_mach_k1om 68
-.#define bfd_mach_k1om_intel_syntax 69
+.#define bfd_mach_k1om (1 << 6)
+.#define bfd_mach_k1om_intel_syntax (bfd_mach_k1om | bfd_mach_i386_intel_syntax)
. bfd_arch_we32k, {* AT&T WE32xxx *}
. bfd_arch_tahoe, {* CCI/Harris Tahoe *}
. bfd_arch_i860, {* Intel 860 *}
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index 6b7be67..ac8145d 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -1886,19 +1886,20 @@ enum bfd_architecture
#define bfd_mach_mipsisa64r2 65
#define bfd_mach_mips_micromips 96
bfd_arch_i386, /* Intel 386 */
-#define bfd_mach_i386_i386 1
-#define bfd_mach_i386_i8086 2
-#define bfd_mach_i386_i386_intel_syntax 3
-#define bfd_mach_x64_32 32
-#define bfd_mach_x64_32_intel_syntax 33
-#define bfd_mach_x86_64 64
-#define bfd_mach_x86_64_intel_syntax 65
+#define bfd_mach_i386_intel_syntax (1 << 0)
+#define bfd_mach_i386_i8086 (1 << 1)
+#define bfd_mach_i386_i386 (1 << 2)
+#define bfd_mach_x86_64 (1 << 3)
+#define bfd_mach_x64_32 (1 << 4)
+#define bfd_mach_i386_i386_intel_syntax (bfd_mach_i386_i386 | bfd_mach_i386_intel_syntax)
+#define bfd_mach_x86_64_intel_syntax (bfd_mach_x86_64 | bfd_mach_i386_intel_syntax)
+#define bfd_mach_x64_32_intel_syntax (bfd_mach_x64_32 | bfd_mach_i386_intel_syntax)
bfd_arch_l1om, /* Intel L1OM */
-#define bfd_mach_l1om 66
-#define bfd_mach_l1om_intel_syntax 67
+#define bfd_mach_l1om (1 << 5)
+#define bfd_mach_l1om_intel_syntax (bfd_mach_l1om | bfd_mach_i386_intel_syntax)
bfd_arch_k1om, /* Intel K1OM */
-#define bfd_mach_k1om 68
-#define bfd_mach_k1om_intel_syntax 69
+#define bfd_mach_k1om (1 << 6)
+#define bfd_mach_k1om_intel_syntax (bfd_mach_k1om | bfd_mach_i386_intel_syntax)
bfd_arch_we32k, /* AT&T WE32xxx */
bfd_arch_tahoe, /* CCI/Harris Tahoe */
bfd_arch_i860, /* Intel 860 */
diff --git a/bfd/cpu-i386.c b/bfd/cpu-i386.c
index c4f41c5..f98c0e5 100644
--- a/bfd/cpu-i386.c
+++ b/bfd/cpu-i386.c
@@ -31,7 +31,8 @@ bfd_i386_compatible (const bfd_arch_info_type *a,
const bfd_arch_info_type *compat = bfd_default_compatible (a, b);
/* Don't allow mixing x64_32 with x86_64. */
- if (compat && a->bits_per_address != b->bits_per_address)
+ if (compat
+ && (a->mach & bfd_mach_x64_32) != (b->mach & bfd_mach_x64_32))
compat = NULL;
return compat;
@@ -40,7 +41,7 @@ bfd_i386_compatible (const bfd_arch_info_type *a,
static const bfd_arch_info_type bfd_x64_32_arch_intel_syntax =
{
64, /* 64 bits in a word */
- 32, /* 32 bits in an address */
+ 64, /* 64 bits in an address */
8, /* 8 bits in a byte */
bfd_arch_i386,
bfd_mach_x64_32_intel_syntax,
@@ -104,7 +105,7 @@ static const bfd_arch_info_type i8086_arch =
static const bfd_arch_info_type bfd_x64_32_arch =
{
64, /* 64 bits in a word */
- 32, /* 32 bits in an address */
+ 64, /* 64 bits in an address */
8, /* 8 bits in a byte */
bfd_arch_i386,
bfd_mach_x64_32,
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 975b558..7b92097 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -30,6 +30,7 @@
#include "objalloc.h"
#include "hashtab.h"
#include "dwarf2.h"
+#include "libiberty.h"
#include "elf/x86-64.h"
@@ -178,7 +179,12 @@ static reloc_howto_type x86_64_elf_howto_table[] =
/* GNU extension to record C++ vtable member usage. */
HOWTO (R_X86_64_GNU_VTENTRY, 0, 4, 0, FALSE, 0, complain_overflow_dont,
_bfd_elf_rel_vtable_reloc_fn, "R_X86_64_GNU_VTENTRY", FALSE, 0, 0,
- FALSE)
+ FALSE),
+
+/* Use complain_overflow_bitfield on R_X86_64_32 for x32. */
+ HOWTO(R_X86_64_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
+ bfd_elf_generic_reloc, "R_X86_64_32", FALSE, 0xffffffff, 0xffffffff,
+ FALSE)
};
#define IS_X86_64_PCREL_TYPE(TYPE) \
@@ -241,8 +247,15 @@ elf_x86_64_rtype_to_howto (bfd *abfd, unsigned r_type)
{
unsigned i;
- if (r_type < (unsigned int) R_X86_64_GNU_VTINHERIT
- || r_type >= (unsigned int) R_X86_64_max)
+ if (r_type == (unsigned int) R_X86_64_32)
+ {
+ if (ABI_64_P (abfd))
+ i = r_type;
+ else
+ i = ARRAY_SIZE (x86_64_elf_howto_table) - 1;
+ }
+ else if (r_type < (unsigned int) R_X86_64_GNU_VTINHERIT
+ || r_type >= (unsigned int) R_X86_64_max)
{
if (r_type >= (unsigned int) R_X86_64_standard)
{
@@ -276,15 +289,21 @@ elf_x86_64_reloc_type_lookup (bfd *abfd,
}
static reloc_howto_type *
-elf_x86_64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
+elf_x86_64_reloc_name_lookup (bfd *abfd,
const char *r_name)
{
unsigned int i;
- for (i = 0;
- i < (sizeof (x86_64_elf_howto_table)
- / sizeof (x86_64_elf_howto_table[0]));
- i++)
+ if (!ABI_64_P (abfd) && strcasecmp (r_name, "R_X86_64_32") == 0)
+ {
+ /* Get x32 R_X86_64_32. */
+ reloc_howto_type *reloc
+ = &x86_64_elf_howto_table[ARRAY_SIZE (x86_64_elf_howto_table) - 1];
+ BFD_ASSERT (reloc->type == (unsigned int) R_X86_64_32);
+ return reloc;
+ }
+
+ for (i = 0; i < ARRAY_SIZE (x86_64_elf_howto_table); i++)
if (x86_64_elf_howto_table[i].name != NULL
&& strcasecmp (x86_64_elf_howto_table[i].name, r_name) == 0)
return &x86_64_elf_howto_table[i];
@@ -1396,14 +1415,6 @@ elf_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
default:
break;
- case R_X86_64_64:
- /* Allow R_X86_64_64 relocations in SEC_DEBUGGING sections
- when building shared libraries. */
- if (info->shared
- && !info->executable
- && (sec->flags & SEC_DEBUGGING) != 0)
- break;
-
case R_X86_64_DTPOFF64:
case R_X86_64_TPOFF64:
case R_X86_64_PC64:
@@ -3022,7 +3033,12 @@ elf_x86_64_relocate_section (bfd *output_bfd,
return FALSE;
}
- howto = x86_64_elf_howto_table + r_type;
+ if (r_type != (int) R_X86_64_32
+ || ABI_64_P (output_bfd))
+ howto = x86_64_elf_howto_table + r_type;
+ else
+ howto = (x86_64_elf_howto_table
+ + ARRAY_SIZE (x86_64_elf_howto_table) - 1);
r_symndx = htab->r_sym (rel->r_info);
h = NULL;
sym = NULL;