[RFC 4/6] aarch64 gas: Free hash tables before exit
Matthieu Longo
matthieu.longo@arm.com
Tue Mar 3 16:45:03 GMT 2026
On 03/03/2026 12:40, Alice Carlotti wrote:
> 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)
Alan has merged [1] which introduced BFD_ASAN.
I think it would make sense to add the #ifdef BFD_ASAN as a part of this patch.
Otherwise, ok with the change.
[1]: https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=f1a664fa55a9ec301b5139788ee033005dd31db6;hp=1e6ad73d0827a246023ba17ca61b35649e3982bb
Matthieu
More information about the Binutils
mailing list