[PATCH 2/6] aarch64: Fix .unreq of predefined aliases
Alice Carlotti
alice.carlotti@arm.com
Tue Mar 3 12:38:44 GMT 2026
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
More information about the Binutils
mailing list