x86 relr memory leaks

Nick Alcock nick.alcock@oracle.com
Mon Feb 10 15:30:34 GMT 2025


On 28 Jan 2025, Nick Alcock uttered the following:

> On 22 Jan 2025, Alan Modra verbalised:
>
>> On Wed, Jan 22, 2025 at 03:24:16PM +0000, Nick Alcock wrote:
>>> On 22 Jan 2025, Nick Alcock spake thusly:
>>> 
>>> > On 21 Jan 2025, Alan Modra told this:
>>> >
>>> >> On Thu, Jan 16, 2025 at 09:52:23AM +1030, Alan Modra wrote:
>>> >>> In fact with another 20 or so patches I have the x86_64 and
>>> >>> powerpc ld testsuites passing without seeing any memory leaks, except
>>> >>> for some in the gcc plugin.
>>> >>
>>> >> Well that claim was premature.  After commit bea261b937df which runs
>>> >> more of the ld tests I see many more leaks.  libctf leaks quite a bit
>>> >> as shown by ld/testsuite/ld-ctf tests.
>>> >
>>> > Could you send me any more info on this? I run routine leak checks via
>>
>> Sent privately.
>
> Thank you! I'll have a look. I can feel my test matrix expanding
> already...

Fix trivial, in the end (see attached). Will throw it at the trybots and
then push soon, but I'm going to use it as an excuse to revive and
improve my testing machinery so there might be another delay while I
hack at that :)

(It turns out I am already testing with the sanitizer flags in question.
Not sure why the leaks didn't show up...)

>From f21a2f94c8587dbf5b86c951c4afcecdfdb9a653 Mon Sep 17 00:00:00 2001
From: Nick Alcock <nick.alcock@oracle.com>
Date: Mon, 10 Feb 2025 14:40:00 +0000
Subject: [PATCH] readelf, objdump: fix ctf dict leak

ctf_archive_next returns an opened dict, which must be closed by the caller.

Thanks to Alan Modra for spotting this.

binutils/
	* objdump.c (dump_ctf): Close dict.
	* readelf.c (dump_section_as_ctf): Likewise.
---
 binutils/objdump.c | 5 ++++-
 binutils/readelf.c | 5 ++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/binutils/objdump.c b/binutils/objdump.c
index 4980929d6ab..9b5b8faf397 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -4939,7 +4939,10 @@ dump_ctf (bfd *abfd, const char *sect_name, const char *parent_name,
   printf (_("Contents of CTF section %s:\n"), sanitize_string (sect_name));
 
   while ((fp = ctf_archive_next (ctfa, &i, &name, 0, &err)) != NULL)
-    dump_ctf_archive_member (fp, name, parent, member++);
+    {
+      dump_ctf_archive_member (fp, name, parent, member++);
+      ctf_dict_close (fp);
+    }
   if (err != ECTF_NEXT_END)
     {
       dump_ctf_errs (NULL);
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 73163e0ee21..3c3acbc632a 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -17037,7 +17037,10 @@ dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata)
 	    printable_section_name (filedata, section));
 
  while ((fp = ctf_archive_next (ctfa, &i, &name, 0, &err)) != NULL)
-    dump_ctf_archive_member (fp, name, parent, member++);
+   {
+     dump_ctf_archive_member (fp, name, parent, member++);
+     ctf_dict_close (fp);
+   }
  if (err != ECTF_NEXT_END)
    {
      dump_ctf_errs (NULL);
-- 
2.48.1.283.g18c60a128c



More information about the Binutils mailing list