This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
elf_map_symbols
- To: binutils at sourceware dot cygnus dot com
- Subject: elf_map_symbols
- From: Alan Modra <amodra at bigpond dot net dot au>
- Date: Wed, 10 Oct 2001 12:24:12 +0930
- Cc: Ian Lance Taylor <ian at zembu dot com>
This patch corrects the problem that made my use of sec->symbol instead
of elf_section_syms (abfd)[sec->index] in set_group_contents wrong.
Ian, you probably were the last person touching this code in any major
way. Do you know any reason why we can't use the existing section
symbols?
* elf.c (elf_map_symbols): Don't create new section symbols; Use
existing section syms. Update comments.
--
Alan Modra
Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.99
diff -u -p -r1.99 elf.c
--- elf.c 2001/10/09 13:12:19 1.99
+++ elf.c 2001/10/10 02:42:54
@@ -2387,7 +2387,6 @@ elf_map_symbols (abfd)
unsigned int num_locals2 = 0;
unsigned int num_globals2 = 0;
int max_index = 0;
- unsigned int num_sections = 0;
unsigned int idx;
asection *asect;
asymbol **new_syms;
@@ -2398,8 +2397,6 @@ elf_map_symbols (abfd)
fflush (stderr);
#endif
- /* Add a section symbol for each BFD section. FIXME: Is this really
- necessary? */
for (asect = abfd->sections; asect; asect = asect->next)
{
if (max_index < asect->index)
@@ -2414,6 +2411,8 @@ elf_map_symbols (abfd)
elf_section_syms (abfd) = sect_syms;
elf_num_section_syms (abfd) = max_index;
+ /* Init sect_syms entries for any section symbols we have already
+ decided to output. */
for (idx = 0; idx < symcount; idx++)
{
asymbol *sym = syms[idx];
@@ -2434,15 +2433,16 @@ elf_map_symbols (abfd)
sec = sec->output_section;
- /* Empty sections in the input files may have had a section
- symbol created for them. (See the comment near the end of
- _bfd_generic_link_output_symbols in linker.c). If the linker
- script discards such sections then we will reach this point.
- Since we know that we cannot avoid this case, we detect it
- and skip the abort and the assignment to the sect_syms array.
- To reproduce this particular case try running the linker
- testsuite test ld-scripts/weak.exp for an ELF port that uses
- the generic linker. */
+ /* Empty sections in the input files may have had a
+ section symbol created for them. (See the comment
+ near the end of _bfd_generic_link_output_symbols in
+ linker.c). If the linker script discards such
+ sections then we will reach this point. Since we know
+ that we cannot avoid this case, we detect it and skip
+ the abort and the assignment to the sect_syms array.
+ To reproduce this particular case try running the
+ linker testsuite test ld-scripts/weak.exp for an ELF
+ port that uses the generic linker. */
if (sec->owner == NULL)
continue;
@@ -2453,31 +2453,6 @@ elf_map_symbols (abfd)
}
}
- for (asect = abfd->sections; asect; asect = asect->next)
- {
- asymbol *sym;
-
- if (sect_syms[asect->index] != NULL)
- continue;
-
- sym = bfd_make_empty_symbol (abfd);
- if (sym == NULL)
- return false;
- sym->the_bfd = abfd;
- sym->name = asect->name;
- sym->value = 0;
- /* Set the flags to 0 to indicate that this one was newly added. */
- sym->flags = 0;
- sym->section = asect;
- sect_syms[asect->index] = sym;
- num_sections++;
-#ifdef DEBUG
- fprintf (stderr,
- _("creating section symbol, name = %s, value = 0x%.8lx, index = %d, section = 0x%.8lx\n"),
- asect->name, (long) asect->vma, asect->index, (long) asect);
-#endif
- }
-
/* Classify all of the symbols. */
for (idx = 0; idx < symcount; idx++)
{
@@ -2486,17 +2461,19 @@ elf_map_symbols (abfd)
else
num_globals++;
}
+
+ /* We will be adding a section symbol for each BFD section. Most normal
+ sections will already have a section symbol in outsymbols, but
+ eg. SHT_GROUP sections will not, and we need the section symbol mapped
+ at least in that case. */
for (asect = abfd->sections; asect; asect = asect->next)
{
- if (sect_syms[asect->index] != NULL
- && sect_syms[asect->index]->flags == 0)
+ if (sect_syms[asect->index] == NULL)
{
- sect_syms[asect->index]->flags = BSF_SECTION_SYM;
- if (!sym_is_global (abfd, sect_syms[asect->index]))
+ if (!sym_is_global (abfd, asect->symbol))
num_locals++;
else
num_globals++;
- sect_syms[asect->index]->flags = 0;
}
}
@@ -2521,13 +2498,12 @@ elf_map_symbols (abfd)
}
for (asect = abfd->sections; asect; asect = asect->next)
{
- if (sect_syms[asect->index] != NULL
- && sect_syms[asect->index]->flags == 0)
+ if (sect_syms[asect->index] == NULL)
{
- asymbol *sym = sect_syms[asect->index];
+ asymbol *sym = asect->symbol;
unsigned int i;
- sym->flags = BSF_SECTION_SYM;
+ sect_syms[asect->index] = sym;
if (!sym_is_global (abfd, sym))
i = num_locals2++;
else