[PATCH v2] LoongArch: Set the default ABI for the loongarch*-elf target

Lulu Cai cailulu@loongson.cn
Fri Dec 12 03:28:36 GMT 2025


The ABI setting for the elf target was ommitted in commit "db614f37cab".
Set the default ABI for elf to support the loongarch*-elf.

In addition, test case failures caused by the loongarch*-elf linker not
supporting relevant options have also been fixed.

gas/

        * config/tc-loongarch.c (loongarch_after_parse_args): Set
	  default ABI for others.

ld/

        * testsuite/ld-loongarch-elf/la32.d: Skip tests when not
	  supported.
        * testsuite/ld-loongarch-elf/ld-loongarch-elf.exp: Likewise.
        * testsuite/ld-loongarch-elf/relax.exp: Likewise.

---
Changes from v1:
  - Skip more unsupported tests.

v1: https://sourceware.org/pipermail/binutils/2025-December/146428.html
---
 gas/config/tc-loongarch.c                     |   3 +-
 ld/testsuite/ld-loongarch-elf/la32.d          |   1 +
 .../ld-loongarch-elf/ld-loongarch-elf.exp     |  26 ++--
 ld/testsuite/ld-loongarch-elf/relax.exp       | 136 +++++++++---------
 4 files changed, 89 insertions(+), 77 deletions(-)

diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c
index e049427956c..5f7d3a3522c 100644
--- a/gas/config/tc-loongarch.c
+++ b/gas/config/tc-loongarch.c
@@ -314,7 +314,8 @@ loongarch_after_parse_args ()
       else if (strcmp (TARGET_OS, "linux-gnu") == 0)
 	LARCH_opts.ase_abi = EF_LOONGARCH_ABI_DOUBLE_FLOAT;
       else
-	as_fatal (_("unsupport TARGET_OS %s"), TARGET_OS);
+	/* To support lonngarch*-elf, the ABI needs to be set.  */
+	LARCH_opts.ase_abi = EF_LOONGARCH_ABI_DOUBLE_FLOAT;
     }
 
   /* Set eflags ABI version to v1 (ELF object file ABI 2.0).  */
diff --git a/ld/testsuite/ld-loongarch-elf/la32.d b/ld/testsuite/ld-loongarch-elf/la32.d
index 9f66b7bba8f..7d4e0e75fbe 100644
--- a/ld/testsuite/ld-loongarch-elf/la32.d
+++ b/ld/testsuite/ld-loongarch-elf/la32.d
@@ -1,6 +1,7 @@
 #as -mabi=ilp32d:
 #ld: -z norelro --hash-style=both -e0
 #objdump: -dr
+#skip: loongarch*-elf
 
 .*:[    ]+file format .*
 
diff --git a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp
index 7b0b066190c..5c4bf3275eb 100644
--- a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp
+++ b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp
@@ -164,18 +164,20 @@ if [istarget "loongarch64-*-*"] {
   # Using DESC and IE to access the same tls symbol but with
   # -mno-relax requires allocating GOT entries for both DESC and IE,
   # not just IE
-  run_ld_link_tests [list \
-      [list \
-	  "desc and ie do not type transition" \
-	  "-pie -e0 --hash-style=both" "" \
-	  "-mno-relax" \
-	  {desc-ie-norelax.s} \
-	  {{objdump {-d} desc-ie-norelax.dd} \
-	   {readelf {-rW} desc-ie-norelax.rd} \
-	   {objdump {-sj.got} desc-ie-norelax.sd}} \
-	  "desc-ie-norelax" \
-      ] \
-  ] \
+  if [check_pie_support] {
+    run_ld_link_tests [list \
+	[list \
+	    "desc and ie do not type transition" \
+	    "-pie -e0 --hash-style=both" "" \
+	    "-mno-relax" \
+	    {desc-ie-norelax.s} \
+	    {{objdump {-d} desc-ie-norelax.dd} \
+	    {readelf {-rW} desc-ie-norelax.rd} \
+	    {objdump {-sj.got} desc-ie-norelax.sd}} \
+	    "desc-ie-norelax" \
+	] \
+    ] \
+  }
 
   run_ld_link_tests \
       [list \
diff --git a/ld/testsuite/ld-loongarch-elf/relax.exp b/ld/testsuite/ld-loongarch-elf/relax.exp
index 49e6b23b606..976ba8df045 100644
--- a/ld/testsuite/ld-loongarch-elf/relax.exp
+++ b/ld/testsuite/ld-loongarch-elf/relax.exp
@@ -51,66 +51,72 @@ if [istarget loongarch64-*-*] {
     run_dump_test "relax-align-ignore-start"
     run_partial_linking_align_test
 
-    run_ld_link_tests \
-      [list \
+    if [check_shared_lib_support] {
+      run_ld_link_tests \
 	[list \
-	"loongarch relax call36 .so build" \
-	"-shared" "" \
-	"" \
-	{relax-call36-so.s} \
-	{} \
-	"relax-call36.so" \
-	] \
-      ]
+	  [list \
+	  "loongarch relax call36 .so build" \
+	  "-shared" "" \
+	  "" \
+	  {relax-call36-so.s} \
+	  {} \
+	  "relax-call36.so" \
+	  ] \
+	]
 
-    if [file exist "tmpdir/relax-call36.so"] {
-      set objdump_output [run_host_cmd "objdump" "-d tmpdir/relax-call36.so"]
-      if { [ regexp "pcaddu18i" $objdump_output] } {
-	fail "loongarch relax call36 so"
-      } {
-	pass "loongarch relax call36 so"
+      if [file exist "tmpdir/relax-call36.so"] {
+	set objdump_output [run_host_cmd "objdump" "-d tmpdir/relax-call36.so"]
+	if { [ regexp "pcaddu18i" $objdump_output] } {
+	  fail "loongarch relax call36 so"
+	} {
+	  pass "loongarch relax call36 so"
+	}
       }
     }
 
-    run_ld_link_tests \
-      [list \
+    if [check_pie_support] {
+      run_ld_link_tests \
 	[list \
-	"loongarch relax call36 dyn exe build" \
-	"-pie -e 0" "" \
-	"" \
-	{relax-call36-exe.s} \
-	{} \
-	"relax-call36-d.exe" \
-	] \
-      ]
+	  [list \
+	  "loongarch relax call36 dyn exe build" \
+	  "-pie -e 0" "" \
+	  "" \
+	  {relax-call36-exe.s} \
+	  {} \
+	  "relax-call36-d.exe" \
+	  ] \
+	]
 
-    if [file exist "tmpdir/relax-call36-d.exe"] {
-      set objdump_output [run_host_cmd "objdump" "-d tmpdir/relax-call36-d.exe"]
-      if { [ regexp "pcaddu18i" $objdump_output] } {
-	fail "loongarch relax call36 dyn exe"
-      } {
-	pass "loongarch relax call36 dyn exe"
+      if [file exist "tmpdir/relax-call36-d.exe"] {
+	set objdump_output [run_host_cmd "objdump" "-d tmpdir/relax-call36-d.exe"]
+	if { [ regexp "pcaddu18i" $objdump_output] } {
+	  fail "loongarch relax call36 dyn exe"
+	} {
+	  pass "loongarch relax call36 dyn exe"
+	}
       }
     }
 
-    run_ld_link_tests \
-      [list \
+    if [check_pie_support] {
+      run_ld_link_tests \
 	[list \
-	"loongarch relax call36 dyn-pie exe build" \
-	"-pie -e 0" "" \
-	"" \
-	{relax-call36-exe.s} \
-	{} \
-	"relax-call36-dp.exe" \
-	] \
-      ]
+	  [list \
+	  "loongarch relax call36 dyn-pie exe build" \
+	  "-pie -e 0" "" \
+	  "" \
+	  {relax-call36-exe.s} \
+	  {} \
+	  "relax-call36-dp.exe" \
+	  ] \
+	]
 
-    if [file exist "tmpdir/relax-call36-dp.exe"] {
-      set objdump_output [run_host_cmd "objdump" "-d tmpdir/relax-call36-dp.exe"]
-      if { [ regexp "pcaddu18i" $objdump_output] } {
-	fail "loongarch relax call36 dyn-pie exe"
-      } {
-	pass "loongarch relax call36 dyn-pie exe"
+      if [file exist "tmpdir/relax-call36-dp.exe"] {
+	set objdump_output [run_host_cmd "objdump" "-d tmpdir/relax-call36-dp.exe"]
+	if { [ regexp "pcaddu18i" $objdump_output] } {
+	  fail "loongarch relax call36 dyn-pie exe"
+	} {
+	  pass "loongarch relax call36 dyn-pie exe"
+	}
       }
     }
 
@@ -135,24 +141,26 @@ if [istarget loongarch64-*-*] {
       }
     }
 
-    run_ld_link_tests \
-      [list \
+    if [check_pie_support] {
+      run_ld_link_tests \
 	[list \
-	"loongarch relax call36 static-pie exe build" \
-	"-static -pie --no-dynamic-linker -e 0" "" \
-	"" \
-	{relax-call36-exe.s} \
-	{} \
-	"relax-call36-sp.exe" \
-	] \
-      ]
+	  [list \
+	  "loongarch relax call36 static-pie exe build" \
+	  "-static -pie --no-dynamic-linker -e 0" "" \
+	  "" \
+	  {relax-call36-exe.s} \
+	  {} \
+	  "relax-call36-sp.exe" \
+	  ] \
+	]
 
-    if [file exist "tmpdir/relax-call36-sp.exe"] {
-      set objdump_output [run_host_cmd "objdump" "-d tmpdir/relax-call36-sp.exe"]
-      if { [ regexp "pcaddu18i" $objdump_output] } {
-	fail "loongarch relax call36 static-pie exe"
-      } {
-	pass "loongarch relax call36 static-pie exe"
+      if [file exist "tmpdir/relax-call36-sp.exe"] {
+	set objdump_output [run_host_cmd "objdump" "-d tmpdir/relax-call36-sp.exe"]
+	if { [ regexp "pcaddu18i" $objdump_output] } {
+	  fail "loongarch relax call36 static-pie exe"
+	} {
+	  pass "loongarch relax call36 static-pie exe"
+	}
       }
     }
 
-- 
2.38.1



More information about the Binutils mailing list