[PATCH 1/2] gas: Keep the ISA bit for a local alias of a weak microMIPS function
Longjun Luo
luolongjuna@gmail.com
Tue Nov 24 11:51:35 GMT 2026
A local alias of a weak microMIPS function can have its ISA mode
recorded only in st_other. Reducing a relocation against the alias
to a section symbol loses that mode, so a call through the alias can
trigger an illegal instruction exception.
When the symbol value does not carry the ISA mode, we must keep the
symbol relocation.
Signed-off-by: Longjun Luo <luolongjuna@gmail.com>
---
gas/config/tc-mips.c | 5 +++-
.../ld-mips-elf/micromips-local-alias-call.d | 13 +++++++++++
.../ld-mips-elf/micromips-local-alias.d | 8 +++++++
.../ld-mips-elf/micromips-local-alias.s | 23 +++++++++++++++++++
ld/testsuite/ld-mips-elf/mips-elf.exp | 4 +++-
5 files changed, 51 insertions(+), 2 deletions(-)
create mode 100644 ld/testsuite/ld-mips-elf/micromips-local-alias-call.d
create mode 100644 ld/testsuite/ld-mips-elf/micromips-local-alias.d
create mode 100644 ld/testsuite/ld-mips-elf/micromips-local-alias.s
diff --git a/gas/config/tc-mips.c b/gas/config/tc-mips.c
index 1fa8b49f805..6733bd810f1 100644
--- a/gas/config/tc-mips.c
+++ b/gas/config/tc-mips.c
@@ -18701,7 +18701,10 @@ mips_fix_adjustable (fixS *fixp)
&& (ELF_ST_IS_MIPS16 (S_GET_OTHER (fixp->fx_addsy))
|| (ELF_ST_IS_MICROMIPS (S_GET_OTHER (fixp->fx_addsy))
&& (jmp_reloc_p (fixp->fx_r_type)
- || b_reloc_p (fixp->fx_r_type)))
+ || b_reloc_p (fixp->fx_r_type)
+ /* Since only st_other records the ISA mode here, we cannot
+ reduce the relocation to a section symbol. */
+ || (S_GET_VALUE (fixp->fx_addsy) & 1) == 0))
|| *symbol_get_tc (fixp->fx_addsy)))
return 0;
diff --git a/ld/testsuite/ld-mips-elf/micromips-local-alias-call.d b/ld/testsuite/ld-mips-elf/micromips-local-alias-call.d
new file mode 100644
index 00000000000..cd1fee4e8ed
--- /dev/null
+++ b/ld/testsuite/ld-mips-elf/micromips-local-alias-call.d
@@ -0,0 +1,13 @@
+#name: Indirect call through a local microMIPS function alias
+#source: micromips-local-alias.s
+#as: -EB -mips32r2 -mmicromips -non_shared
+#ld: -EB -Ttext=0x1000 -e _start
+#objdump: -d
+
+# la must load 0x1001 so that jalr enters f in microMIPS mode.
+#...
+[0-9a-f]+ <_start>:
+.* lui a0,0x0
+.* addiu a0,a0,4097
+.* jalr a0
+#pass
diff --git a/ld/testsuite/ld-mips-elf/micromips-local-alias.d b/ld/testsuite/ld-mips-elf/micromips-local-alias.d
new file mode 100644
index 00000000000..c36b9020017
--- /dev/null
+++ b/ld/testsuite/ld-mips-elf/micromips-local-alias.d
@@ -0,0 +1,8 @@
+#name: Address of a local microMIPS function alias
+#as: -EB -mips32r2 -mmicromips -non_shared
+#ld: -EB -Ttext=0x1000 -e f
+#readelf: -x .data
+
+#...
+ 0x[0-9a-f]+ 00001001 00001001 .*
+#pass
diff --git a/ld/testsuite/ld-mips-elf/micromips-local-alias.s b/ld/testsuite/ld-mips-elf/micromips-local-alias.s
new file mode 100644
index 00000000000..d32414371b4
--- /dev/null
+++ b/ld/testsuite/ld-mips-elf/micromips-local-alias.s
@@ -0,0 +1,23 @@
+ .text
+ .set noreorder
+ .weak f
+ .type f, @function
+f:
+ jr $31
+ nop
+ .size f, .-f
+
+ .local alias
+ .set alias, f
+
+ .globl _start
+ .type _start, @function
+_start:
+ la $4, alias
+ jalr $4
+ nop
+ break
+ .size _start, .-_start
+
+ .data
+ .word f, alias
diff --git a/ld/testsuite/ld-mips-elf/mips-elf.exp b/ld/testsuite/ld-mips-elf/mips-elf.exp
index 04b2951f2fd..f347302a621 100644
--- a/ld/testsuite/ld-mips-elf/mips-elf.exp
+++ b/ld/testsuite/ld-mips-elf/mips-elf.exp
@@ -326,8 +326,10 @@ if { $linux_gnu } {
"mips16-pic-4"]]
}
-# Check MIPS16 markings being passed through link.
+# Check compressed ISA modes through the final link.
run_dump_test "mips16-1"
+run_dump_test_o32 "micromips-local-alias"
+run_dump_test_o32 "micromips-local-alias-call"
# MIPS branch offset final link checking.
run_dump_test "branch-misc-1"
--
2.55.0
More information about the Binutils
mailing list