[binutils-gdb] aarch64: clean up subsection used to initialize the frozen attributes set

Matthieu Longo mlongo@sourceware.org
Fri Feb 6 14:12:24 GMT 2026


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=49a621b2d3a01a2f998de9014ef14c1e61a9d5b0

commit 49a621b2d3a01a2f998de9014ef14c1e61a9d5b0
Author: Matthieu Longo <matthieu.longo@arm.com>
Date:   Mon Feb 2 14:14:30 2026 +0000

    aarch64: clean up subsection used to initialize the frozen attributes set
    
    On AArch64, some attributes are set globally when software protections
    options such as BTI, PAC or GCS are enabled. These attributes are then
    used as the frozen set during the attributes merge.
    
    In the current implementation of bfd_elfNN_aarch64_set_options, the
    subsection is created before linker options are examined. If relevant
    options are provided, the subsection is appended to the frozen set;
    otherwise, it is left unused and leaked. This issue was detected by
    LeakSanitizer (see the stack trace below).
    
    This patch fixes the memory leak by handling the case where no attributes
    are recorded. An 'else' is added to free the empty subsection when it is
    not added to the frozen set.
    
    ==ERROR: LeakSanitizer: detected memory leaks
    Indirect leak of 23 byte(s) in 1 object(s) allocated from:
        #2 xstrdup ../../libiberty/xstrdup.c:34
        #3 bfd_elf64_aarch64_set_options ../../bfd/elfnn-aarch64.c:5046
        #4 aarch64_elf_create_output_section_statements <build-dir>/ld/eaarch64linux.c:358
        #5 ldemul_create_output_section_statements ../../ld/ldemul.c:130
        #6 lang_process ../../ld/ldlang.c:8367
        #7 main ../../ld/ldmain.c:958

Diff:
---
 bfd/elfnn-aarch64.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index 1ba7dd393e6..de68f24e86d 100644
--- a/bfd/elfnn-aarch64.c
+++ b/bfd/elfnn-aarch64.c
@@ -5123,6 +5123,8 @@ bfd_elfNN_aarch64_set_options (struct bfd *output_bfd,
   if (attrs_subsection->size > 0)
     LINKED_LIST_APPEND (obj_attr_subsection_v2_t)
       (&elf_obj_attr_subsections (output_bfd), attrs_subsection);
+  else
+    _bfd_elf_obj_attr_subsection_v2_free (attrs_subsection);
 
   elf_aarch64_tdata (output_bfd)->gnu_property_aarch64_feature_1_and
     = gnu_property_aarch64_feature_1_and;


More information about the Binutils-cvs mailing list