[AArch64] Factor out common behaviour between elf_aarch64_create_or_find_stub_sec and elfNN_aarch64_add_stub

This commit is contained in:
Marcus Shawcroft 2015-02-28 00:10:21 +00:00
parent 2144188dcf
commit ef85752125
2 changed files with 42 additions and 52 deletions

View File

@ -1,3 +1,13 @@
2015-03-23 Marcus Shawcroft <marcus.shawcroft@arm.com>
* elfnn-aarch64.c (_bfd_aarch64_create_or_find_stub_sec): Rename
from elf_aarch64_create_or_find_stub_sec.
(_bfd_aarch64_add_stub_entry_in_group): Rename from
elfNN_aarch64_add_stub. Call
_bfd_aarch64_create_or_find_stub_sec.
(elfNN_aarch64_size_stubs, elfNN_aarch64_size_stubs): Call
_bfd_aarch64_add_stub_entry_in_group.
2015-03-23 Marcus Shawcroft <marcus.shawcroft@arm.com>
* elfnn-aarch64.c (erratum_835769_scan) Add comment. Reverse

View File

@ -2326,20 +2326,21 @@ elfNN_aarch64_get_stub_entry (const asection *input_section,
return stub_entry;
}
/* Add a new stub entry to the stub hash. Not all fields of the new
stub entry are initialised. */
static struct elf_aarch64_stub_hash_entry *
elfNN_aarch64_add_stub (const char *stub_name,
asection *section,
struct elf_aarch64_link_hash_table *htab)
/* Find or create a stub section in the stub group for an input
section. */
static asection *
_bfd_aarch64_create_or_find_stub_sec (asection *section,
struct elf_aarch64_link_hash_table *htab)
{
asection *link_sec;
asection *stub_sec;
struct elf_aarch64_stub_hash_entry *stub_entry;
link_sec = htab->stub_group[section->id].link_sec;
BFD_ASSERT (link_sec != NULL);
stub_sec = htab->stub_group[section->id].stub_sec;
if (stub_sec == NULL)
{
stub_sec = htab->stub_group[link_sec->id].stub_sec;
@ -2358,6 +2359,7 @@ elfNN_aarch64_add_stub (const char *stub_name,
memcpy (s_name, link_sec->name, namelen);
memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
stub_sec = (*htab->add_stub_section) (s_name, link_sec);
if (stub_sec == NULL)
return NULL;
htab->stub_group[link_sec->id].stub_sec = stub_sec;
@ -2365,6 +2367,26 @@ elfNN_aarch64_add_stub (const char *stub_name,
htab->stub_group[section->id].stub_sec = stub_sec;
}
return stub_sec;
}
/* Add a new stub entry in the stub group associated with an input
section to the stub hash. Not all fields of the new stub entry are
initialised. */
static struct elf_aarch64_stub_hash_entry *
_bfd_aarch64_add_stub_entry_in_group (const char *stub_name,
asection *section,
struct elf_aarch64_link_hash_table *htab)
{
asection *link_sec;
asection *stub_sec;
struct elf_aarch64_stub_hash_entry *stub_entry;
link_sec = htab->stub_group[section->id].link_sec;
stub_sec = _bfd_aarch64_create_or_find_stub_sec (section, htab);
/* Enter this entry into the linker stub hash table. */
stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
TRUE, FALSE);
@ -3087,48 +3109,6 @@ erratum_835769_scan (bfd *input_bfd,
return TRUE;
}
/* Find or create a stub section. */
static asection *
elf_aarch64_create_or_find_stub_sec (asection *section,
struct elf_aarch64_link_hash_table *htab)
{
asection *link_sec;
asection *stub_sec;
link_sec = htab->stub_group[section->id].link_sec;
BFD_ASSERT (link_sec != NULL);
stub_sec = htab->stub_group[section->id].stub_sec;
if (stub_sec == NULL)
{
stub_sec = htab->stub_group[link_sec->id].stub_sec;
if (stub_sec == NULL)
{
size_t namelen;
bfd_size_type len;
char *s_name;
namelen = strlen (link_sec->name);
len = namelen + sizeof (STUB_SUFFIX);
s_name = (char *) bfd_alloc (htab->stub_bfd, len);
if (s_name == NULL)
return NULL;
memcpy (s_name, link_sec->name, namelen);
memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
stub_sec = (*htab->add_stub_section) (s_name, link_sec);
if (stub_sec == NULL)
return NULL;
htab->stub_group[link_sec->id].stub_sec = stub_sec;
}
htab->stub_group[section->id].stub_sec = stub_sec;
}
return stub_sec;
}
/* Determine and set the size of the stub section for a final link.
The basic idea here is to examine all the relocations looking for
@ -3413,8 +3393,8 @@ elfNN_aarch64_size_stubs (bfd *output_bfd,
continue;
}
stub_entry = elfNN_aarch64_add_stub (stub_name, section,
htab);
stub_entry = _bfd_aarch64_add_stub_entry_in_group
(stub_name, section, htab);
if (stub_entry == NULL)
{
free (stub_name);
@ -3481,7 +3461,7 @@ elfNN_aarch64_size_stubs (bfd *output_bfd,
if (htab->fix_erratum_835769)
for (i = 0; i < num_erratum_835769_fixes; i++)
{
stub_sec = elf_aarch64_create_or_find_stub_sec
stub_sec = _bfd_aarch64_create_or_find_stub_sec
(erratum_835769_fixes[i].section, htab);
if (stub_sec == NULL)