aboutsummaryrefslogtreecommitdiff
path: root/bfd/elf.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2001-11-07 16:50:38 +0000
committerJakub Jelinek <jakub@redhat.com>2001-11-07 16:50:38 +0000
commit2b0f7ef92ee30445837f86ca0149ec6c6c01dc93 (patch)
treece6ae15166b1586424ca4f6032a9ab72d98e61c7 /bfd/elf.c
parentef5cdfc7ddd53e80fed2c3b6e6ee9c57f7b29c35 (diff)
downloadgdb-2b0f7ef92ee30445837f86ca0149ec6c6c01dc93.zip
gdb-2b0f7ef92ee30445837f86ca0149ec6c6c01dc93.tar.gz
gdb-2b0f7ef92ee30445837f86ca0149ec6c6c01dc93.tar.bz2
* Makefile.am (BFD32_BACKENDS): Add elf-strtab.lo.
(BFD32_BACKENDS_CFILES): Add elf-strtab.c. (elf-strtab.lo): Add rule. * Makefile.in: Rebuilt. * configure.in (elf): Add elf-strtab.lo. * configure: Rebuilt. * elf-bfd.h (elf_strtab_hash): Forward declare. (struct elf_link_hash_table): Change dynstr type to struct elf_strtab_hash *. (struct elf_obj_tdata): Change strtab_ptr type to struct elf_strtab_hash *. (_bfd_elf_strtab_init, _bfd_elf_strtab_free, _bfd_elf_strtab_add, _bfd_elf_strtab_addref, _bfd_elf_strtab_delref, _bfd_elf_strtab_clear_all_refs, _bfd_elf_strtab_size, _bfd_elf_strtab_offset, _bfd_elf_strtab_emit, _bfd_elf_strtab_finalize): New prototypes. * elf-strtab.c: New file. * elflink.h (elf_link_add_object_symbols): Use _bfd_elf_strtab_add and _bfd_elf_strtab_size instead of _bfd_stringtab calls. Call _bfd_elf_strtab_delref if DT_NEEDED entry is not needed or when forcing dynamic symbol to local. (elf_link_create_dynamic_sections): Call _bfd_elf_strtab_init instead of elf_stringtab_init. (elf_link_record_local_dynamic_symbol): Likewise, change dynstr type. Use _bfd_elf_strtab functions instead of _bfd_stringtab calls. (size_dynamic_sections): Use _bfd_elf_strtab functions instead of _bfd_stringtab calls. For DT_RUNPATH and Verdaux vda_name fields, call _bfd_elf_strtab_addref. Call elf_finalize_dynstr. (elf_adjust_dynstr_offsets, elf_finalize_dynstr): New functions. (elf_fix_symbol_flags): Call _bfd_elf_strtab_delref when forcing dynamic symbol to local. (elf_link_assign_sym_version): Likewise. (elf_bfd_final_link): Call _bfd_elf_strtab_emit instead of _bfd_stringtab_emit. * elflink.c (_bfd_elf_link_record_dynamic_symbol): Change dynstr type. Call _bfd_elf_strtab functions instead of _bfd_stringtab functions. * elf64-sparc.c (sparc64_elf_size_dynamic_sections): Likewise. * elf.c (_bfd_elf_init_reloc_shdr): Likewise. (elf_fake_sections): Likewise. (assign_section_numbers): Call _bfd_elf_strtab_clear_all_refs on shstrtab hash table, call _bfd_elf_strtab_addref on each section name in the output. Call _bfd_elf_strtab_finalize and use _bfd_elf_strtab_offset to finalize sh_name section header fields. (_bfd_elf_compute_section_file_positions): Use _bfd_elf_strtab_size instead of _bfd_stringtab_size. (prep_headers): Change shstrtab type. Use _bfd_elf_strtab calls instead of _bfd_stringtab calls.
Diffstat (limited to 'bfd/elf.c')
-rw-r--r--bfd/elf.c50
1 files changed, 33 insertions, 17 deletions
diff --git a/bfd/elf.c b/bfd/elf.c
index c03bd4a..8c1694e 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -1939,8 +1939,8 @@ _bfd_elf_init_reloc_shdr (abfd, rel_hdr, asect, use_rela_p)
return false;
sprintf (name, "%s%s", use_rela_p ? ".rela" : ".rel", asect->name);
rel_hdr->sh_name =
- (unsigned int) _bfd_stringtab_add (elf_shstrtab (abfd), name,
- true, false);
+ (unsigned int) _bfd_elf_strtab_add (elf_shstrtab (abfd), name,
+ false);
if (rel_hdr->sh_name == (unsigned int) -1)
return false;
rel_hdr->sh_type = use_rela_p ? SHT_RELA : SHT_REL;
@@ -1977,9 +1977,8 @@ elf_fake_sections (abfd, asect, failedptrarg)
this_hdr = &elf_section_data (asect)->this_hdr;
- this_hdr->sh_name = (unsigned long) _bfd_stringtab_add (elf_shstrtab (abfd),
- asect->name,
- true, false);
+ this_hdr->sh_name = (unsigned long) _bfd_elf_strtab_add (elf_shstrtab (abfd),
+ asect->name, false);
if (this_hdr->sh_name == (unsigned long) -1)
{
*failedptr = true;
@@ -2200,38 +2199,51 @@ assign_section_numbers (abfd)
{
struct elf_obj_tdata *t = elf_tdata (abfd);
asection *sec;
- unsigned int section_number;
+ unsigned int section_number, secn;
Elf_Internal_Shdr **i_shdrp;
bfd_size_type amt;
section_number = 1;
+ _bfd_elf_strtab_clear_all_refs (elf_shstrtab (abfd));
+
for (sec = abfd->sections; sec; sec = sec->next)
{
struct bfd_elf_section_data *d = elf_section_data (sec);
d->this_idx = section_number++;
+ _bfd_elf_strtab_addref (elf_shstrtab (abfd), d->this_hdr.sh_name);
if ((sec->flags & SEC_RELOC) == 0)
d->rel_idx = 0;
else
- d->rel_idx = section_number++;
+ {
+ d->rel_idx = section_number++;
+ _bfd_elf_strtab_addref (elf_shstrtab (abfd), d->rel_hdr.sh_name);
+ }
if (d->rel_hdr2)
- d->rel_idx2 = section_number++;
+ {
+ d->rel_idx2 = section_number++;
+ _bfd_elf_strtab_addref (elf_shstrtab (abfd), d->rel_hdr2->sh_name);
+ }
else
d->rel_idx2 = 0;
}
t->shstrtab_section = section_number++;
+ _bfd_elf_strtab_addref (elf_shstrtab (abfd), t->shstrtab_hdr.sh_name);
elf_elfheader (abfd)->e_shstrndx = t->shstrtab_section;
- t->shstrtab_hdr.sh_size = _bfd_stringtab_size (elf_shstrtab (abfd));
if (bfd_get_symcount (abfd) > 0)
{
t->symtab_section = section_number++;
+ _bfd_elf_strtab_addref (elf_shstrtab (abfd), t->symtab_hdr.sh_name);
t->strtab_section = section_number++;
+ _bfd_elf_strtab_addref (elf_shstrtab (abfd), t->strtab_hdr.sh_name);
}
+ _bfd_elf_strtab_finalize (elf_shstrtab (abfd));
+ t->shstrtab_hdr.sh_size = _bfd_elf_strtab_size (elf_shstrtab (abfd));
elf_elfheader (abfd)->e_shnum = section_number;
/* Set up the list of section header pointers, in agreement with the
@@ -2368,6 +2380,10 @@ assign_section_numbers (abfd)
}
}
+ for (secn = 1; secn < section_number; ++secn)
+ i_shdrp[secn]->sh_name = _bfd_elf_strtab_offset (elf_shstrtab (abfd),
+ i_shdrp[secn]->sh_name);
+
return true;
}
@@ -2629,7 +2645,7 @@ _bfd_elf_compute_section_file_positions (abfd, link_info)
shstrtab_hdr->sh_type = SHT_STRTAB;
shstrtab_hdr->sh_flags = 0;
shstrtab_hdr->sh_addr = 0;
- shstrtab_hdr->sh_size = _bfd_stringtab_size (elf_shstrtab (abfd));
+ shstrtab_hdr->sh_size = _bfd_elf_strtab_size (elf_shstrtab (abfd));
shstrtab_hdr->sh_entsize = 0;
shstrtab_hdr->sh_link = 0;
shstrtab_hdr->sh_info = 0;
@@ -3620,13 +3636,13 @@ prep_headers (abfd)
Elf_Internal_Phdr *i_phdrp = 0; /* Program header table, internal form */
Elf_Internal_Shdr **i_shdrp; /* Section header table, internal form */
int count;
- struct bfd_strtab_hash *shstrtab;
+ struct elf_strtab_hash *shstrtab;
struct elf_backend_data *bed = get_elf_backend_data (abfd);
i_ehdrp = elf_elfheader (abfd);
i_shdrp = elf_elfsections (abfd);
- shstrtab = _bfd_elf_stringtab_init ();
+ shstrtab = _bfd_elf_strtab_init ();
if (shstrtab == NULL)
return false;
@@ -3712,11 +3728,11 @@ prep_headers (abfd)
}
elf_tdata (abfd)->symtab_hdr.sh_name =
- (unsigned int) _bfd_stringtab_add (shstrtab, ".symtab", true, false);
+ (unsigned int) _bfd_elf_strtab_add (shstrtab, ".symtab", false);
elf_tdata (abfd)->strtab_hdr.sh_name =
- (unsigned int) _bfd_stringtab_add (shstrtab, ".strtab", true, false);
+ (unsigned int) _bfd_elf_strtab_add (shstrtab, ".strtab", false);
elf_tdata (abfd)->shstrtab_hdr.sh_name =
- (unsigned int) _bfd_stringtab_add (shstrtab, ".shstrtab", true, false);
+ (unsigned int) _bfd_elf_strtab_add (shstrtab, ".shstrtab", false);
if (elf_tdata (abfd)->symtab_hdr.sh_name == (unsigned int) -1
|| elf_tdata (abfd)->symtab_hdr.sh_name == (unsigned int) -1
|| elf_tdata (abfd)->shstrtab_hdr.sh_name == (unsigned int) -1)
@@ -3795,7 +3811,7 @@ _bfd_elf_write_object_contents (abfd)
/* Write out the section header names. */
if (bfd_seek (abfd, elf_tdata (abfd)->shstrtab_hdr.sh_offset, SEEK_SET) != 0
- || ! _bfd_stringtab_emit (abfd, elf_shstrtab (abfd)))
+ || ! _bfd_elf_strtab_emit (abfd, elf_shstrtab (abfd)))
return false;
if (bed->elf_backend_final_write_processing)
@@ -5549,7 +5565,7 @@ _bfd_elf_close_and_cleanup (abfd)
if (bfd_get_format (abfd) == bfd_object)
{
if (elf_shstrtab (abfd) != NULL)
- _bfd_stringtab_free (elf_shstrtab (abfd));
+ _bfd_elf_strtab_free (elf_shstrtab (abfd));
}
return _bfd_generic_close_and_cleanup (abfd);