diff options
author | Oleg Tolmatcev <oleg.tolmatcev@gmail.com> | 2023-05-16 14:25:32 +0100 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2023-05-16 14:25:32 +0100 |
commit | 0e759f232b6def277d4ae3f2d8bccfe6e34d6034 (patch) | |
tree | ecf626fa9cad39ed53b9582ad5143f68c47491ed /bfd/coff-x86_64.c | |
parent | 73eff1cbd3e35f9f3ea3f69d145aa74c57043953 (diff) | |
download | binutils-gdb-0e759f232b6def277d4ae3f2d8bccfe6e34d6034.tar.gz |
Add section caches to coff_data_type
* libcoff-in.h (struct coff_tdata): Add section_by_index and section_by_target_index hash tables.
* libcoff.h: Regenerate.
* coffcode.h (htab_hash_section_index): New function. (htab_eq_section_index): New function. (htab_hash_section_target_index): New function. (htab_eq_section_target_index): New function. (coff_mkobject_hool): Create the hash tables.
* peicode.h: Add the same new functions. (pe_mkobject_hook): Create the hash tables.
* coff-x86_64.c (coff_amd64_rtype_to_howto): Use the new tables to speed up lookups.
* coffgen.c (coff_section_from_bfd_index): Likewise. (_bfd_coff_close_and_cleanup): Delete the hash tables.
Diffstat (limited to 'bfd/coff-x86_64.c')
-rw-r--r-- | bfd/coff-x86_64.c | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/bfd/coff-x86_64.c b/bfd/coff-x86_64.c index 822504a339b..1f8c8d515c4 100644 --- a/bfd/coff-x86_64.c +++ b/bfd/coff-x86_64.c @@ -745,22 +745,37 @@ coff_amd64_rtype_to_howto (bfd *abfd ATTRIBUTE_UNUSED, if (rel->r_type == R_AMD64_SECREL) { - bfd_vma osect_vma; + bfd_vma osect_vma = 0; - if (h && (h->root.type == bfd_link_hash_defined - || h->root.type == bfd_link_hash_defweak)) + if (h != NULL + && (h->root.type == bfd_link_hash_defined + || h->root.type == bfd_link_hash_defweak)) osect_vma = h->root.u.def.section->output_section->vma; else { + htab_t table = coff_data (abfd)->section_by_index; asection *s; - int i; - /* Sigh, the only way to get the section to offset against - is to find it the hard way. */ - for (s = abfd->sections, i = 1; i < sym->n_scnum; i++) - s = s->next; + if (htab_elements (table) == 0) + { + /* Sigh - if we do not have a section index then the only way + to get the section to offset against is to find it the hard + way. */ + for (s = abfd->sections; s != NULL; s = s->next) + { + void ** slot = htab_find_slot (table, s, INSERT); + + if (slot != NULL) + *slot = s; + } + } + + struct bfd_section needle; - osect_vma = s->output_section->vma; + needle.index = sym->n_scnum - 1; + s = htab_find (table, &needle); + if (s != NULL) + osect_vma = s->output_section->vma; } *addendp -= osect_vma; |