[PATCH v1 5/7] aarch64: clean up subsection used to initialize the frozen attributes set
Matthieu Longo
matthieu.longo@arm.com
Tue Feb 3 10:00:46 GMT 2026
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 0x56bec58a661c in xstrdup ../../libiberty/xstrdup.c:34
#3 0x56bec559cc8d in bfd_elf64_aarch64_set_options ../../bfd/elfnn-aarch64.c:5046
#4 0x56bec54d839a in aarch64_elf_create_output_section_statements <build-dir>/ld/eaarch64linux.c:358
#5 0x56bec54c2b04 in ldemul_create_output_section_statements ../../ld/ldemul.c:130
#6 0x56bec549fa50 in lang_process ../../ld/ldlang.c:8367
#7 0x56bec54b2b2c in main ../../ld/ldmain.c:958
---
bfd/elfnn-aarch64.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index 08077fb74f8..d50f3bcbf48 100644
--- a/bfd/elfnn-aarch64.c
+++ b/bfd/elfnn-aarch64.c
@@ -5125,6 +5125,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;
--
2.52.0
More information about the Binutils
mailing list