aboutsummaryrefslogtreecommitdiff
path: root/bfd/elf-m10300.c
diff options
context:
space:
mode:
Diffstat (limited to 'bfd/elf-m10300.c')
-rw-r--r--bfd/elf-m10300.c659
1 files changed, 196 insertions, 463 deletions
diff --git a/bfd/elf-m10300.c b/bfd/elf-m10300.c
index 501c3dd..2c9b4a9 100644
--- a/bfd/elf-m10300.c
+++ b/bfd/elf-m10300.c
@@ -127,7 +127,7 @@ static asection *mn10300_elf_gc_mark_hook
static boolean mn10300_elf_relax_delete_bytes
PARAMS ((bfd *, asection *, bfd_vma, int));
static boolean mn10300_elf_symbol_address_p
- PARAMS ((bfd *, asection *, bfd_vma));
+PARAMS ((bfd *, asection *, Elf_Internal_Sym *, bfd_vma));
static boolean elf32_mn10300_finish_hash_table_entry
PARAMS ((struct bfd_hash_entry *, PTR));
static void compute_function_info
@@ -783,16 +783,12 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
boolean *again;
{
Elf_Internal_Shdr *symtab_hdr;
- Elf_Internal_Shdr *shndx_hdr;
Elf_Internal_Rela *internal_relocs = NULL;
- Elf_Internal_Rela *free_relocs = NULL;
Elf_Internal_Rela *irel, *irelend;
bfd_byte *contents = NULL;
- bfd_byte *free_contents = NULL;
- Elf32_External_Sym *extsyms = NULL;
- Elf32_External_Sym *free_extsyms = NULL;
- Elf_External_Sym_Shndx *shndx_buf = NULL;
+ Elf_Internal_Sym *isymbuf = NULL;
struct elf32_mn10300_link_hash_table *hash_table;
+ asection *section = sec;
/* Assume nothing changes. */
*again = false;
@@ -810,42 +806,16 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
input_bfd != NULL;
input_bfd = input_bfd->link_next)
{
- asection *section;
-
/* We're going to need all the symbols for each bfd. */
symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
- shndx_hdr = &elf_tdata (input_bfd)->symtab_shndx_hdr;
-
- /* Get cached copy if it exists. */
- if (symtab_hdr->contents != NULL)
- extsyms = (Elf32_External_Sym *) symtab_hdr->contents;
- else
- {
- /* Go get them off disk. */
- bfd_size_type amt;
-
- amt = symtab_hdr->sh_info;
- amt *= sizeof (Elf32_External_Sym);
- extsyms = (Elf32_External_Sym *) bfd_malloc (amt);
- if (extsyms == NULL)
- goto error_return;
- free_extsyms = extsyms;
- if (bfd_seek (input_bfd, symtab_hdr->sh_offset, SEEK_SET) != 0
- || bfd_bread ((PTR) extsyms, amt, input_bfd) != amt)
- goto error_return;
- }
-
- if (shndx_hdr->sh_size != 0)
+ if (symtab_hdr->sh_info != 0)
{
- bfd_size_type amt;
-
- amt = symtab_hdr->sh_info;
- amt *= sizeof (Elf_External_Sym_Shndx);
- shndx_buf = (Elf_External_Sym_Shndx *) bfd_malloc (amt);
- if (shndx_buf == NULL)
- goto error_return;
- if (bfd_seek (input_bfd, shndx_hdr->sh_offset, SEEK_SET) != 0
- || bfd_bread ((PTR) shndx_buf, amt, input_bfd) != amt)
+ isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
+ if (isymbuf == NULL)
+ isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ symtab_hdr->sh_info, 0,
+ NULL, NULL, NULL);
+ if (isymbuf == NULL)
goto error_return;
}
@@ -875,7 +845,6 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
contents = (bfd_byte *) bfd_malloc (section->_raw_size);
if (contents == NULL)
goto error_return;
- free_contents = contents;
if (!bfd_get_section_contents (input_bfd, section,
contents, (file_ptr) 0,
@@ -883,10 +852,7 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
goto error_return;
}
else
- {
- contents = NULL;
- free_contents = NULL;
- }
+ contents = NULL;
/* If there aren't any relocs, then there's nothing to do. */
if ((section->flags & SEC_RELOC) != 0
@@ -900,8 +866,6 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
link_info->keep_memory));
if (internal_relocs == NULL)
goto error_return;
- if (! link_info->keep_memory)
- free_relocs = internal_relocs;
/* Now examine each relocation. */
irel = internal_relocs;
@@ -927,40 +891,31 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
if (r_index < symtab_hdr->sh_info)
{
/* A local symbol. */
- Elf32_External_Sym *esym;
- Elf_External_Sym_Shndx *shndx;
- Elf_Internal_Sym isym;
+ Elf_Internal_Sym *isym;
struct elf_link_hash_table *elftab;
bfd_size_type amt;
- esym = extsyms + r_index;
- shndx = shndx_buf + (shndx_buf ? r_index : 0);
- bfd_elf32_swap_symbol_in (input_bfd,
- (const PTR) esym,
- (const PTR) shndx,
- &isym);
-
- if (isym.st_shndx == SHN_UNDEF)
+ isym = isymbuf + r_index;
+ if (isym->st_shndx == SHN_UNDEF)
sym_sec = bfd_und_section_ptr;
- else if (isym.st_shndx == SHN_ABS)
+ else if (isym->st_shndx == SHN_ABS)
sym_sec = bfd_abs_section_ptr;
- else if (isym.st_shndx == SHN_COMMON)
+ else if (isym->st_shndx == SHN_COMMON)
sym_sec = bfd_com_section_ptr;
else
sym_sec
= bfd_section_from_elf_index (input_bfd,
- isym.st_shndx);
+ isym->st_shndx);
sym_name
= bfd_elf_string_from_elf_section (input_bfd,
(symtab_hdr
->sh_link),
- isym.st_name);
+ isym->st_name);
/* If it isn't a function, then we don't care
about it. */
- if (r_index < symtab_hdr->sh_info
- && ELF_ST_TYPE (isym.st_info) != STT_FUNC)
+ if (ELF_ST_TYPE (isym->st_info) != STT_FUNC)
continue;
/* Tack on an ID so we can uniquely identify this
@@ -995,8 +950,9 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
if (code != 0xdd && code != 0xcd)
hash->flags |= MN10300_CONVERT_CALL_TO_CALLS;
- /* If this is a jump/call, then bump the direct_calls
- counter. Else force "call" to "calls" conversions. */
+ /* If this is a jump/call, then bump the
+ direct_calls counter. Else force "call" to
+ "calls" conversions. */
if (r_type == R_MN10300_PCREL32
|| r_type == R_MN10300_PCREL16)
hash->direct_calls++;
@@ -1010,46 +966,40 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
(ie movm_args). */
if ((section->flags & SEC_CODE) != 0)
{
-
- Elf32_External_Sym *esym, *esymend;
- Elf_External_Sym_Shndx *shndx;
- int idx;
+ Elf_Internal_Sym *isym, *isymend;
unsigned int sec_shndx;
+ struct elf_link_hash_entry **hashes;
+ struct elf_link_hash_entry **end_hashes;
+ unsigned int symcount;
sec_shndx = _bfd_elf_section_from_bfd_section (input_bfd,
section);
/* Look at each function defined in this section and
update info for that function. */
- for (esym = extsyms, esymend = esym + symtab_hdr->sh_info,
- shndx = shndx_buf;
- esym < esymend;
- esym++, shndx = (shndx ? shndx + 1 : NULL))
+ isymend = isymbuf + symtab_hdr->sh_info;
+ for (isym = isymbuf; isym < isymend; isym++)
{
- Elf_Internal_Sym isym;
-
- bfd_elf32_swap_symbol_in (input_bfd, (const PTR) esym,
- (const PTR) shndx, &isym);
- if (isym.st_shndx == sec_shndx
- && ELF_ST_TYPE (isym.st_info) == STT_FUNC)
+ if (isym->st_shndx == sec_shndx
+ && ELF_ST_TYPE (isym->st_info) == STT_FUNC)
{
struct elf_link_hash_table *elftab;
bfd_size_type amt;
- if (isym.st_shndx == SHN_UNDEF)
+ if (isym->st_shndx == SHN_UNDEF)
sym_sec = bfd_und_section_ptr;
- else if (isym.st_shndx == SHN_ABS)
+ else if (isym->st_shndx == SHN_ABS)
sym_sec = bfd_abs_section_ptr;
- else if (isym.st_shndx == SHN_COMMON)
+ else if (isym->st_shndx == SHN_COMMON)
sym_sec = bfd_com_section_ptr;
else
sym_sec
= bfd_section_from_elf_index (input_bfd,
- isym.st_shndx);
+ isym->st_shndx);
sym_name = (bfd_elf_string_from_elf_section
(input_bfd, symtab_hdr->sh_link,
- isym.st_name));
+ isym->st_name));
/* Tack on an ID so we can uniquely identify this
local symbol in the global hash table. */
@@ -1068,23 +1018,21 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
true, true, false));
free (new_name);
compute_function_info (input_bfd, hash,
- isym.st_value, contents);
+ isym->st_value, contents);
}
}
- esym = extsyms + symtab_hdr->sh_info;
- esymend = extsyms + (symtab_hdr->sh_size
- / sizeof (Elf32_External_Sym));
- for (idx = 0; esym < esymend; esym++, idx++)
+ symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
+ - symtab_hdr->sh_info);
+ hashes = elf_sym_hashes (abfd);
+ end_hashes = hashes + symcount;
+ for (; hashes < end_hashes; hashes++)
{
- Elf_Internal_Sym isym;
-
- hash = (struct elf32_mn10300_link_hash_entry *)
- elf_sym_hashes (input_bfd)[idx];
+ hash = (struct elf32_mn10300_link_hash_entry *) *hashes;
if ((hash->root.root.type == bfd_link_hash_defined
|| hash->root.root.type == bfd_link_hash_defweak)
&& hash->root.root.u.def.section == section
- && ELF_ST_TYPE (isym.st_info) == STT_FUNC)
+ && ELF_ST_TYPE (isym->st_info) == STT_FUNC)
compute_function_info (input_bfd, hash,
(hash)->root.root.u.def.value,
contents);
@@ -1092,44 +1040,39 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
}
/* Cache or free any memory we allocated for the relocs. */
- if (free_relocs != NULL)
- {
- free (free_relocs);
- free_relocs = NULL;
- }
+ if (internal_relocs != NULL
+ && elf_section_data (section)->relocs != internal_relocs)
+ free (internal_relocs);
+ internal_relocs = NULL;
/* Cache or free any memory we allocated for the contents. */
- if (free_contents != NULL)
+ if (contents != NULL
+ && elf_section_data (section)->this_hdr.contents != contents)
{
if (! link_info->keep_memory)
- free (free_contents);
+ free (contents);
else
{
/* Cache the section contents for elf_link_input_bfd. */
elf_section_data (section)->this_hdr.contents = contents;
}
- free_contents = NULL;
}
- }
-
- if (shndx_buf != NULL)
- {
- free (shndx_buf);
- shndx_buf = NULL;
+ contents = NULL;
}
/* Cache or free any memory we allocated for the symbols. */
- if (free_extsyms != NULL)
+ if (isymbuf != NULL
+ && symtab_hdr->contents != (unsigned char *) isymbuf)
{
if (! link_info->keep_memory)
- free (free_extsyms);
+ free (isymbuf);
else
{
/* Cache the symbols for elf_link_input_bfd. */
- symtab_hdr->contents = (unsigned char *) extsyms;
+ symtab_hdr->contents = (unsigned char *) isymbuf;
}
- free_extsyms = NULL;
}
+ isymbuf = NULL;
}
/* Now iterate on each symbol in the hash table and perform
@@ -1152,45 +1095,17 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
input_bfd != NULL;
input_bfd = input_bfd->link_next)
{
- asection *section;
-
/* We're going to need all the local symbols for each bfd. */
symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
- shndx_hdr = &elf_tdata (input_bfd)->symtab_shndx_hdr;
-
- /* Get cached copy if it exists. */
- if (symtab_hdr->contents != NULL)
- extsyms = (Elf32_External_Sym *) symtab_hdr->contents;
- else
- {
- /* Go get them off disk. */
- bfd_size_type amt;
-
- amt = symtab_hdr->sh_info;
- amt *= sizeof (Elf32_External_Sym);
- extsyms = (Elf32_External_Sym *) bfd_malloc (amt);
- if (extsyms == NULL)
- goto error_return;
- free_extsyms = extsyms;
- if (bfd_seek (input_bfd, symtab_hdr->sh_offset, SEEK_SET) != 0
- || bfd_bread ((PTR) extsyms, amt, input_bfd) != amt)
- goto error_return;
- symtab_hdr->contents = (bfd_byte *) extsyms;
- }
-
- if (shndx_hdr->sh_size != 0)
+ if (symtab_hdr->sh_info != 0)
{
- bfd_size_type amt;
-
- amt = symtab_hdr->sh_info;
- amt *= sizeof (Elf_External_Sym_Shndx);
- shndx_buf = (Elf_External_Sym_Shndx *) bfd_malloc (amt);
- if (shndx_buf == NULL)
- goto error_return;
- if (bfd_seek (input_bfd, shndx_hdr->sh_offset, SEEK_SET) != 0
- || bfd_bread ((PTR) shndx_buf, amt, input_bfd) != amt)
+ isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
+ if (isymbuf == NULL)
+ isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ symtab_hdr->sh_info, 0,
+ NULL, NULL, NULL);
+ if (isymbuf == NULL)
goto error_return;
- shndx_hdr->contents = (bfd_byte *) shndx_buf;
}
/* Walk over each section in this bfd. */
@@ -1199,9 +1114,10 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
section = section->next)
{
unsigned int sec_shndx;
- Elf32_External_Sym *esym, *esymend;
- Elf_External_Sym_Shndx *shndx;
- unsigned int idx;
+ Elf_Internal_Sym *isym, *isymend;
+ struct elf_link_hash_entry **hashes;
+ struct elf_link_hash_entry **end_hashes;
+ unsigned int symcount;
/* Skip non-code sections and empty sections. */
if ((section->flags & SEC_CODE) == 0 || section->_raw_size == 0)
@@ -1216,8 +1132,6 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
link_info->keep_memory));
if (internal_relocs == NULL)
goto error_return;
- if (! link_info->keep_memory)
- free_relocs = internal_relocs;
}
/* Get cached copy of section contents if it exists. */
@@ -1229,7 +1143,6 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
contents = (bfd_byte *) bfd_malloc (section->_raw_size);
if (contents == NULL)
goto error_return;
- free_contents = contents;
if (!bfd_get_section_contents (input_bfd, section,
contents, (file_ptr) 0,
@@ -1242,12 +1155,9 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
/* Now look for any function in this section which needs
insns deleted from its prologue. */
- for (esym = extsyms, esymend = esym + symtab_hdr->sh_info,
- shndx = shndx_buf;
- esym < esymend;
- esym++, shndx = (shndx ? shndx + 1 : NULL))
+ isymend = isymbuf + symtab_hdr->sh_info;
+ for (isym = isymbuf; isym < isymend; isym++)
{
- Elf_Internal_Sym isym;
struct elf32_mn10300_link_hash_entry *sym_hash;
asection *sym_sec = NULL;
const char *sym_name;
@@ -1255,26 +1165,23 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
struct elf_link_hash_table *elftab;
bfd_size_type amt;
- bfd_elf32_swap_symbol_in (input_bfd, (const PTR) esym,
- (const PTR) shndx, &isym);
-
- if (isym.st_shndx != sec_shndx)
+ if (isym->st_shndx != sec_shndx)
continue;
- if (isym.st_shndx == SHN_UNDEF)
+ if (isym->st_shndx == SHN_UNDEF)
sym_sec = bfd_und_section_ptr;
- else if (isym.st_shndx == SHN_ABS)
+ else if (isym->st_shndx == SHN_ABS)
sym_sec = bfd_abs_section_ptr;
- else if (isym.st_shndx == SHN_COMMON)
+ else if (isym->st_shndx == SHN_COMMON)
sym_sec = bfd_com_section_ptr;
else
sym_sec
- = bfd_section_from_elf_index (input_bfd, isym.st_shndx);
+ = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
sym_name
= bfd_elf_string_from_elf_section (input_bfd,
symtab_hdr->sh_link,
- isym.st_name);
+ isym->st_name);
/* Tack on an ID so we can uniquely identify this
local symbol in the global hash table. */
@@ -1301,12 +1208,8 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
/* Note that we've changed things. */
elf_section_data (section)->relocs = internal_relocs;
- free_relocs = NULL;
-
elf_section_data (section)->this_hdr.contents = contents;
- free_contents = NULL;
-
- free_extsyms = NULL;
+ symtab_hdr->contents = (unsigned char *) isymbuf;
/* Count how many bytes we're going to delete. */
if (sym_hash->movm_args)
@@ -1325,7 +1228,7 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
/* Actually delete the bytes. */
if (!mn10300_elf_relax_delete_bytes (input_bfd,
section,
- isym.st_value,
+ isym->st_value,
bytes))
goto error_return;
@@ -1337,15 +1240,15 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
/* Look for any global functions in this section which
need insns deleted from their prologues. */
- for (idx = 0;
- idx < (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
+ symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
- symtab_hdr->sh_info);
- idx++)
+ hashes = elf_sym_hashes (abfd);
+ end_hashes = hashes + symcount;
+ for (; hashes < end_hashes; hashes++)
{
struct elf32_mn10300_link_hash_entry *sym_hash;
- sym_hash = (struct elf32_mn10300_link_hash_entry *)
- (elf_sym_hashes (input_bfd)[idx]);
+ sym_hash = (struct elf32_mn10300_link_hash_entry *) *hashes;
if ((sym_hash->root.root.type == bfd_link_hash_defined
|| sym_hash->root.root.type == bfd_link_hash_defweak)
&& sym_hash->root.root.u.def.section == section
@@ -1357,12 +1260,8 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
/* Note that we've changed things. */
elf_section_data (section)->relocs = internal_relocs;
- free_relocs = NULL;
-
elf_section_data (section)->this_hdr.contents = contents;
- free_contents = NULL;
-
- free_extsyms = NULL;
+ symtab_hdr->contents = (unsigned char *) isymbuf;
/* Count how many bytes we're going to delete. */
if (sym_hash->movm_args)
@@ -1393,53 +1292,48 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
}
/* Cache or free any memory we allocated for the relocs. */
- if (free_relocs != NULL)
- {
- free (free_relocs);
- free_relocs = NULL;
- }
+ if (internal_relocs != NULL
+ && elf_section_data (section)->relocs != internal_relocs)
+ free (internal_relocs);
+ internal_relocs = NULL;
/* Cache or free any memory we allocated for the contents. */
- if (free_contents != NULL)
+ if (contents != NULL
+ && elf_section_data (section)->this_hdr.contents != contents)
{
if (! link_info->keep_memory)
- free (free_contents);
+ free (contents);
else
{
/* Cache the section contents for elf_link_input_bfd. */
elf_section_data (section)->this_hdr.contents = contents;
}
- free_contents = NULL;
}
- }
-
- if (shndx_buf != NULL)
- {
- shndx_hdr->contents = NULL;
- free (shndx_buf);
- shndx_buf = NULL;
+ contents = NULL;
}
/* Cache or free any memory we allocated for the symbols. */
- if (free_extsyms != NULL)
+ if (isymbuf != NULL
+ && symtab_hdr->contents != (unsigned char *) isymbuf)
{
if (! link_info->keep_memory)
+ free (isymbuf);
+ else
{
- symtab_hdr->contents = NULL;
- free (free_extsyms);
+ /* Cache the symbols for elf_link_input_bfd. */
+ symtab_hdr->contents = (unsigned char *) isymbuf;
}
- free_extsyms = NULL;
}
+ isymbuf = NULL;
}
}
/* (Re)initialize for the basic instruction shortening/relaxing pass. */
contents = NULL;
- extsyms = NULL;
internal_relocs = NULL;
- free_relocs = NULL;
- free_contents = NULL;
- free_extsyms = NULL;
+ isymbuf = NULL;
+ /* For error_return. */
+ section = sec;
/* We don't have to do anything for a relocateable link, if
this section does not have relocs, or if this is not a
@@ -1456,7 +1350,6 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
sec->_cooked_size = sec->_raw_size;
symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
- shndx_hdr = &elf_tdata (abfd)->symtab_shndx_hdr;
/* Get a copy of the native relocations. */
internal_relocs = (_bfd_elf32_link_read_relocs
@@ -1464,8 +1357,6 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
link_info->keep_memory));
if (internal_relocs == NULL)
goto error_return;
- if (! link_info->keep_memory)
- free_relocs = internal_relocs;
/* Walk through them looking for relaxing opportunities. */
irelend = internal_relocs + sec->reloc_count;
@@ -1493,7 +1384,6 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
contents = (bfd_byte *) bfd_malloc (sec->_raw_size);
if (contents == NULL)
goto error_return;
- free_contents = contents;
if (! bfd_get_section_contents (abfd, sec, contents,
(file_ptr) 0, sec->_raw_size))
@@ -1501,76 +1391,43 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
}
}
- /* Read this BFD's symbols if we haven't done so already. */
- if (extsyms == NULL)
+ /* Read this BFD's symbols if we haven't done so already. */
+ if (isymbuf == NULL && symtab_hdr->sh_info != 0)
{
- /* Get cached copy if it exists. */
- if (symtab_hdr->contents != NULL)
- extsyms = (Elf32_External_Sym *) symtab_hdr->contents;
- else
- {
- /* Go get them off disk. */
- bfd_size_type amt;
-
- amt = symtab_hdr->sh_info;
- amt *= sizeof (Elf32_External_Sym);
- extsyms = (Elf32_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;
- symtab_hdr->contents = (bfd_byte *) extsyms;
- }
-
- if (shndx_hdr->sh_size != 0)
- {
- bfd_size_type amt;
-
- amt = symtab_hdr->sh_info;
- amt *= 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;
- shndx_hdr->contents = (bfd_byte *) shndx_buf;
- }
+ 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;
}
/* Get the value of the symbol 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;
+ Elf_Internal_Sym *isym;
asection *sym_sec = NULL;
const char *sym_name;
char *new_name;
/* 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, (const PTR) esym,
- (const PTR) shndx, &isym);
-
- if (isym.st_shndx == SHN_UNDEF)
+ isym = isymbuf + ELF32_R_SYM (irel->r_info);
+ if (isym->st_shndx == SHN_UNDEF)
sym_sec = bfd_und_section_ptr;
- else if (isym.st_shndx == SHN_ABS)
+ else if (isym->st_shndx == SHN_ABS)
sym_sec = bfd_abs_section_ptr;
- else if (isym.st_shndx == SHN_COMMON)
+ else if (isym->st_shndx == SHN_COMMON)
sym_sec = bfd_com_section_ptr;
else
- sym_sec = bfd_section_from_elf_index (abfd, isym.st_shndx);
+ sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
- symval = (isym.st_value
+ symval = (isym->st_value
+ sym_sec->output_section->vma
+ sym_sec->output_offset);
sym_name = bfd_elf_string_from_elf_section (abfd,
symtab_hdr->sh_link,
- isym.st_name);
+ isym->st_name);
/* Tack on an ID so we can uniquely identify this
local symbol in the global hash table. */
@@ -1638,12 +1495,8 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
/* Note that we've changed the relocs, section contents,
etc. */
elf_section_data (sec)->relocs = internal_relocs;
- free_relocs = NULL;
-
elf_section_data (sec)->this_hdr.contents = contents;
- free_contents = NULL;
-
- free_extsyms = NULL;
+ symtab_hdr->contents = (unsigned char *) isymbuf;
/* Fix the opcode. */
bfd_put_8 (abfd, 0xfc, contents + irel->r_offset - 1);
@@ -1702,12 +1555,8 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
/* Note that we've changed the relocs, section contents, etc. */
elf_section_data (sec)->relocs = internal_relocs;
- free_relocs = NULL;
-
elf_section_data (sec)->this_hdr.contents = contents;
- free_contents = NULL;
-
- free_extsyms = NULL;
+ symtab_hdr->contents = (unsigned char *) isymbuf;
/* Fix the opcode. */
if (code == 0xdc)
@@ -1753,12 +1602,8 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
/* Note that we've changed the relocs, section contents,
etc. */
elf_section_data (sec)->relocs = internal_relocs;
- free_relocs = NULL;
-
elf_section_data (sec)->this_hdr.contents = contents;
- free_contents = NULL;
-
- free_extsyms = NULL;
+ symtab_hdr->contents = (unsigned char *) isymbuf;
/* Fix the opcode. */
bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 1);
@@ -1815,12 +1660,8 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
/* Note that we've changed the relocs, section contents, etc. */
elf_section_data (sec)->relocs = internal_relocs;
- free_relocs = NULL;
-
elf_section_data (sec)->this_hdr.contents = contents;
- free_contents = NULL;
-
- free_extsyms = NULL;
+ symtab_hdr->contents = (unsigned char *) isymbuf;
/* Fix the opcode. */
bfd_put_8 (abfd, 0xca, contents + irel->r_offset - 1);
@@ -1904,17 +1745,14 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
/* We also have to be sure there is no symbol/label
at the unconditional branch. */
- if (mn10300_elf_symbol_address_p (abfd, sec, irel->r_offset + 1))
+ if (mn10300_elf_symbol_address_p (abfd, sec, isymbuf,
+ irel->r_offset + 1))
continue;
/* Note that we've changed the relocs, section contents, etc. */
elf_section_data (sec)->relocs = internal_relocs;
- free_relocs = NULL;
-
elf_section_data (sec)->this_hdr.contents = contents;
- free_contents = NULL;
-
- free_extsyms = NULL;
+ symtab_hdr->contents = (unsigned char *) isymbuf;
/* Reverse the condition of the first branch. */
switch (code)
@@ -2022,12 +1860,8 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
/* Note that we've changed the relocation contents,
etc. */
elf_section_data (sec)->relocs = internal_relocs;
- free_relocs = NULL;
-
elf_section_data (sec)->this_hdr.contents = contents;
- free_contents = NULL;
-
- free_extsyms = NULL;
+ symtab_hdr->contents = (unsigned char *) isymbuf;
/* Fix the opcode. */
bfd_put_8 (abfd, 0xfb, contents + irel->r_offset - 3);
@@ -2097,12 +1931,8 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
/* Note that we've changed the relocation contents,
etc. */
elf_section_data (sec)->relocs = internal_relocs;
- free_relocs = NULL;
-
elf_section_data (sec)->this_hdr.contents = contents;
- free_contents = NULL;
-
- free_extsyms = NULL;
+ symtab_hdr->contents = (unsigned char *) isymbuf;
/* Fix the opcode. */
bfd_put_8 (abfd, 0xfd, contents + irel->r_offset - 3);
@@ -2180,12 +2010,8 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
/* Note that we've changed the relocation contents, etc. */
elf_section_data (sec)->relocs = internal_relocs;
- free_relocs = NULL;
-
elf_section_data (sec)->this_hdr.contents = contents;
- free_contents = NULL;
-
- free_extsyms = NULL;
+ symtab_hdr->contents = (unsigned char *) isymbuf;
/* Fix the opcode. */
bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
@@ -2217,12 +2043,8 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
case 0x83:
/* Note that we've changed the relocation contents, etc. */
elf_section_data (sec)->relocs = internal_relocs;
- free_relocs = NULL;
-
elf_section_data (sec)->this_hdr.contents = contents;
- free_contents = NULL;
-
- free_extsyms = NULL;
+ symtab_hdr->contents = (unsigned char *) isymbuf;
if ((code & 0xf3) == 0x81)
code = 0x01 + (code & 0x0c);
@@ -2271,12 +2093,8 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
/* Note that we've changed the relocation contents, etc. */
elf_section_data (sec)->relocs = internal_relocs;
- free_relocs = NULL;
-
elf_section_data (sec)->this_hdr.contents = contents;
- free_contents = NULL;
-
- free_extsyms = NULL;
+ symtab_hdr->contents = (unsigned char *) isymbuf;
/* Fix the opcode. */
bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
@@ -2323,12 +2141,8 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
/* Note that we've changed the relocation contents, etc. */
elf_section_data (sec)->relocs = internal_relocs;
- free_relocs = NULL;
-
elf_section_data (sec)->this_hdr.contents = contents;
- free_contents = NULL;
-
- free_extsyms = NULL;
+ symtab_hdr->contents = (unsigned char *) isymbuf;
if ((code & 0xfc) == 0xcc)
code = 0x2c + (code & 0x03);
@@ -2404,12 +2218,8 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
/* Note that we've changed the relocation contents, etc. */
elf_section_data (sec)->relocs = internal_relocs;
- free_relocs = NULL;
-
elf_section_data (sec)->this_hdr.contents = contents;
- free_contents = NULL;
-
- free_extsyms = NULL;
+ symtab_hdr->contents = (unsigned char *) isymbuf;
/* Fix the opcode. */
bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
@@ -2435,12 +2245,8 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
/* Note that we've changed the relocation contents, etc. */
elf_section_data (sec)->relocs = internal_relocs;
- free_relocs = NULL;
-
elf_section_data (sec)->this_hdr.contents = contents;
- free_contents = NULL;
-
- free_extsyms = NULL;
+ symtab_hdr->contents = (unsigned char *) isymbuf;
/* Fix the opcode. */
bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
@@ -2464,52 +2270,46 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
}
}
- if (free_relocs != NULL)
- free (free_relocs);
-
- if (free_contents != NULL)
+ if (isymbuf != NULL
+ && symtab_hdr->contents != (unsigned char *) isymbuf)
{
if (! link_info->keep_memory)
- free (free_contents);
+ free (isymbuf);
else
{
- /* Cache the section contents for elf_link_input_bfd. */
- elf_section_data (sec)->this_hdr.contents = contents;
+ /* Cache the symbols for elf_link_input_bfd. */
+ symtab_hdr->contents = (unsigned char *) isymbuf;
}
}
- if (shndx_buf != NULL)
- {
- shndx_hdr->contents = NULL;
- free (shndx_buf);
- }
-
- if (free_extsyms != NULL)
+ if (contents != NULL
+ && elf_section_data (sec)->this_hdr.contents != contents)
{
if (! link_info->keep_memory)
+ free (contents);
+ else
{
- symtab_hdr->contents = NULL;
- free (free_extsyms);
+ /* Cache the section contents for elf_link_input_bfd. */
+ elf_section_data (sec)->this_hdr.contents = contents;
}
}
+ if (internal_relocs != NULL
+ && elf_section_data (sec)->relocs != internal_relocs)
+ free (internal_relocs);
+
return true;
error_return:
- if (free_relocs != NULL)
- free (free_relocs);
- if (free_contents != NULL)
- free (free_contents);
- if (shndx_buf != NULL)
- {
- shndx_hdr->contents = NULL;
- free (shndx_buf);
- }
- if (free_extsyms != NULL)
- {
- symtab_hdr->contents = NULL;
- free (free_extsyms);
- }
+ if (isymbuf != NULL
+ && symtab_hdr->contents != (unsigned char *) isymbuf)
+ free (isymbuf);
+ if (contents != NULL
+ && elf_section_data (section)->this_hdr.contents != contents)
+ free (contents);
+ if (internal_relocs != NULL
+ && elf_section_data (section)->relocs != internal_relocs)
+ free (internal_relocs);
return false;
}
@@ -2624,22 +2424,16 @@ mn10300_elf_relax_delete_bytes (abfd, sec, addr, count)
int count;
{
Elf_Internal_Shdr *symtab_hdr;
- Elf_Internal_Shdr *shndx_hdr;
- Elf32_External_Sym *extsyms;
unsigned int sec_shndx;
bfd_byte *contents;
Elf_Internal_Rela *irel, *irelend;
Elf_Internal_Rela *irelalign;
bfd_vma toaddr;
- Elf32_External_Sym *esym, *esymend;
- Elf_External_Sym_Shndx *shndx;
+ Elf_Internal_Sym *isym, *isymend;
struct elf_link_hash_entry **sym_hashes;
struct elf_link_hash_entry **end_hashes;
unsigned int symcount;
- symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
- extsyms = (Elf32_External_Sym *) symtab_hdr->contents;
-
sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
contents = elf_section_data (sec)->this_hdr.contents;
@@ -2668,25 +2462,14 @@ mn10300_elf_relax_delete_bytes (abfd, sec, addr, count)
}
/* Adjust the local symbols defined in this section. */
- shndx_hdr = &elf_tdata (abfd)->symtab_shndx_hdr;
- shndx = (Elf_External_Sym_Shndx *) shndx_hdr->contents;
- esym = extsyms;
- esymend = esym + symtab_hdr->sh_info;
- for (; esym < esymend; esym++, shndx = (shndx ? shndx + 1 : NULL))
+ symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
+ isym = (Elf_Internal_Sym *) symtab_hdr->contents;
+ for (isymend = isym + symtab_hdr->sh_info; isym < isymend; isym++)
{
- Elf_Internal_Sym isym;
- Elf_External_Sym_Shndx dummy;
-
- bfd_elf32_swap_symbol_in (abfd, (const PTR) esym, (const PTR) shndx,
- &isym);
-
- if (isym.st_shndx == sec_shndx
- && isym.st_value > addr
- && isym.st_value < toaddr)
- {
- isym.st_value -= count;
- bfd_elf32_swap_symbol_out (abfd, &isym, (PTR) esym, (PTR) &dummy);
- }
+ if (isym->st_shndx == sec_shndx
+ && isym->st_value > addr
+ && isym->st_value < toaddr)
+ isym->st_value -= count;
}
/* Now adjust the global symbols defined in this section. */
@@ -2713,16 +2496,15 @@ mn10300_elf_relax_delete_bytes (abfd, sec, addr, count)
/* Return true if a symbol exists at the given address, else return
false. */
static boolean
-mn10300_elf_symbol_address_p (abfd, sec, addr)
+mn10300_elf_symbol_address_p (abfd, sec, isym, addr)
bfd *abfd;
asection *sec;
+ Elf_Internal_Sym *isym;
bfd_vma addr;
{
Elf_Internal_Shdr *symtab_hdr;
- Elf_Internal_Shdr *shndx_hdr;
unsigned int sec_shndx;
- Elf32_External_Sym *esym, *esymend;
- Elf_External_Sym_Shndx *shndx;
+ Elf_Internal_Sym *isymend;
struct elf_link_hash_entry **sym_hashes;
struct elf_link_hash_entry **end_hashes;
unsigned int symcount;
@@ -2731,19 +2513,10 @@ mn10300_elf_symbol_address_p (abfd, sec, addr)
/* Examine all the symbols. */
symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
- shndx_hdr = &elf_tdata (abfd)->symtab_shndx_hdr;
- shndx = (Elf_External_Sym_Shndx *) shndx_hdr->contents;
- esym = (Elf32_External_Sym *) symtab_hdr->contents;
- esymend = esym + symtab_hdr->sh_info;
- for (; esym < esymend; esym++, shndx = (shndx ? shndx + 1 : NULL))
+ for (isymend = isym + symtab_hdr->sh_info; isym < isymend; isym++)
{
- Elf_Internal_Sym isym;
-
- bfd_elf32_swap_symbol_in (abfd, (const PTR) esym, (const PTR) shndx,
- &isym);
-
- if (isym.st_shndx == sec_shndx
- && isym.st_value == addr)
+ if (isym->st_shndx == sec_shndx
+ && isym->st_value == addr)
return true;
}
@@ -2778,15 +2551,11 @@ mn10300_elf_get_relocated_section_contents (output_bfd, link_info, link_order,
asymbol **symbols;
{
Elf_Internal_Shdr *symtab_hdr;
- Elf_Internal_Shdr *shndx_hdr;
asection *input_section = link_order->u.indirect.section;
bfd *input_bfd = input_section->owner;
asection **sections = NULL;
Elf_Internal_Rela *internal_relocs = NULL;
- Elf32_External_Sym *external_syms = NULL;
- Elf_External_Sym_Shndx *shndx_buf = NULL;
- Elf_External_Sym_Shndx *shndx;
- Elf_Internal_Sym *internal_syms = NULL;
+ Elf_Internal_Sym *isymbuf = NULL;
/* We only need to handle the case of relaxing, or of having a
particular set of section contents, specially. */
@@ -2798,7 +2567,6 @@ mn10300_elf_get_relocated_section_contents (output_bfd, link_info, link_order,
symbols);
symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
- shndx_hdr = &elf_tdata (input_bfd)->symtab_shndx_hdr;
memcpy (data, elf_section_data (input_section)->this_hdr.contents,
(size_t) input_section->_raw_size);
@@ -2806,48 +2574,26 @@ mn10300_elf_get_relocated_section_contents (output_bfd, link_info, link_order,
if ((input_section->flags & SEC_RELOC) != 0
&& input_section->reloc_count > 0)
{
- Elf_Internal_Sym *isymp;
asection **secpp;
- Elf32_External_Sym *esym, *esymend;
+ Elf_Internal_Sym *isym, *isymend;
bfd_size_type amt;
- if (symtab_hdr->contents != NULL)
- external_syms = (Elf32_External_Sym *) symtab_hdr->contents;
- else if (symtab_hdr->sh_info != 0)
- {
- amt = symtab_hdr->sh_info;
- amt *= sizeof (Elf32_External_Sym);
- external_syms = (Elf32_External_Sym *) bfd_malloc (amt);
- if (external_syms == NULL)
- goto error_return;
- if (bfd_seek (input_bfd, symtab_hdr->sh_offset, SEEK_SET) != 0
- || bfd_bread ((PTR) external_syms, amt, input_bfd) != amt)
- goto error_return;
- }
-
- if (symtab_hdr->sh_info != 0 && 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)
- goto error_return;
- if (bfd_seek (input_bfd, shndx_hdr->sh_offset, SEEK_SET) != 0
- || bfd_bread ((PTR) shndx_buf, amt, input_bfd) != amt)
- goto error_return;
- }
-
internal_relocs = (_bfd_elf32_link_read_relocs
(input_bfd, input_section, (PTR) NULL,
(Elf_Internal_Rela *) NULL, false));
if (internal_relocs == NULL)
goto error_return;
- amt = symtab_hdr->sh_info;
- amt *= sizeof (Elf_Internal_Sym);
- internal_syms = (Elf_Internal_Sym *) bfd_malloc (amt);
- if (internal_syms == NULL && amt != 0)
- goto error_return;
+ if (symtab_hdr->sh_info != 0)
+ {
+ isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
+ if (isymbuf == NULL)
+ isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ symtab_hdr->sh_info, 0,
+ NULL, NULL, NULL);
+ if (isymbuf == NULL)
+ goto error_return;
+ }
amt = symtab_hdr->sh_info;
amt *= sizeof (asection *);
@@ -2855,41 +2601,32 @@ mn10300_elf_get_relocated_section_contents (output_bfd, link_info, link_order,
if (sections == NULL && amt != 0)
goto error_return;
- for (isymp = internal_syms, secpp = sections, shndx = shndx_buf,
- esym = external_syms, esymend = esym + symtab_hdr->sh_info;
- esym < esymend;
- ++esym, ++isymp, ++secpp, shndx = (shndx ? shndx + 1 : NULL))
+ isymend = isymbuf + symtab_hdr->sh_info;
+ for (isym = isymbuf, secpp = sections; isym < isymend; ++isym, ++secpp)
{
asection *isec;
- bfd_elf32_swap_symbol_in (input_bfd, (const PTR) esym,
- (const PTR) shndx, isymp);
-
- if (isymp->st_shndx == SHN_UNDEF)
+ if (isym->st_shndx == SHN_UNDEF)
isec = bfd_und_section_ptr;
- else if (isymp->st_shndx == SHN_ABS)
+ else if (isym->st_shndx == SHN_ABS)
isec = bfd_abs_section_ptr;
- else if (isymp->st_shndx == SHN_COMMON)
+ else if (isym->st_shndx == SHN_COMMON)
isec = bfd_com_section_ptr;
else
- isec = bfd_section_from_elf_index (input_bfd, isymp->st_shndx);
+ isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
*secpp = isec;
}
if (! mn10300_elf_relocate_section (output_bfd, link_info, input_bfd,
input_section, data, internal_relocs,
- internal_syms, sections))
+ isymbuf, sections))
goto error_return;
if (sections != NULL)
free (sections);
- if (internal_syms != NULL)
- free (internal_syms);
- if (shndx_buf != NULL)
- free (shndx_buf);
- if (external_syms != NULL && symtab_hdr->contents == NULL)
- free (external_syms);
+ if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
+ free (isymbuf);
if (internal_relocs != elf_section_data (input_section)->relocs)
free (internal_relocs);
}
@@ -2897,17 +2634,13 @@ mn10300_elf_get_relocated_section_contents (output_bfd, link_info, link_order,
return data;
error_return:
+ if (sections != NULL)
+ free (sections);
+ if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
+ free (isymbuf);
if (internal_relocs != NULL
&& internal_relocs != elf_section_data (input_section)->relocs)
free (internal_relocs);
- if (shndx_buf != NULL)
- free (shndx_buf);
- if (external_syms != NULL && symtab_hdr->contents == NULL)
- free (external_syms);
- if (internal_syms != NULL)
- free (internal_syms);
- if (sections != NULL)
- free (sections);
return NULL;
}