]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
aarch64: clean up subsection used to initialize the frozen attributes set
authorMatthieu Longo <matthieu.longo@arm.com>
Mon, 2 Feb 2026 14:14:30 +0000 (14:14 +0000)
committerMatthieu Longo <matthieu.longo@arm.com>
Fri, 6 Feb 2026 14:12:04 +0000 (14:12 +0000)
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

bfd/elfnn-aarch64.c

index 1ba7dd393e68e454819360726cd6b30e07031e2f..de68f24e86d0c8efba67a52f8250888ed0b4d04a 100644 (file)
@@ -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;