This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] Set CPU type in BFD backend for x86_64-nacl* and i?86-nacl* targets
- From: Roland McGrath <mcgrathr at google dot com>
- To: "binutils at sourceware dot org" <binutils at sourceware dot org>
- Date: Wed, 6 Nov 2013 16:36:12 -0800
- Subject: [PATCH] Set CPU type in BFD backend for x86_64-nacl* and i?86-nacl* targets
- Authentication-results: sourceware.org; auth=none
When I made the NaCl variants in bfd/cpu-i386.c and got the linker to use
them, I neglected to make them the defaults for the BFD backends so that
objcopy/strip and the like would use them too. Changing state in the
elf_object_p hook seems to be the way this is done, loony as that seems.
Fixing this revealed that I had botched the addition of the
bfd_mach_i386_nacl bit flag, using the same bit already assigned to
bfd_mach_l1om (which affects disassembler output). It also necessitated
adjusting objdump.c to treat the *_nacl variants like their baselines, and
loosening some test cases' error message matching to accept the ":nacl"
variants of the CPU strings.
OK for trunk and 2.24?
Thanks,
Roland
bfd/
2013-11-06 Roland McGrath <mcgrathr@google.com>
* archures.c (bfd_mach_i386_nacl): Fix definition so it doesn't
collide with bfd_mach_l1om.
* bfd-in2.h: Regenerate.
* elf32-i386.c (elf32_i386_nacl_elf_object_p): New function.
(elf_backend_object_p): Use that in elf32-i386-nacl definition.
* elf64-x86-64.c (elf64_x86_64_nacl_elf_object_p): New function.
(elf_backend_object_p): Use that in elf64-x86-64-nacl definition.
(elf32_x86_64_nacl_elf_object_p): New function.
(elf_backend_object_p): Use that in elf32-x86-64-nacl definition.
binutils/
2013-11-06 Roland McGrath <mcgrathr@google.com>
* objdump.c (dump_dwarf): Grok bfd_mach_x86_64_nacl and
bfd_mach_x64_32_nacl as equivalent to bfd_mach_x86_64.
ld/testsuite/
2013-11-06 Roland McGrath <mcgrathr@google.com>
* ld-x86-64/x86-64.exp (mixed1, mixed2): Loosen error string match
so it accepts "i386:nacl" in place of "i386".
* ld-x86-64/ilp32-2.d: Likewise.
* ld-x86-64/ilp32-3.d: Likewise.
* ld-x86-64/lp64-2.d: Likewise.
* ld-x86-64/lp64-3.d: Likewise.
--- a/bfd/archures.c
+++ b/bfd/archures.c
@@ -189,19 +189,19 @@ DESCRIPTION
.#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_nacl (1 << 5)
.#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)
-.#define bfd_mach_i386_i386_nacl (bfd_mach_i386_i386 | bfd_mach_i386_nacl)
-.#define bfd_mach_x86_64_nacl (bfd_mach_x86_64 | bfd_mach_i386_nacl)
-.#define bfd_mach_x64_32_nacl (bfd_mach_x64_32 | bfd_mach_i386_nacl)
. bfd_arch_l1om, {* Intel L1OM *}
.#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 (1 << 6)
.#define bfd_mach_k1om_intel_syntax (bfd_mach_k1om |
bfd_mach_i386_intel_syntax)
+.#define bfd_mach_i386_nacl (1 << 7)
+.#define bfd_mach_i386_i386_nacl (bfd_mach_i386_i386 | bfd_mach_i386_nacl)
+.#define bfd_mach_x86_64_nacl (bfd_mach_x86_64 | bfd_mach_i386_nacl)
+.#define bfd_mach_x64_32_nacl (bfd_mach_x64_32 | bfd_mach_i386_nacl)
. bfd_arch_we32k, {* AT&T WE32xxx *}
. bfd_arch_tahoe, {* CCI/Harris Tahoe *}
. bfd_arch_i860, {* Intel 860 *}
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -1946,19 +1946,19 @@ enum bfd_architecture
#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_nacl (1 << 5)
#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)
-#define bfd_mach_i386_i386_nacl (bfd_mach_i386_i386 |
bfd_mach_i386_nacl)
-#define bfd_mach_x86_64_nacl (bfd_mach_x86_64 | bfd_mach_i386_nacl)
-#define bfd_mach_x64_32_nacl (bfd_mach_x64_32 | bfd_mach_i386_nacl)
bfd_arch_l1om, /* Intel L1OM */
#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 (1 << 6)
#define bfd_mach_k1om_intel_syntax (bfd_mach_k1om |
bfd_mach_i386_intel_syntax)
+#define bfd_mach_i386_nacl (1 << 7)
+#define bfd_mach_i386_i386_nacl (bfd_mach_i386_i386 |
bfd_mach_i386_nacl)
+#define bfd_mach_x86_64_nacl (bfd_mach_x86_64 | bfd_mach_i386_nacl)
+#define bfd_mach_x64_32_nacl (bfd_mach_x64_32 | bfd_mach_i386_nacl)
bfd_arch_we32k, /* AT&T WE32xxx */
bfd_arch_tahoe, /* CCI/Harris Tahoe */
bfd_arch_i860, /* Intel 860 */
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -5296,9 +5296,19 @@ static const struct elf_i386_backend_data
elf_i386_nacl_arch_bed =
0, /* is_vxworks */
};
+static bfd_boolean
+elf32_i386_nacl_elf_object_p (bfd *abfd)
+{
+ /* Set the right machine number for a NaCl i386 ELF32 file. */
+ bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_i386_i386_nacl);
+ return TRUE;
+}
+
#undef elf_backend_arch_data
#define elf_backend_arch_data &elf_i386_nacl_arch_bed
+#undef elf_backend_object_p
+#define elf_backend_object_p elf32_i386_nacl_elf_object_p
#undef elf_backend_modify_segment_map
#define elf_backend_modify_segment_map nacl_modify_segment_map
#undef elf_backend_modify_program_headers
@@ -5309,6 +5319,7 @@ static const struct elf_i386_backend_data
elf_i386_nacl_arch_bed =
#include "elf32-target.h"
/* Restore defaults. */
+#undef elf_backend_object_p
#undef elf_backend_modify_segment_map
#undef elf_backend_modify_program_headers
#undef elf_backend_final_write_processing
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -5348,6 +5348,14 @@ static const struct bfd_elf_special_section
/* Native Client support. */
+static bfd_boolean
+elf64_x86_64_nacl_elf_object_p (bfd *abfd)
+{
+ /* Set the right machine number for a NaCl x86-64 ELF64 file. */
+ bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x86_64_nacl);
+ return TRUE;
+}
+
#undef TARGET_LITTLE_SYM
#define TARGET_LITTLE_SYM bfd_elf64_x86_64_nacl_vec
#undef TARGET_LITTLE_NAME
@@ -5480,6 +5488,8 @@ static const struct elf_x86_64_backend_data
elf_x86_64_nacl_arch_bed =
#undef elf_backend_arch_data
#define elf_backend_arch_data &elf_x86_64_nacl_arch_bed
+#undef elf_backend_object_p
+#define elf_backend_object_p elf64_x86_64_nacl_elf_object_p
#undef elf_backend_modify_segment_map
#define elf_backend_modify_segment_map nacl_modify_segment_map
#undef elf_backend_modify_program_headers
@@ -5491,6 +5501,14 @@ static const struct elf_x86_64_backend_data
elf_x86_64_nacl_arch_bed =
/* Native Client x32 support. */
+static bfd_boolean
+elf32_x86_64_nacl_elf_object_p (bfd *abfd)
+{
+ /* Set the right machine number for a NaCl x86-64 ELF32 file. */
+ bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x64_32_nacl);
+ return TRUE;
+}
+
#undef TARGET_LITTLE_SYM
#define TARGET_LITTLE_SYM bfd_elf32_x86_64_nacl_vec
#undef TARGET_LITTLE_NAME
@@ -5511,7 +5529,7 @@ static const struct elf_x86_64_backend_data
elf_x86_64_nacl_arch_bed =
#undef elf_backend_object_p
#define elf_backend_object_p \
- elf32_x86_64_elf_object_p
+ elf32_x86_64_nacl_elf_object_p
#undef elf_backend_bfd_from_remote_memory
#define elf_backend_bfd_from_remote_memory \
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -27,14 +27,14 @@
relocations, debugging directives and more.
The flow of execution is as follows:
-
+
1. Command line arguments are checked for control switches and the
information to be displayed is selected.
-
+
2. Any remaining arguments are assumed to be object files, and they are
processed in order by display_bfd(). If the file is an archive each
of its elements is processed in turn.
-
+
3. The file's target architecture and binary file format are determined
by bfd_check_format(). If they are recognised, then dump_bfd() is
called.
@@ -905,7 +905,7 @@ find_symbol_for_address (bfd_vma vma,
sections have overlapping memory ranges, but in that case there's
no way to tell what's desired without looking at the relocation
table.
-
+
Also give the target a chance to reject symbols. */
want_section = (aux->require_sec
|| ((abfd->flags & HAS_RELOC) != 0
@@ -1097,9 +1097,9 @@ struct print_file_list
struct print_file_list *next;
const char *filename;
const char *modname;
- const char *map;
+ const char *map;
size_t mapsize;
- const char **linemap;
+ const char **linemap;
unsigned maxline;
unsigned last_line;
int first;
@@ -1156,38 +1156,38 @@ slurp_file (const char *fn, size_t *size)
/* Precompute array of lines for a mapped file. */
-static const char **
-index_file (const char *map, size_t size, unsigned int *maxline)
+static const char **
+index_file (const char *map, size_t size, unsigned int *maxline)
{
const char *p, *lstart, *end;
int chars_per_line = 45; /* First iteration will use 40. */
unsigned int lineno;
- const char **linemap = NULL;
+ const char **linemap = NULL;
unsigned long line_map_size = 0;
-
+
lineno = 0;
lstart = map;
end = map + size;
- for (p = map; p < end; p++)
- {
- if (*p == '\n')
- {
- if (p + 1 < end && p[1] == '\r')
- p++;
- }
- else if (*p == '\r')
- {
+ for (p = map; p < end; p++)
+ {
+ if (*p == '\n')
+ {
+ if (p + 1 < end && p[1] == '\r')
+ p++;
+ }
+ else if (*p == '\r')
+ {
if (p + 1 < end && p[1] == '\n')
p++;
}
else
continue;
-
+
/* End of line found. */
- if (linemap == NULL || line_map_size < lineno + 1)
- {
+ if (linemap == NULL || line_map_size < lineno + 1)
+ {
unsigned long newsize;
chars_per_line -= line_map_decrease;
@@ -1200,11 +1200,11 @@ index_file (const char *map, size_t size,
unsigned int *maxline)
linemap = (const char **) xrealloc (linemap, newsize);
}
- linemap[lineno++] = lstart;
- lstart = p + 1;
+ linemap[lineno++] = lstart;
+ lstart = p + 1;
}
-
- *maxline = lineno;
+
+ *maxline = lineno;
return linemap;
}
@@ -1224,7 +1224,7 @@ try_print_file_open (const char *origname, const
char *modname)
free (p);
return NULL;
}
-
+
p->linemap = index_file (p->map, p->mapsize, &p->maxline);
p->last_line = 0;
p->filename = origname;
@@ -1274,13 +1274,13 @@ update_source_path (const char *filename)
/* Print a source file line. */
-static void
+static void
print_line (struct print_file_list *p, unsigned int linenum)
{
const char *l;
size_t len;
-
- --linenum;
+
+ --linenum;
if (linenum >= p->maxline)
return;
l = p->linemap [linenum];
@@ -1297,7 +1297,7 @@ dump_lines (struct print_file_list *p, unsigned
int start, unsigned int end)
{
if (p->map == NULL)
return;
- while (start <= end)
+ while (start <= end)
{
print_line (p, start);
start++;
@@ -1373,9 +1373,9 @@ show_line (bfd *abfd, asection *section, bfd_vma
addr_offset)
&& (prev_functionname == NULL
|| strcmp (functionname, prev_functionname) != 0))
printf ("%s():\n", functionname);
- if (linenumber > 0 && (linenumber != prev_line ||
+ if (linenumber > 0 && (linenumber != prev_line ||
(discriminator != prev_discriminator)))
- {
+ {
if (discriminator > 0)
printf ("%s:%u (discriminator %u)\n", filename == NULL ?
"???" : filename,
linenumber, discriminator);
@@ -1405,12 +1405,12 @@ show_line (bfd *abfd, asection *section,
bfd_vma addr_offset)
if (p != NULL && linenumber != p->last_line)
{
- if (file_start_context && p->first)
+ if (file_start_context && p->first)
l = 1;
- else
+ else
{
l = linenumber - SHOW_PRECEDING_CONTEXT_LINES;
- if (l >= linenumber)
+ if (l >= linenumber)
l = 1;
if (p->last_line >= l && p->last_line <= linenumber)
l = p->last_line + 1;
@@ -1457,19 +1457,19 @@ objdump_sprintf (SFILE *f, const char *format, ...)
while (1)
{
size_t space = f->alloc - f->pos;
-
+
va_start (args, format);
n = vsnprintf (f->buffer + f->pos, space, format, args);
va_end (args);
if (space > n)
break;
-
+
f->alloc = (f->alloc + n) * 2;
f->buffer = (char *) xrealloc (f->buffer, f->alloc);
}
f->pos += n;
-
+
return n;
}
@@ -1517,7 +1517,7 @@ disassemble_bytes (struct disassemble_info * inf,
sfile.alloc = 120;
sfile.buffer = (char *) xmalloc (sfile.alloc);
sfile.pos = 0;
-
+
if (insn_width)
octets_per_line = insn_width;
else if (insns)
@@ -2061,7 +2061,7 @@ disassemble_section (bfd *abfd, asection
*section, void *inf)
((SYM)->section == section \
&& (bfd_asymbol_value (SYM) > bfd_asymbol_value (sym)) \
&& pinfo->symbol_is_valid (SYM, pinfo))
-
+
/* Search forward for the next appropriate symbol in
SECTION. Note that all the symbols are sorted
together into one big array, and that some sections
@@ -2107,7 +2107,7 @@ disassemble_section (bfd *abfd, asection
*section, void *inf)
disassemble_bytes (pinfo, paux->disassemble_fn, insns, data,
addr_offset, nextstop_offset,
rel_offset, &rel_pp, rel_ppend);
-
+
addr_offset = nextstop_offset;
sym = nextsym;
}
@@ -2219,7 +2219,7 @@ disassemble_data (bfd *abfd)
if (dump_dynamic_reloc_info)
{
long relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
-
+
if (relsize < 0)
bfd_fatal (bfd_get_filename (abfd));
@@ -2363,7 +2363,7 @@ dump_dwarf_section (bfd *abfd, asection *section,
section, abfd))
{
debug_displays [i].display (sec, abfd);
-
+
if (i != info && i != abbrev)
free_debug_section ((enum dwarf_section_display_enum) i);
}
@@ -2394,8 +2394,10 @@ dump_dwarf (bfd *abfd)
{
case bfd_mach_x86_64:
case bfd_mach_x86_64_intel_syntax:
+ case bfd_mach_x86_64_nacl:
case bfd_mach_x64_32:
case bfd_mach_x64_32_intel_syntax:
+ case bfd_mach_x64_32_nacl:
init_dwarf_regnames_x86_64 ();
break;
@@ -2565,7 +2567,7 @@ find_stabs_section (bfd *abfd, asection
*section, void *names)
if (strtab == NULL)
strtab = read_section_stabs (abfd, sought->string_section_name,
&stabstr_size);
-
+
if (strtab)
{
stabs = (bfd_byte *) read_section_stabs (abfd, section->name,
@@ -2715,7 +2717,7 @@ dump_section (bfd *abfd, asection *section, void
*dummy ATTRIBUTE_UNUSED)
if (! process_section_p (section))
return;
-
+
if ((datasize = bfd_section_size (abfd, section)) == 0)
return;
@@ -2741,7 +2743,7 @@ dump_section (bfd *abfd, asection *section, void
*dummy ATTRIBUTE_UNUSED)
if (start_offset >= stop_offset)
return;
-
+
printf (_("Contents of section %s:"), section->name);
if (display_file_offsets)
printf (_(" (Starting at file offset: 0x%lx)"),
@@ -3272,7 +3274,7 @@ dump_bfd (bfd *abfd)
info in the file, try DWARF instead. */
else if (! dump_dwarf_section_info)
{
- dwarf_select_sections_all ();
+ dwarf_select_sections_all ();
dump_dwarf (abfd);
}
}
--- a/ld/testsuite/ld-x86-64/ilp32-2.d
+++ b/ld/testsuite/ld-x86-64/ilp32-2.d
@@ -1,4 +1,4 @@
#source: dummy.s
#as: --x32
#ld: -m elf32_x86_64 tmpdir/startx32.o tmpdir/foo32.o
-#error: .*i386 architecture of input file `tmpdir/foo32.o' is
incompatible with i386:x64-32.* output
+#error: .*i386(:.+)? architecture of input file `tmpdir/foo32.o' is
incompatible with i386:x64-32.* output
--- a/ld/testsuite/ld-x86-64/ilp32-3.d
+++ b/ld/testsuite/ld-x86-64/ilp32-3.d
@@ -1,4 +1,4 @@
#source: dummy.s
#as: --x32
#ld: -m elf32_x86_64 tmpdir/startx32.o tmpdir/foo64.o
-#error: .*i386:x86-64 architecture of input file `tmpdir/foo64.o' is
incompatible with i386:x64-32.* output
+#error: .*i386:x86-64(:.+)? architecture of input file
`tmpdir/foo64.o' is incompatible with i386:x64-32.* output
--- a/ld/testsuite/ld-x86-64/lp64-2.d
+++ b/ld/testsuite/ld-x86-64/lp64-2.d
@@ -1,4 +1,4 @@
#source: dummy.s
#as: --64
#ld: -m elf_x86_64 tmpdir/start64.o tmpdir/foo32.o
-#error: .*i386 architecture of input file `tmpdir/foo32.o' is
incompatible with i386:x86-64.* output
+#error: .*i386(:.+)? architecture of input file `tmpdir/foo32.o' is
incompatible with i386:x86-64.* output
--- a/ld/testsuite/ld-x86-64/lp64-3.d
+++ b/ld/testsuite/ld-x86-64/lp64-3.d
@@ -1,4 +1,4 @@
#source: dummy.s
#as: --64
#ld: -m elf_x86_64 tmpdir/start64.o tmpdir/foox32.o
-#error: .*i386:x64-32 architecture of input file `tmpdir/foox32.o' is
incompatible with i386:x86-64.* output
+#error: .*i386:x64-32(:.+)? architecture of input file
`tmpdir/foox32.o' is incompatible with i386:x86-64.* output
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -172,7 +172,7 @@ global ld
set test_name "Mixed x86_64 and i386 input test 1"
set test mixed1
if { ![ld_simple_link $ld tmpdir/$test "-m$emul tmpdir/${test}a.o
tmpdir/${test}b.o"] } {
- if [string match "*i386 architecture of input file
`tmpdir/${test}b.o' is incompatible with i386:x86-64* output*"
$link_output] {
+ if [string match "*i386* architecture of input file
`tmpdir/${test}b.o' is incompatible with i386:x86-64* output*"
$link_output] {
pass "$test_name"
} {
fail "$test_name"
@@ -182,7 +182,7 @@ if { ![ld_simple_link $ld tmpdir/$test "-m$emul
tmpdir/${test}a.o tmpdir/${test}
set test_name "Mixed x86_64 and i386 input test 2"
set test mixed2
if { ![ld_simple_link $ld tmpdir/$test "-m$emul tmpdir/${test}a.o
tmpdir/${test}b.o"] } {
- if [string match "*i386 architecture of input file
`tmpdir/${test}b.o' is incompatible with i386:x86-64* output*"
$link_output] {
+ if [string match "*i386* architecture of input file
`tmpdir/${test}b.o' is incompatible with i386:x86-64* output*"
$link_output] {
pass "$test_name"
} {
fail "$test_name"