aboutsummaryrefslogtreecommitdiff
path: root/bfd/elf32-m68k.c
diff options
context:
space:
mode:
Diffstat (limited to 'bfd/elf32-m68k.c')
-rw-r--r--bfd/elf32-m68k.c101
1 files changed, 31 insertions, 70 deletions
diff --git a/bfd/elf32-m68k.c b/bfd/elf32-m68k.c
index b507fba..2c50ed08 100644
--- a/bfd/elf32-m68k.c
+++ b/bfd/elf32-m68k.c
@@ -37,7 +37,7 @@ static boolean elf_m68k_check_relocs
PARAMS ((bfd *, struct bfd_link_info *, asection *,
const Elf_Internal_Rela *));
static asection *elf_m68k_gc_mark_hook
- PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Rela *,
+ PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
struct elf_link_hash_entry *, Elf_Internal_Sym *));
static boolean elf_m68k_gc_sweep_hook
PARAMS ((bfd *, struct bfd_link_info *, asection *,
@@ -180,8 +180,6 @@ reloc_type_lookup (abfd, code)
#define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup
#define ELF_ARCH bfd_arch_m68k
/* end code generated by elf.el */
-
-#define USE_RELA
/* Functions for the m68k ELF linker. */
@@ -754,8 +752,8 @@ elf_m68k_check_relocs (abfd, info, sec, relocs)
relocation. */
static asection *
-elf_m68k_gc_mark_hook (abfd, info, rel, h, sym)
- bfd *abfd;
+elf_m68k_gc_mark_hook (sec, info, rel, h, sym)
+ asection *sec;
struct bfd_link_info *info ATTRIBUTE_UNUSED;
Elf_Internal_Rela *rel;
struct elf_link_hash_entry *h;
@@ -785,9 +783,7 @@ elf_m68k_gc_mark_hook (abfd, info, rel, h, sym)
}
}
else
- {
- return bfd_section_from_elf_index (abfd, sym->st_shndx);
- }
+ return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
return NULL;
}
@@ -2113,12 +2109,8 @@ bfd_m68k_elf32_create_embedded_relocs (abfd, info, datasec, relsec, errmsg)
char **errmsg;
{
Elf_Internal_Shdr *symtab_hdr;
- Elf_Internal_Shdr *shndx_hdr;
- Elf32_External_Sym *extsyms;
- Elf32_External_Sym *free_extsyms = NULL;
- Elf_External_Sym_Shndx *shndx_buf = NULL;
- Elf_Internal_Rela *internal_relocs;
- Elf_Internal_Rela *free_relocs = NULL;
+ Elf_Internal_Sym *isymbuf = NULL;
+ Elf_Internal_Rela *internal_relocs = NULL;
Elf_Internal_Rela *irel, *irelend;
bfd_byte *p;
bfd_size_type amt;
@@ -2131,40 +2123,6 @@ bfd_m68k_elf32_create_embedded_relocs (abfd, info, datasec, relsec, errmsg)
return true;
symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
- /* Read this BFD's symbols if we haven't done so already, or get the cached
- copy if it exists. */
- if (symtab_hdr->contents != NULL)
- extsyms = (Elf32_External_Sym *) symtab_hdr->contents;
- else
- {
- /* Go get them off disk. */
- amt = symtab_hdr->sh_info * sizeof (Elf32_External_Sym);
- if (info->keep_memory)
- extsyms = (Elf32_External_Sym *) bfd_alloc (abfd, amt);
- else
- extsyms = (Elf32_External_Sym *) bfd_malloc (amt);
- if (extsyms == NULL)
- goto error_return;
- if (! info->keep_memory)
- free_extsyms = extsyms;
- if (bfd_seek (abfd, symtab_hdr->sh_offset, SEEK_SET) != 0
- || bfd_bread (extsyms, amt, abfd) != amt)
- goto error_return;
- if (info->keep_memory)
- symtab_hdr->contents = (unsigned char *) extsyms;
- }
-
- shndx_hdr = &elf_tdata (abfd)->symtab_shndx_hdr;
- if (shndx_hdr->sh_size != 0)
- {
- 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;
- }
/* Get a copy of the native relocations. */
internal_relocs = (_bfd_elf32_link_read_relocs
@@ -2172,8 +2130,6 @@ bfd_m68k_elf32_create_embedded_relocs (abfd, info, datasec, relsec, errmsg)
info->keep_memory));
if (internal_relocs == NULL)
goto error_return;
- if (! info->keep_memory)
- free_relocs = internal_relocs;
amt = (bfd_size_type) datasec->reloc_count * 12;
relsec->contents = (bfd_byte *) bfd_alloc (abfd, amt);
@@ -2204,16 +2160,23 @@ bfd_m68k_elf32_create_embedded_relocs (abfd, info, datasec, relsec, errmsg)
/* Get the target section referred to by the reloc. */
if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
{
- Elf32_External_Sym *esym;
- Elf_External_Sym_Shndx *shndx;
- Elf_Internal_Sym isym;
-
/* A local symbol. */
- esym = extsyms + ELF32_R_SYM (irel->r_info);
- shndx = shndx_buf + (shndx_buf ? ELF32_R_SYM (irel->r_info) : 0);
- bfd_elf32_swap_symbol_in (abfd, esym, shndx, &isym);
+ Elf_Internal_Sym *isym;
+
+ /* Read this BFD's local symbols if we haven't done so already. */
+ 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;
+ }
- targetsec = bfd_section_from_elf_index (abfd, isym.st_shndx);
+ isym = isymbuf + ELF32_R_SYM (irel->r_info);
+ targetsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
}
else
{
@@ -2237,21 +2200,19 @@ bfd_m68k_elf32_create_embedded_relocs (abfd, info, datasec, relsec, errmsg)
strncpy (p + 4, targetsec->output_section->name, 8);
}
- if (shndx_buf != NULL)
- free (shndx_buf);
- if (free_extsyms != NULL)
- free (free_extsyms);
- if (free_relocs != NULL)
- free (free_relocs);
+ if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
+ free (isymbuf);
+ if (internal_relocs != NULL
+ && elf_section_data (datasec)->relocs != internal_relocs)
+ free (internal_relocs);
return true;
error_return:
- if (shndx_buf != NULL)
- free (shndx_buf);
- if (free_extsyms != NULL)
- free (free_extsyms);
- if (free_relocs != NULL)
- free (free_relocs);
+ if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
+ free (isymbuf);
+ if (internal_relocs != NULL
+ && elf_section_data (datasec)->relocs != internal_relocs)
+ free (internal_relocs);
return false;
}