[PATCH 2/6] aarch64: Fix .unreq of predefined aliases

Alice Carlotti alice.carlotti@arm.com
Tue Mar 3 17:41:07 GMT 2026


On Tue, Mar 03, 2026 at 04:39:07PM +0000, Matthieu Longo wrote:
> On 03/03/2026 12:38, Alice Carlotti wrote:
> > Attempting to free a static reg_entry is invalid, so use
> > insert_reg_alias to create a dynamic copy of the content.
> > 
> > 
> > diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c
> > index 5e92007007310b9f12f1f0051890839216666c17..7af05abbb5c777de1e7e3fa9e9f910a9719a152e 100644
> > --- a/gas/config/tc-aarch64.c
> > +++ b/gas/config/tc-aarch64.c
> > @@ -1599,7 +1599,7 @@ parse_simd_vector_with_bit_index (char **ccp, struct vector_type_el *typeinfo)
> >   /* Directives: register aliases.  */
> >   static reg_entry *
> > -insert_reg_alias (char *str, int number, aarch64_reg_type type)
> > +insert_reg_alias (const char *str, int number, aarch64_reg_type type)
> >   {
> >     reg_entry *new;
> >     const char *name;
> > @@ -10589,8 +10589,17 @@ md_begin (void)
> >   			aarch64_sys_regs_sr + i);
> >     for (i = 0; i < ARRAY_SIZE (reg_names); i++)
> > -    checked_hash_insert (aarch64_reg_hsh, reg_names[i].name,
> > -			 reg_names + i);
> > +    {
> > +      if (reg_names[i].builtin)
> > +	checked_hash_insert (aarch64_reg_hsh, reg_names[i].name,
> > +			     reg_names + i);
> > +      else
> > +	/* Aliases need to be safely removable, so create a copy of
> > +	   the reg_entry data.  */
> > +	insert_reg_alias (reg_names[i].name, reg_names[i].number,
> > +			  reg_names[i].type);
> > +    }
> > +
> >     for (i = 0; i < ARRAY_SIZE (nzcv_names); i++)
> >       checked_hash_insert (aarch64_nzcv_hsh, nzcv_names[i].template,
> > diff --git a/gas/testsuite/gas/aarch64/register_aliases.s b/gas/testsuite/gas/aarch64/register_aliases.s
> > index 856be5699ce434e41d52923020dcbc615208f983..10ee6d189170f6692cfe8e5f2c725fe138c72827 100644
> > --- a/gas/testsuite/gas/aarch64/register_aliases.s
> > +++ b/gas/testsuite/gas/aarch64/register_aliases.s
> > @@ -10,3 +10,9 @@
> >   	str 	IP0, [fp]
> >   	ldr	IP1, [fp]
> >   	str	zero, [x0]
> > +
> > +	# Removing builtin register aliases should not segfault.
> > +	.unreq lr
> > +	.unreq fp
> > +	.unreq ip0
> > +	.unreq ip1
> 
> I agree on the code fix, but not the testing.
> Please look at patch 4 from my patch series that has more complete tests.

Your changes to register_aliases_invalid.* look unrelated to this bug fix, but
seem ok as a standalone test coverage improvement.  I recommend that you submit
this a separate patch yourself.

The other thing you test is .unreq of a non-predefined alias.  This is
currently already tested in pr29519.*, but I'll add an instance of this to my
patch as well.

Alice

> 
> Matthieu


More information about the Binutils mailing list