aboutsummaryrefslogtreecommitdiff
path: root/bfd/elf64-hppa.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2002-07-07 09:10:41 +0000
committerAlan Modra <amodra@gmail.com>2002-07-07 09:10:41 +0000
commit6cdc0ccc1276096134b1870e92875487ffdc8292 (patch)
treed9ce6f2bb8abc152c4b8d99c9761b8c46658e619 /bfd/elf64-hppa.c
parentd8462f1281a70eddafd4f2f50f142491299b69c2 (diff)
downloadgdb-6cdc0ccc1276096134b1870e92875487ffdc8292.zip
gdb-6cdc0ccc1276096134b1870e92875487ffdc8292.tar.gz
gdb-6cdc0ccc1276096134b1870e92875487ffdc8292.tar.bz2
* elf-bfd.h (struct elf_reloc_cookie): Remove locsym_shndx,
change type of locsyms. (bfd_elf_get_elf_syms): Declare. * elf.c (bfd_elf_get_elf_syms): New function. (group_signature): Use bfd_elf_get_elf_syms. (bfd_section_from_r_symndx): Likewise. * elfcode.h (elf_slurp_symbol_table): Likewise. * elflink.h (elf_link_is_defined_archive_symbol): Likewise. (elf_link_add_object_symbols): Likewise. Reorganise to increase locality of various data structures. Properly free internal relocs. (elf_bfd_final_link): Properly free internal relocs. (elf_link_check_versioned_symbol): Use bfd_elf_get_elf_syms. (elf_link_input_bfd): Likewise. (elf_gc_mark): Likewise. Properly free internal relocs. (elf_gc_sweep): Properly free internal relocs. (elf_reloc_symbol_deleted_p): No need to swap syms in. (elf_bfd_discard_info): Use bfd_elf_get_elf_syms. Properly free internal relocs. * elf-m10200.c (mn10200_elf_relax_section): Use bfd_elf_get_elf_syms. Properly free possibly cached info. (mn10200_elf_relax_delete_bytes): Remove symbol swapping code. (mn10200_elf_symbol_address_p): Pass in internal syms. Remove symbol swapping code. (mn10200_elf_get_relocated_section_contents): Use bfd_elf_get_elf_syms. Properly free possibly cached info. * elf-m10300.c (mn10300_elf_relax_section): As above for elf-m10200.c. (mn10300_elf_relax_delete_bytes): Likewise. (mn10300_elf_symbol_address_p): Likewise. (mn10300_elf_get_relocated_section_contents): Likewise. * elf32-h8300.c (elf32_h8_relax_section): As above for elf-m10200.c. (elf32_h8_relax_delete_bytes): Likewise. (elf32_h8_symbol_address_p): Likewise. (elf32_h8_get_relocated_section_contents): Likewise. * elf32-m32r.c (m32r_elf_relax_section): As above for elf-m10200.c. (m32r_elf_relax_delete_bytes): Likewise. (m32r_elf_get_relocated_section_contents): Likewise. * elf32-sh.c (sh_elf_reloc_loop): Free section contents using elf_section_data to determine whether cached. (sh_elf_relax_section): As above for elf-m10200.c. (sh_elf_relax_delete_bytes): Likewise. (sh_elf_get_relocated_section_contents): Likewise. * elf32-xstormy16.c (xstormy16_elf_relax_section): As above. * elf64-alpha.c (elf64_alpha_relax_section): As above. Also delay reading of local syms. * elf64-mmix.c (mmix_elf_relax_section): Likewise. * elf64-sh64.c (sh_elf64_get_relocated_section_contents): As above. * elfxx-ia64.c (elfNN_ia64_relax_section): As above. * elfxx-mips.c (_bfd_mips_elf_check_relocs): Properly free internal relocs. * elf32-arm.h (bfd_elf32_arm_process_before_allocation): Properly free internal relocs and section contents. Don't read symbols. * elf32-hppa.c (get_local_syms): Use bfd_elf_get_elf_syms. (elf32_hppa_size_stubs): Don't free local syms. * elf32-m68k.c (bfd_m68k_elf32_create_embedded_relocs): Delay reading of local syms. Use bfd_elf_get_elf_syms. Properly free possibly cached info. * elf32-mips.c (bfd_mips_elf32_create_embedded_relocs): Likewise. * elf64-hppa.c (elf64_hppa_check_relocs): Use bfd_elf_get_elf_syms. * elf64-ppc.c (struct ppc_link_hash_table): Delete bfd_count and all_local_syms. (get_local_syms): Delete function. (edit_opd): Use bfd_elf_get_elf_syms. Free on error exit. Cache on exit. (ppc64_elf_size_stubs): Use bfd_elf_get_elf_syms. Free/cache on exit.
Diffstat (limited to 'bfd/elf64-hppa.c')
-rw-r--r--bfd/elf64-hppa.c93
1 files changed, 28 insertions, 65 deletions
diff --git a/bfd/elf64-hppa.c b/bfd/elf64-hppa.c
index 929cacd..7ebbb52 100644
--- a/bfd/elf64-hppa.c
+++ b/bfd/elf64-hppa.c
@@ -591,7 +591,6 @@ elf64_hppa_check_relocs (abfd, info, sec, relocs)
struct elf64_hppa_link_hash_table *hppa_info;
const Elf_Internal_Rela *relend;
Elf_Internal_Shdr *symtab_hdr;
- Elf_Internal_Shdr *shndx_hdr;
const Elf_Internal_Rela *rel;
asection *dlt, *plt, *stubs;
char *buf;
@@ -613,15 +612,14 @@ elf64_hppa_check_relocs (abfd, info, sec, relocs)
symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
/* If necessary, build a new table holding section symbols indices
- for this BFD. This is disgusting. */
+ for this BFD. */
if (info->shared && hppa_info->section_syms_bfd != abfd)
{
unsigned long i;
unsigned int highest_shndx;
- Elf_Internal_Sym *local_syms, *isym;
- Elf64_External_Sym *ext_syms, *esym;
- Elf_External_Sym_Shndx *shndx_buf, *shndx;
+ Elf_Internal_Sym *local_syms = NULL;
+ Elf_Internal_Sym *isym, *isymend;
bfd_size_type amt;
/* We're done with the old cache of section index to section symbol
@@ -632,72 +630,27 @@ elf64_hppa_check_relocs (abfd, info, sec, relocs)
if (hppa_info->section_syms)
free (hppa_info->section_syms);
- /* Allocate memory for the internal and external symbols. */
- amt = symtab_hdr->sh_info;
- amt *= sizeof (Elf_Internal_Sym);
- local_syms = (Elf_Internal_Sym *) bfd_malloc (amt);
- if (local_syms == NULL)
- return false;
-
- amt = symtab_hdr->sh_info;
- amt *= sizeof (Elf64_External_Sym);
- ext_syms = (Elf64_External_Sym *) bfd_malloc (amt);
- if (ext_syms == NULL)
- {
- free (local_syms);
- return false;
- }
-
- /* Read in the local symbols. */
- if (bfd_seek (abfd, symtab_hdr->sh_offset, SEEK_SET) != 0
- || bfd_bread (ext_syms, amt, abfd) != amt)
+ /* Read this BFD's local symbols. */
+ if (symtab_hdr->sh_info != 0)
{
- free (ext_syms);
- free (local_syms);
- return false;
- }
-
- shndx_buf = NULL;
- shndx_hdr = &elf_tdata (abfd)->symtab_shndx_hdr;
- if (shndx_hdr->sh_size != 0)
- {
- amt = symtab_hdr->sh_info;
- amt *= sizeof (Elf_External_Sym_Shndx);
- shndx_buf = (Elf_External_Sym_Shndx *) bfd_malloc (amt);
- if (shndx_buf == NULL)
- {
- free (ext_syms);
- free (local_syms);
- return false;
- }
-
- if (bfd_seek (abfd, shndx_hdr->sh_offset, SEEK_SET) != 0
- || bfd_bread (shndx_buf, amt, abfd) != amt)
- {
- free (shndx_buf);
- free (ext_syms);
- free (local_syms);
- return false;
- }
+ local_syms = (Elf_Internal_Sym *) symtab_hdr->contents;
+ if (local_syms == NULL)
+ local_syms = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ symtab_hdr->sh_info, 0,
+ NULL, NULL, NULL);
+ if (local_syms == NULL)
+ return false;
}
- /* Swap in the local symbols, also record the highest section index
- referenced by the local symbols. */
+ /* Record the highest section index referenced by the local symbols. */
highest_shndx = 0;
- for (i = 0, isym = local_syms, esym = ext_syms, shndx = shndx_buf;
- i < symtab_hdr->sh_info;
- i++, esym++, isym++, shndx = (shndx != NULL ? shndx + 1 : NULL))
+ isymend = local_syms + symtab_hdr->sh_info;
+ for (isym = local_syms; isym < isymend; isym++)
{
- bfd_elf64_swap_symbol_in (abfd, (const PTR) esym, (const PTR) shndx,
- isym);
if (isym->st_shndx > highest_shndx)
highest_shndx = isym->st_shndx;
}
- /* Now we can free the external symbols. */
- free (shndx_buf);
- free (ext_syms);
-
/* Allocate an array to hold the section index to section symbol index
mapping. Bump by one since we start counting at zero. */
highest_shndx++;
@@ -707,14 +660,24 @@ elf64_hppa_check_relocs (abfd, info, sec, relocs)
/* Now walk the local symbols again. If we find a section symbol,
record the index of the symbol into the section_syms array. */
- for (isym = local_syms, i = 0; i < symtab_hdr->sh_info; i++, isym++)
+ for (i = 0, isym = local_syms; isym < isymend; i++, isym++)
{
if (ELF_ST_TYPE (isym->st_info) == STT_SECTION)
hppa_info->section_syms[isym->st_shndx] = i;
}
- /* We are finished with the local symbols. Get rid of them. */
- free (local_syms);
+ /* We are finished with the local symbols. */
+ if (local_syms != NULL
+ && symtab_hdr->contents != (unsigned char *) local_syms)
+ {
+ if (! info->keep_memory)
+ free (local_syms);
+ else
+ {
+ /* Cache the symbols for elf_link_input_bfd. */
+ symtab_hdr->contents = (unsigned char *) local_syms;
+ }
+ }
/* Record which BFD we built the section_syms mapping for. */
hppa_info->section_syms_bfd = abfd;