mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-26 05:47:26 +08:00
* More fixes for object formats which allow multiple sections
with the same name: * objcopy.c (setup_section): Make a new output section even if one already exists with the given name. (copy_section): Use isection->output_section rather than trying to look the output section up by its (possibly non-unique) name.
This commit is contained in:
@ -1,3 +1,15 @@
|
|||||||
|
Sun Mar 27 16:23:39 1994 Jeffrey A. Law (law@snake.cs.utah.edu)
|
||||||
|
|
||||||
|
* More fixes for object formats which allow multiple sections
|
||||||
|
with the same name:
|
||||||
|
* objcopy.c (setup_section): Make a new output section even if
|
||||||
|
one already exists with the given name.
|
||||||
|
(copy_section): Use isection->output_section rather than trying
|
||||||
|
to look the output section up by its (possibly non-unique) name.
|
||||||
|
|
||||||
|
* Makefile.in (install-info): Look for binutils.info in the
|
||||||
|
current directory, then in $(srcdir). Don't use $<.
|
||||||
|
|
||||||
Mon Mar 21 12:55:45 1994 Ian Lance Taylor (ian@tweedledumb.cygnus.com)
|
Mon Mar 21 12:55:45 1994 Ian Lance Taylor (ian@tweedledumb.cygnus.com)
|
||||||
|
|
||||||
* objdump.c (objdump_print_address): Make static. Declare with
|
* objdump.c (objdump_print_address): Make static. Declare with
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
static void setup_section ();
|
static void setup_section ();
|
||||||
static void copy_section ();
|
static void copy_section ();
|
||||||
|
static void mark_symbols_used_in_relocations ();
|
||||||
|
|
||||||
#define nonfatal(s) {bfd_nonfatal(s); status = 1; return;}
|
#define nonfatal(s) {bfd_nonfatal(s); status = 1; return;}
|
||||||
|
|
||||||
@ -180,7 +181,6 @@ filter_symbols (abfd, osyms, isyms, symcount)
|
|||||||
unsigned long symcount;
|
unsigned long symcount;
|
||||||
{
|
{
|
||||||
register asymbol **from = isyms, **to = osyms;
|
register asymbol **from = isyms, **to = osyms;
|
||||||
char locals_prefix = bfd_get_symbol_leading_char (abfd) == '_' ? 'L' : '.';
|
|
||||||
unsigned int src_count = 0, dst_count = 0;
|
unsigned int src_count = 0, dst_count = 0;
|
||||||
|
|
||||||
for (; src_count < symcount; src_count++)
|
for (; src_count < symcount; src_count++)
|
||||||
@ -190,6 +190,7 @@ filter_symbols (abfd, osyms, isyms, symcount)
|
|||||||
int keep;
|
int keep;
|
||||||
|
|
||||||
if ((flags & BSF_GLOBAL) /* Keep if external. */
|
if ((flags & BSF_GLOBAL) /* Keep if external. */
|
||||||
|
|| (flags & BSF_KEEP) /* Keep if used in a relocation. */
|
||||||
|| bfd_get_section (sym) == &bfd_und_section
|
|| bfd_get_section (sym) == &bfd_und_section
|
||||||
|| bfd_is_com_section (bfd_get_section (sym)))
|
|| bfd_is_com_section (bfd_get_section (sym)))
|
||||||
keep = 1;
|
keep = 1;
|
||||||
@ -198,7 +199,7 @@ filter_symbols (abfd, osyms, isyms, symcount)
|
|||||||
else /* Local symbol. */
|
else /* Local symbol. */
|
||||||
keep = discard_locals != locals_all
|
keep = discard_locals != locals_all
|
||||||
&& (discard_locals != locals_start_L ||
|
&& (discard_locals != locals_start_L ||
|
||||||
bfd_asymbol_name (sym)[0] != locals_prefix);
|
! bfd_is_local_label (abfd, sym));
|
||||||
if (keep)
|
if (keep)
|
||||||
to[dst_count++] = sym;
|
to[dst_count++] = sym;
|
||||||
}
|
}
|
||||||
@ -266,6 +267,22 @@ copy_object (ibfd, obfd)
|
|||||||
if (osympp != isympp)
|
if (osympp != isympp)
|
||||||
free (osympp);
|
free (osympp);
|
||||||
|
|
||||||
|
/* Allow the BFD backend to copy any private data it understands
|
||||||
|
from the input BFD to the output BFD. */
|
||||||
|
if (!bfd_copy_private_bfd_data (ibfd, obfd))
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s: %s: error copying private BFD data: %s\n",
|
||||||
|
program_name, bfd_errmsg (bfd_get_error ()));
|
||||||
|
status = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* bfd mandates that all output sections be created and sizes set before
|
||||||
|
any output is done. Thus, we traverse all sections multiple times. */
|
||||||
|
bfd_map_over_sections (ibfd, setup_section, (void *) obfd);
|
||||||
|
|
||||||
|
/* Symbol filtering must happen after the output sections have
|
||||||
|
been created, but before their contents are set. */
|
||||||
if (strip_symbols == strip_all && discard_locals == locals_undef)
|
if (strip_symbols == strip_all && discard_locals == locals_undef)
|
||||||
{
|
{
|
||||||
osympp = isympp = NULL;
|
osympp = isympp = NULL;
|
||||||
@ -278,6 +295,17 @@ copy_object (ibfd, obfd)
|
|||||||
|
|
||||||
if (strip_symbols == strip_debug || discard_locals != locals_undef)
|
if (strip_symbols == strip_debug || discard_locals != locals_undef)
|
||||||
{
|
{
|
||||||
|
/* Mark symbols used in output relocations so that they
|
||||||
|
are kept, even if they are local labels or static symbols.
|
||||||
|
|
||||||
|
Note we iterate over the input sections examining their
|
||||||
|
relocations since the relocations for the output sections
|
||||||
|
haven't been set yet. mark_symbols_used_in_relocations will
|
||||||
|
ignore input sections which have no corresponding output
|
||||||
|
section. */
|
||||||
|
bfd_map_over_sections (ibfd,
|
||||||
|
mark_symbols_used_in_relocations,
|
||||||
|
(void *)isympp);
|
||||||
osympp = (asymbol **) xmalloc (symcount * sizeof (asymbol *));
|
osympp = (asymbol **) xmalloc (symcount * sizeof (asymbol *));
|
||||||
symcount = filter_symbols (ibfd, osympp, isympp, symcount);
|
symcount = filter_symbols (ibfd, osympp, isympp, symcount);
|
||||||
}
|
}
|
||||||
@ -285,9 +313,7 @@ copy_object (ibfd, obfd)
|
|||||||
|
|
||||||
bfd_set_symtab (obfd, osympp, symcount);
|
bfd_set_symtab (obfd, osympp, symcount);
|
||||||
|
|
||||||
/* bfd mandates that all output sections be created and sizes set before
|
/* This has to happen after the symbol table has been set. */
|
||||||
any output is done. Thus, we traverse all sections multiple times. */
|
|
||||||
bfd_map_over_sections (ibfd, setup_section, (void *) obfd);
|
|
||||||
bfd_map_over_sections (ibfd, copy_section, (void *) obfd);
|
bfd_map_over_sections (ibfd, copy_section, (void *) obfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -458,16 +484,12 @@ setup_section (ibfd, isection, obfd)
|
|||||||
|| discard_locals == locals_all))
|
|| discard_locals == locals_all))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
osection = bfd_get_section_by_name (obfd, bfd_section_name (ibfd, isection));
|
osection = bfd_make_section_anyway (obfd, bfd_section_name (ibfd, isection));
|
||||||
if (osection == NULL)
|
|
||||||
{
|
|
||||||
osection = bfd_make_section (obfd, bfd_section_name (ibfd, isection));
|
|
||||||
if (osection == NULL)
|
if (osection == NULL)
|
||||||
{
|
{
|
||||||
err = "making";
|
err = "making";
|
||||||
goto loser;
|
goto loser;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!bfd_set_section_size (obfd,
|
if (!bfd_set_section_size (obfd,
|
||||||
osection,
|
osection,
|
||||||
@ -508,6 +530,14 @@ setup_section (ibfd, isection, obfd)
|
|||||||
isection->output_section = osection;
|
isection->output_section = osection;
|
||||||
isection->output_offset = 0;
|
isection->output_offset = 0;
|
||||||
|
|
||||||
|
/* Allow the BFD backend to copy any private data it understands
|
||||||
|
from the input section to the output section. */
|
||||||
|
if (!bfd_copy_private_section_data (ibfd, isection, obfd, osection))
|
||||||
|
{
|
||||||
|
err = "private data";
|
||||||
|
goto loser;
|
||||||
|
}
|
||||||
|
|
||||||
/* All went well */
|
/* All went well */
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -542,12 +572,10 @@ copy_section (ibfd, isection, obfd)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
osection = bfd_get_section_by_name (obfd,
|
osection = isection->output_section;
|
||||||
bfd_section_name (ibfd, isection));
|
|
||||||
|
|
||||||
size = bfd_get_section_size_before_reloc (isection);
|
size = bfd_get_section_size_before_reloc (isection);
|
||||||
|
|
||||||
if (size == 0)
|
if (size == 0 || osection == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (strip_symbols == strip_all
|
if (strip_symbols == strip_all
|
||||||
@ -587,6 +615,41 @@ copy_section (ibfd, isection, obfd)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Mark all the symbols which will be used in output relocations with
|
||||||
|
the BSF_KEEP flag so that those symbols will not be stripped.
|
||||||
|
|
||||||
|
Ignore relocations which will not appear in the output file. */
|
||||||
|
|
||||||
|
static void
|
||||||
|
mark_symbols_used_in_relocations (ibfd, isection, symbols)
|
||||||
|
bfd *ibfd;
|
||||||
|
sec_ptr isection;
|
||||||
|
asymbol **symbols;
|
||||||
|
{
|
||||||
|
arelent **relpp;
|
||||||
|
unsigned int relcount, i;
|
||||||
|
|
||||||
|
/* Ignore an input section with no corresponding output section. */
|
||||||
|
if (isection->output_section == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
relpp = (arelent **) xmalloc (bfd_get_reloc_upper_bound (ibfd, isection));
|
||||||
|
relcount = bfd_canonicalize_reloc (ibfd, isection, relpp, symbols);
|
||||||
|
|
||||||
|
/* Examine each symbol used in a relocation. If it's not one of the
|
||||||
|
special bfd section symbols, then mark it with BSF_KEEP. */
|
||||||
|
for (i = 0; i < relcount; i++)
|
||||||
|
{
|
||||||
|
if (*relpp[i]->sym_ptr_ptr != bfd_com_section.symbol
|
||||||
|
&& *relpp[i]->sym_ptr_ptr != bfd_abs_section.symbol
|
||||||
|
&& *relpp[i]->sym_ptr_ptr != bfd_und_section.symbol)
|
||||||
|
(*relpp[i]->sym_ptr_ptr)->flags |= BSF_KEEP;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (relpp != NULL)
|
||||||
|
free (relpp);
|
||||||
|
}
|
||||||
|
|
||||||
/* The number of bytes to copy at once. */
|
/* The number of bytes to copy at once. */
|
||||||
#define COPY_BUF 8192
|
#define COPY_BUF 8192
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user