[PATCH v1 1/4] aarch64 gas: free hash tables in md_begin() to avoid memory leaks

Alan Modra amodra@gmail.com
Mon Mar 2 23:54:00 GMT 2026


On Mon, Mar 02, 2026 at 01:10:30PM +0000, Richard Earnshaw (foss) wrote:
> On 24/02/2026 16:39, Jan Beulich wrote:
> > On 24.02.2026 17:26, Matthieu Longo wrote:
> >> The AArch64 GAS backend allocates several hash tables in md_begin(). All of
> >> these hash tables use strings as keys; some of those strings are dynamically
> >> allocated, while others are statically allocated. None of these hash tables
> >> have ever been deallocated in aarch64_md_end(), resulting in memory leaks
> >> that spam LeakSanitizer reports.
> >>
> >> The first part of the fix deallocates the hash tables in aarch64_md_end().
> > 
> > By how much does this increase assembly time for small or medium size input?
> > 
> > Jan
> 
> Can't we just wrap this code inside an ifdef so that it's only triggered when the sanitizers are enabled?  It's all pretty pointless given that we're going to exit anyway.

I'll add this to bfd.h so code can use "if (BFD_ASAN)".  This should
work for both gcc and clang.

diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h
index 751f0ad3cbb..8650fa12d82 100644
--- a/bfd/bfd-in.h
+++ b/bfd/bfd-in.h
@@ -151,6 +151,16 @@ struct orl;
    ? (((bfd_vma) (this) + ((boundary) - 1)) & ~ (bfd_vma) ((boundary)-1)) \
    : ~ (bfd_vma) 0)
 
+/* Detect whether we are compiling with -fsanitize=address.  */
+#ifndef BFD_ASAN
+# if ((defined (__SANITIZE_ADDRESS__) && __SANITIZE_ADDRESS__)		\
+      || (defined __has_feature && __has_feature (address_sanitizer)))
+#  define BFD_ASAN 1
+# else
+#  define BFD_ASAN 0
+# endif
+#endif
+
 /* Return TRUE if the start of STR matches PREFIX, FALSE otherwise.  */
 
 static inline bool

-- 
Alan Modra


More information about the Binutils mailing list