aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2025-01-15 23:12:52 +1030
committerAlan Modra <amodra@gmail.com>2025-01-16 09:31:19 +1030
commit6adf00f8a7e390a83b0885d56405f737f1b31dca (patch)
tree64422f209423e60a3458191ba5b310e6b3d43678
parentbb9ea706c5f845b6e245029a17f0ab8fc6fde739 (diff)
downloadgdb-6adf00f8a7e390a83b0885d56405f737f1b31dca.zip
gdb-6adf00f8a7e390a83b0885d56405f737f1b31dca.tar.gz
gdb-6adf00f8a7e390a83b0885d56405f737f1b31dca.tar.bz2
x86 relr memory leaks
This fixes some x86 memory leaks. I think it would be possible to free the relr data in _bfd_elf_x86_finish_relative_relocs if we wanted to reclaim some memory earlier, but for tidying after errors we likely would need to free in the hash_table_free function anyway. _bfd_x86_elf_link_relax_section is called via bfd_relax_section, ie. whenever relaxation is enabled. This is a waste of time if dt_relr relocs are not enabled since the function is there only to handle relr. * elfxx-x86.c (elf_x86_link_hash_table_free): Free relr data. (_bfd_x86_elf_link_relax_section): Return early if !info->enable_dt_relr. Do set "again" false before early returns.
-rw-r--r--bfd/elfxx-x86.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
index 7c164e9..cd47575 100644
--- a/bfd/elfxx-x86.c
+++ b/bfd/elfxx-x86.c
@@ -693,6 +693,9 @@ elf_x86_link_hash_table_free (bfd *obfd)
struct elf_x86_link_hash_table *htab
= (struct elf_x86_link_hash_table *) obfd->link.hash;
+ free (htab->dt_relr_bitmap.u.elf64);
+ free (htab->unaligned_relative_reloc.data);
+ free (htab->relative_reloc.data);
if (htab->loc_hash_table)
htab_delete (htab->loc_hash_table);
if (htab->loc_hash_memory)
@@ -1089,13 +1092,16 @@ _bfd_x86_elf_link_relax_section (bfd *abfd ATTRIBUTE_UNUSED,
bool return_status = false;
bool keep_symbuf = false;
- if (bfd_link_relocatable (info))
- return true;
-
/* Assume we're not going to change any sizes, and we'll only need
one pass. */
*again = false;
+ if (bfd_link_relocatable (info))
+ return true;
+
+ if (!info->enable_dt_relr)
+ return true;
+
bed = get_elf_backend_data (abfd);
htab = elf_x86_hash_table (info, bed->target_id);
if (htab == NULL)