[RFC 4/6] aarch64 gas: Free hash tables before exit
Alice Carlotti
alice.carlotti@arm.com
Tue Mar 3 12:40:48 GMT 2026
There are several hash tables allocated at startup in md_begin(), which
are currently leaked when gas exits. This isn't directly harmful, but
it adds clutter to LeakSanitizer reports.
Some of the hash table keys and values are also dynamically allocated;
these will be addressed in subsequent commits.
Co-Authored-By: Matthieu Longo <matthieu.longo@arm.com>
diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c
index 7af05abbb5c777de1e7e3fa9e9f910a9719a152e..b580815bdfa20f358c818925b44f8bb2e2adba94 100644
--- a/gas/config/tc-aarch64.c
+++ b/gas/config/tc-aarch64.c
@@ -10721,6 +10721,32 @@ md_begin (void)
#endif
}
+void
+aarch64_md_end (void)
+{
+ /* Deallocate all the hash tables. */
+ htab_delete (aarch64_ops_hsh);
+ htab_delete (aarch64_sys_regs_hsh);
+ htab_delete (aarch64_pstatefield_hsh);
+ htab_delete (aarch64_sys_regs_ic_hsh);
+ htab_delete (aarch64_sys_regs_dc_hsh);
+ htab_delete (aarch64_sys_regs_at_hsh);
+ htab_delete (aarch64_sys_regs_tlbi_hsh);
+ htab_delete (aarch64_sys_regs_plbi_hsh);
+ htab_delete (aarch64_sys_regs_mlbi_hsh);
+ htab_delete (aarch64_sys_regs_sr_hsh);
+ htab_delete (aarch64_reg_hsh);
+ htab_delete (aarch64_nzcv_hsh);
+ htab_delete (aarch64_sys_ins_gic_hsh);
+ htab_delete (aarch64_sys_ins_gicr_hsh);
+ htab_delete (aarch64_sys_ins_gsb_hsh);
+ htab_delete (aarch64_cond_hsh);
+ htab_delete (aarch64_shift_hsh);
+ htab_delete (aarch64_barrier_opt_hsh);
+ htab_delete (aarch64_pldop_hsh);
+ htab_delete (aarch64_hint_opt_hsh);
+}
+
/* Command line processing. */
const char md_shortopts[] = "m:";
diff --git a/gas/config/tc-aarch64.h b/gas/config/tc-aarch64.h
index d1fb4c9058b882ed2f3f60607a1b60a0029cd053..b89df2bc4259388d84d16203dc9a29d2444a360c 100644
--- a/gas/config/tc-aarch64.h
+++ b/gas/config/tc-aarch64.h
@@ -73,6 +73,9 @@ struct aarch64_fix
#define md_cleanup() aarch64_cleanup ()
+extern void aarch64_md_end (void);
+#define md_end aarch64_md_end
+
#define md_start_line_hook() aarch64_start_line_hook ()
#define tc_frob_label(S) aarch64_frob_label (S)
More information about the Binutils
mailing list