public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* x86 relr memory leaks
@ 2025-01-15 22:56 Alan Modra
  2025-01-15 23:01 ` H.J. Lu
  0 siblings, 1 reply; 10+ messages in thread
From: Alan Modra @ 2025-01-15 22:56 UTC (permalink / raw)
  To: binutils; +Cc: Jan Beulich, H.J. Lu

From 2af61a5d22c550ac951fbbd2a606ae689657066a Mon Sep 17 00:00:00 2001
From: Alan Modra <amodra@gmail.com>
Date: Wed, 15 Jan 2025 23:12:52 +1030
Subject: 

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.

Since I may have missed something with the relax_section change,
OK to install?

	* 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.

diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
index 7c164e9c131..cd47575f589 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)

-- 
Alan Modra

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2025-02-11  7:09 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-15 22:56 x86 relr memory leaks Alan Modra
2025-01-15 23:01 ` H.J. Lu
2025-01-15 23:22   ` Alan Modra
2025-01-21 21:53     ` Alan Modra
2025-01-22 15:19       ` Nick Alcock
2025-01-22 15:24         ` Nick Alcock
2025-01-22 23:49           ` Alan Modra
2025-01-28 18:23             ` Nick Alcock
2025-02-10 15:30               ` Nick Alcock
2025-02-11  7:09                 ` Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).