* elf.c (elf_map_symbols): Don't create new section symbols; Use

existing section syms.  Update comments.
	(copy_private_bfd_data): Formatting fixes.
	(elfcore_grok_win32pstatus): Likewise.
	(swap_out_syms): Likewise.  Remove unnecessary level of braces.
This commit is contained in:
Alan Modra
2001-10-10 11:19:54 +00:00
parent f3a55c17eb
commit 079e9a2ffe
2 changed files with 244 additions and 254 deletions

View File

@ -1,3 +1,11 @@
2001-10-10 Alan Modra <amodra@bigpond.net.au>
* elf.c (elf_map_symbols): Don't create new section symbols; Use
existing section syms. Update comments.
(copy_private_bfd_data): Formatting fixes.
(elfcore_grok_win32pstatus): Likewise.
(swap_out_syms): Likewise. Remove unnecessary level of braces.
2001-10-09 Alan Modra <amodra@bigpond.net.au> 2001-10-09 Alan Modra <amodra@bigpond.net.au>
* elf-bfd.h (struct bfd_elf_section_data): Rename "group" to * elf-bfd.h (struct bfd_elf_section_data): Rename "group" to

106
bfd/elf.c
View File

@ -2387,7 +2387,6 @@ elf_map_symbols (abfd)
unsigned int num_locals2 = 0; unsigned int num_locals2 = 0;
unsigned int num_globals2 = 0; unsigned int num_globals2 = 0;
int max_index = 0; int max_index = 0;
unsigned int num_sections = 0;
unsigned int idx; unsigned int idx;
asection *asect; asection *asect;
asymbol **new_syms; asymbol **new_syms;
@ -2398,8 +2397,6 @@ elf_map_symbols (abfd)
fflush (stderr); fflush (stderr);
#endif #endif
/* Add a section symbol for each BFD section. FIXME: Is this really
necessary? */
for (asect = abfd->sections; asect; asect = asect->next) for (asect = abfd->sections; asect; asect = asect->next)
{ {
if (max_index < asect->index) if (max_index < asect->index)
@ -2414,6 +2411,8 @@ elf_map_symbols (abfd)
elf_section_syms (abfd) = sect_syms; elf_section_syms (abfd) = sect_syms;
elf_num_section_syms (abfd) = max_index; 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++) for (idx = 0; idx < symcount; idx++)
{ {
asymbol *sym = syms[idx]; asymbol *sym = syms[idx];
@ -2434,15 +2433,16 @@ elf_map_symbols (abfd)
sec = sec->output_section; sec = sec->output_section;
/* Empty sections in the input files may have had a section /* Empty sections in the input files may have had a
symbol created for them. (See the comment near the end of section symbol created for them. (See the comment
_bfd_generic_link_output_symbols in linker.c). If the linker near the end of _bfd_generic_link_output_symbols in
script discards such sections then we will reach this point. linker.c). If the linker script discards such
Since we know that we cannot avoid this case, we detect it sections then we will reach this point. Since we know
and skip the abort and the assignment to the sect_syms array. that we cannot avoid this case, we detect it and skip
To reproduce this particular case try running the linker the abort and the assignment to the sect_syms array.
testsuite test ld-scripts/weak.exp for an ELF port that uses To reproduce this particular case try running the
the generic linker. */ linker testsuite test ld-scripts/weak.exp for an ELF
port that uses the generic linker. */
if (sec->owner == NULL) if (sec->owner == NULL)
continue; 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. */ /* Classify all of the symbols. */
for (idx = 0; idx < symcount; idx++) for (idx = 0; idx < symcount; idx++)
{ {
@ -2486,17 +2461,19 @@ elf_map_symbols (abfd)
else else
num_globals++; 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) for (asect = abfd->sections; asect; asect = asect->next)
{ {
if (sect_syms[asect->index] != NULL if (sect_syms[asect->index] == NULL)
&& sect_syms[asect->index]->flags == 0)
{ {
sect_syms[asect->index]->flags = BSF_SECTION_SYM; if (!sym_is_global (abfd, asect->symbol))
if (!sym_is_global (abfd, sect_syms[asect->index]))
num_locals++; num_locals++;
else else
num_globals++; num_globals++;
sect_syms[asect->index]->flags = 0;
} }
} }
@ -2521,13 +2498,12 @@ elf_map_symbols (abfd)
} }
for (asect = abfd->sections; asect; asect = asect->next) for (asect = abfd->sections; asect; asect = asect->next)
{ {
if (sect_syms[asect->index] != NULL if (sect_syms[asect->index] == NULL)
&& sect_syms[asect->index]->flags == 0)
{ {
asymbol *sym = sect_syms[asect->index]; asymbol *sym = asect->symbol;
unsigned int i; unsigned int i;
sym->flags = BSF_SECTION_SYM; sect_syms[asect->index] = sym;
if (!sym_is_global (abfd, sym)) if (!sym_is_global (abfd, sym))
i = num_locals2++; i = num_locals2++;
else else
@ -4233,7 +4209,8 @@ copy_private_bfd_data (ibfd, obfd)
? iehdr->e_ehsize ? iehdr->e_ehsize
: 0) : 0)
+ (map->includes_phdrs + (map->includes_phdrs
? iehdr->e_phnum * iehdr->e_phentsize ? (iehdr->e_phnum
* iehdr->e_phentsize)
: 0)))) : 0))))
map->p_paddr = segment->p_vaddr; map->p_paddr = segment->p_vaddr;
@ -4358,9 +4335,11 @@ copy_private_bfd_data (ibfd, obfd)
/* If the gap between the end of the previous section /* If the gap between the end of the previous section
and the start of this section is more than and the start of this section is more than
maxpagesize then we need to start a new segment. */ maxpagesize then we need to start a new segment. */
if ((BFD_ALIGN (prev_sec->lma + prev_sec->_raw_size, maxpagesize) if ((BFD_ALIGN (prev_sec->lma + prev_sec->_raw_size,
maxpagesize)
< BFD_ALIGN (output_section->lma, maxpagesize)) < BFD_ALIGN (output_section->lma, maxpagesize))
|| ((prev_sec->lma + prev_sec->_raw_size) > output_section->lma)) || ((prev_sec->lma + prev_sec->_raw_size)
> output_section->lma))
{ {
if (suggested_lma == 0) if (suggested_lma == 0)
suggested_lma = output_section->lma; suggested_lma = output_section->lma;
@ -4592,15 +4571,9 @@ swap_out_syms (abfd, sttp, relocatable_p)
struct bfd_strtab_hash **sttp; struct bfd_strtab_hash **sttp;
int relocatable_p; int relocatable_p;
{ {
struct elf_backend_data *bed = get_elf_backend_data (abfd); struct elf_backend_data *bed;
int symcount;
if (!elf_map_symbols (abfd)) asymbol **syms;
return false;
/* Dump out the symtabs. */
{
int symcount = bfd_get_symcount (abfd);
asymbol **syms = bfd_get_outsymbols (abfd);
struct bfd_strtab_hash *stt; struct bfd_strtab_hash *stt;
Elf_Internal_Shdr *symtab_hdr; Elf_Internal_Shdr *symtab_hdr;
Elf_Internal_Shdr *symstrtab_hdr; Elf_Internal_Shdr *symstrtab_hdr;
@ -4608,10 +4581,16 @@ swap_out_syms (abfd, sttp, relocatable_p)
int idx; int idx;
bfd_size_type amt; bfd_size_type amt;
if (!elf_map_symbols (abfd))
return false;
/* Dump out the symtabs. */
stt = _bfd_elf_stringtab_init (); stt = _bfd_elf_stringtab_init ();
if (stt == NULL) if (stt == NULL)
return false; return false;
bed = get_elf_backend_data (abfd);
symcount = bfd_get_symcount (abfd);
symtab_hdr = &elf_tdata (abfd)->symtab_hdr; symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
symtab_hdr->sh_type = SHT_SYMTAB; symtab_hdr->sh_type = SHT_SYMTAB;
symtab_hdr->sh_entsize = bed->s->sizeof_sym; symtab_hdr->sh_entsize = bed->s->sizeof_sym;
@ -4641,6 +4620,8 @@ swap_out_syms (abfd, sttp, relocatable_p)
bed->s->swap_symbol_out (abfd, &sym, (PTR) outbound_syms); bed->s->swap_symbol_out (abfd, &sym, (PTR) outbound_syms);
outbound_syms += bed->s->sizeof_sym; outbound_syms += bed->s->sizeof_sym;
} }
syms = bfd_get_outsymbols (abfd);
for (idx = 0; idx < symcount; idx++) for (idx = 0; idx < symcount; idx++)
{ {
Elf_Internal_Sym sym; Elf_Internal_Sym sym;
@ -4757,7 +4738,8 @@ swap_out_syms (abfd, sttp, relocatable_p)
/* Processor-specific types */ /* Processor-specific types */
if (type_ptr != NULL if (type_ptr != NULL
&& bed->elf_backend_get_symbol_type) && bed->elf_backend_get_symbol_type)
type = (*bed->elf_backend_get_symbol_type) (&type_ptr->internal_elf_sym, type); type = ((*bed->elf_backend_get_symbol_type)
(&type_ptr->internal_elf_sym, type));
if (flags & BSF_SECTION_SYM) if (flags & BSF_SECTION_SYM)
{ {
@ -4808,7 +4790,6 @@ swap_out_syms (abfd, sttp, relocatable_p)
symstrtab_hdr->sh_link = 0; symstrtab_hdr->sh_link = 0;
symstrtab_hdr->sh_info = 0; symstrtab_hdr->sh_info = 0;
symstrtab_hdr->sh_addralign = 1; symstrtab_hdr->sh_addralign = 1;
}
return true; return true;
} }
@ -6032,8 +6013,9 @@ elfcore_grok_win32pstatus (abfd, note)
return false; return false;
sect->_raw_size = sizeof (pstatus.data.thread_info.thread_context); sect->_raw_size = sizeof (pstatus.data.thread_info.thread_context);
sect->filepos = note->descpos + offsetof (struct win32_pstatus, sect->filepos = (note->descpos
data.thread_info.thread_context); + offsetof (struct win32_pstatus,
data.thread_info.thread_context));
sect->flags = SEC_HAS_CONTENTS; sect->flags = SEC_HAS_CONTENTS;
sect->alignment_power = 2; sect->alignment_power = 2;