diff options
author | Alan Modra <amodra@gmail.com> | 2002-07-07 09:10:41 +0000 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2002-07-07 09:10:41 +0000 |
commit | 6cdc0ccc1276096134b1870e92875487ffdc8292 (patch) | |
tree | d9ce6f2bb8abc152c4b8d99c9761b8c46658e619 /bfd/elf64-alpha.c | |
parent | d8462f1281a70eddafd4f2f50f142491299b69c2 (diff) | |
download | gdb-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-alpha.c')
-rw-r--r-- | bfd/elf64-alpha.c | 130 |
1 files changed, 51 insertions, 79 deletions
diff --git a/bfd/elf64-alpha.c b/bfd/elf64-alpha.c index 32546f4..36b0cb6 100644 --- a/bfd/elf64-alpha.c +++ b/bfd/elf64-alpha.c @@ -2037,14 +2037,9 @@ elf64_alpha_relax_section (abfd, sec, link_info, again) boolean *again; { Elf_Internal_Shdr *symtab_hdr; - Elf_Internal_Shdr *shndx_hdr; Elf_Internal_Rela *internal_relocs; - Elf_Internal_Rela *free_relocs = NULL; Elf_Internal_Rela *irel, *irelend; - bfd_byte *free_contents = NULL; - Elf64_External_Sym *extsyms; - Elf64_External_Sym *free_extsyms = NULL; - Elf_External_Sym_Shndx *shndx_buf = NULL; + Elf_Internal_Sym *isymbuf = NULL; struct alpha_elf_got_entry **local_got_entries; struct alpha_relax_info info; struct elf_link_tls_segment tls_segment; @@ -2070,9 +2065,7 @@ elf64_alpha_relax_section (abfd, sec, link_info, again) (abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL, link_info->keep_memory)); if (internal_relocs == NULL) - goto error_return; - if (! link_info->keep_memory) - free_relocs = internal_relocs; + return false; memset(&info, 0, sizeof (info)); info.abfd = abfd; @@ -2101,41 +2094,12 @@ elf64_alpha_relax_section (abfd, sec, link_info, again) info.contents = (bfd_byte *) bfd_malloc (sec->_raw_size); if (info.contents == NULL) goto error_return; - free_contents = info.contents; if (! bfd_get_section_contents (abfd, sec, info.contents, (file_ptr) 0, sec->_raw_size)) goto error_return; } - /* Read this BFD's symbols. */ - if (symtab_hdr->contents != NULL) - extsyms = (Elf64_External_Sym *) symtab_hdr->contents; - else - { - bfd_size_type amt = symtab_hdr->sh_info * sizeof (Elf64_External_Sym); - extsyms = (Elf64_External_Sym *) bfd_malloc (amt); - if (extsyms == NULL) - goto error_return; - free_extsyms = extsyms; - if (bfd_seek (abfd, symtab_hdr->sh_offset, SEEK_SET) != 0 - || bfd_bread ((PTR) extsyms, amt, abfd) != amt) - goto error_return; - } - - shndx_hdr = &elf_tdata (abfd)->symtab_shndx_hdr; - if (shndx_hdr->sh_size != 0) - { - bfd_size_type amt; - amt = symtab_hdr->sh_info * sizeof (Elf_External_Sym_Shndx); - shndx_buf = (Elf_External_Sym_Shndx *) bfd_malloc (amt); - if (shndx_buf == NULL) - goto error_return; - if (bfd_seek (abfd, shndx_hdr->sh_offset, SEEK_SET) != 0 - || bfd_bread ((PTR) shndx_buf, amt, abfd) != amt) - goto error_return; - } - /* Compute the TLS segment information. The version normally found in elf_hash_table (link_info)->tls_segment isn't built until final_link. ??? Probably should look into extracting this into a common function. */ @@ -2144,7 +2108,6 @@ elf64_alpha_relax_section (abfd, sec, link_info, again) for (irel = internal_relocs; irel < irelend; irel++) { bfd_vma symval; - Elf_Internal_Sym isym; struct alpha_elf_got_entry *gotent; unsigned long r_type = ELF64_R_TYPE (irel->r_info); @@ -2167,26 +2130,34 @@ elf64_alpha_relax_section (abfd, sec, link_info, again) if (ELF64_R_SYM (irel->r_info) < symtab_hdr->sh_info) { /* A local symbol. */ - Elf64_External_Sym *esym; - Elf_External_Sym_Shndx *shndx; - - esym = extsyms + ELF64_R_SYM (irel->r_info); - shndx = shndx_buf + (shndx_buf ? ELF64_R_SYM (irel->r_info) : 0); - bfd_elf64_swap_symbol_in (abfd, (const PTR) esym, (const PTR) shndx, - &isym); - if (isym.st_shndx == SHN_UNDEF) + Elf_Internal_Sym *isym; + + /* Read this BFD's local symbols. */ + if (isymbuf == NULL) + { + isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; + if (isymbuf == NULL) + isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, + symtab_hdr->sh_info, 0, + NULL, NULL, NULL); + if (isymbuf == NULL) + goto error_return; + } + + isym = isymbuf + ELF64_R_SYM (irel->r_info); + if (isym->st_shndx == SHN_UNDEF) continue; - else if (isym.st_shndx == SHN_ABS) + else if (isym->st_shndx == SHN_ABS) info.tsec = bfd_abs_section_ptr; - else if (isym.st_shndx == SHN_COMMON) + else if (isym->st_shndx == SHN_COMMON) info.tsec = bfd_com_section_ptr; else - info.tsec = bfd_section_from_elf_index (abfd, isym.st_shndx); + info.tsec = bfd_section_from_elf_index (abfd, isym->st_shndx); info.h = NULL; - info.other = isym.st_other; + info.other = isym->st_other; info.first_gotent = &local_got_entries[ELF64_R_SYM(irel->r_info)]; - symval = isym.st_value; + symval = isym->st_value; } else { @@ -2281,17 +2252,23 @@ elf64_alpha_relax_section (abfd, sec, link_info, again) if (!elf64_alpha_size_rela_got_section (link_info)) return false; - if (info.changed_relocs) - elf_section_data (sec)->relocs = internal_relocs; - else if (free_relocs != NULL) - free (free_relocs); + if (isymbuf != NULL + && symtab_hdr->contents != (unsigned char *) isymbuf) + { + if (!link_info->keep_memory) + free (isymbuf); + else + { + /* Cache the symbols for elf_link_input_bfd. */ + symtab_hdr->contents = (unsigned char *) isymbuf; + } + } - if (info.changed_contents) - elf_section_data (sec)->this_hdr.contents = info.contents; - else if (free_contents != NULL) + if (info.contents != NULL + && elf_section_data (sec)->this_hdr.contents != info.contents) { - if (! link_info->keep_memory) - free (free_contents); + if (!info.changed_contents && !link_info->keep_memory) + free (info.contents); else { /* Cache the section contents for elf_link_input_bfd. */ @@ -2299,18 +2276,12 @@ elf64_alpha_relax_section (abfd, sec, link_info, again) } } - if (shndx_buf != NULL) - free (shndx_buf); - - if (free_extsyms != NULL) + if (elf_section_data (sec)->relocs != internal_relocs) { - if (! link_info->keep_memory) - free (free_extsyms); + if (!info.changed_relocs) + free (internal_relocs); else - { - /* Cache the symbols for elf_link_input_bfd. */ - symtab_hdr->contents = (unsigned char *) extsyms; - } + elf_section_data (sec)->relocs = internal_relocs; } *again = info.changed_contents || info.changed_relocs; @@ -2318,14 +2289,15 @@ elf64_alpha_relax_section (abfd, sec, link_info, again) return true; error_return: - if (free_relocs != NULL) - free (free_relocs); - if (free_contents != NULL) - free (free_contents); - if (shndx_buf != NULL) - free (shndx_buf); - if (free_extsyms != NULL) - free (free_extsyms); + if (isymbuf != NULL + && symtab_hdr->contents != (unsigned char *) isymbuf) + free (isymbuf); + if (info.contents != NULL + && elf_section_data (sec)->this_hdr.contents != info.contents) + free (info.contents); + if (internal_relocs != NULL + && elf_section_data (sec)->relocs != internal_relocs) + free (internal_relocs); return false; } |