From: Matthieu Longo Date: Mon, 2 Feb 2026 14:14:30 +0000 (+0000) Subject: aarch64: clean up subsection used to initialize the frozen attributes set X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=49a621b2d3a01a2f998de9014ef14c1e61a9d5b0;p=thirdparty%2Fbinutils-gdb.git 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 /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 --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;