https://gcc.gnu.org/g:a79d9b6dbfb485055dd6cad2981dead4407d3b7d

commit r16-6054-ga79d9b6dbfb485055dd6cad2981dead4407d3b7d
Author: mengqinggang <[email protected]>
Date:   Thu Dec 11 14:13:55 2025 +0800

    LoongArch: Add support for libgcc on LA32
    
    LA32 does not support extreme code mode, change to medium code model on 
LA32.
    
    libgcc/ChangeLog:
    
            * configure: Regenerate.
            * configure.ac:
            * config/loongarch/t-crtstuff-la32: New file.
            * config/loongarch/t-crtstuff: Rename to t-crtstuff-la64.
    
    Reviewed-by: Xi Ruoyao <[email protected]>
    Reviewed-by: Lulu Cheng <[email protected]>

Diff:
---
 libgcc/config/loongarch/t-crtstuff-la32                 | 11 +++++++++++
 libgcc/config/loongarch/{t-crtstuff => t-crtstuff-la64} |  0
 libgcc/configure                                        | 12 ++++++++++++
 libgcc/configure.ac                                     | 12 ++++++++++++
 4 files changed, 35 insertions(+)

diff --git a/libgcc/config/loongarch/t-crtstuff-la32 
b/libgcc/config/loongarch/t-crtstuff-la32
new file mode 100644
index 000000000000..d2bc8e5e79fc
--- /dev/null
+++ b/libgcc/config/loongarch/t-crtstuff-la32
@@ -0,0 +1,11 @@
+# -fasynchronous-unwind-tables is on by default for LoongArch.
+# We turn it off for crt*.o because it would make __EH_FRAME_BEGIN__ point
+# to .eh_frame data from crtbeginT.o instead of the user-defined object
+# during static linking.
+CRTSTUFF_T_CFLAGS += -fno-omit-frame-pointer -fno-asynchronous-unwind-tables
+
+# As shown in the test case PR118844, when using lld for linking,
+# it fails due to B26 in crtbeginS.o causing the link to exceed the range.
+# Therefore, the issue was resolved by adding the compilation option
+# "-mcmodel=extreme" when compiling crtbeginS.o.
+CRTSTUFF_T_CFLAGS_S += -mcmodel=medium
diff --git a/libgcc/config/loongarch/t-crtstuff 
b/libgcc/config/loongarch/t-crtstuff-la64
similarity index 100%
rename from libgcc/config/loongarch/t-crtstuff
rename to libgcc/config/loongarch/t-crtstuff-la64
diff --git a/libgcc/configure b/libgcc/configure
index fe7a21c296c3..8cdc021f9c18 100755
--- a/libgcc/configure
+++ b/libgcc/configure
@@ -5397,6 +5397,18 @@ case ${host} in
 esac
 
 
+case ${host} in
+loongarch32*-*-*)
+  tmake_file="${tmake_file} loongarch/t-crtstuff-la32"
+  ;;
+esac
+
+case ${host} in
+loongarch64*-*-*)
+  tmake_file="${tmake_file} loongarch/t-crtstuff-la64"
+  ;;
+esac
+
 # Check if xtensa target is configured for windowed ABI and thus needs to use
 # custom unwind code.
 # This is after config.host so we can augment tmake_file.
diff --git a/libgcc/configure.ac b/libgcc/configure.ac
index 59452436bd8a..1ae782c480c8 100644
--- a/libgcc/configure.ac
+++ b/libgcc/configure.ac
@@ -530,6 +530,18 @@ case ${host} in
 esac
 AC_SUBST(solaris_ld_v2_maps)
 
+case ${host} in
+loongarch32*-*-*)
+  tmake_file="${tmake_file} loongarch/t-crtstuff-la32"
+  ;;
+esac
+
+case ${host} in
+loongarch64*-*-*)
+  tmake_file="${tmake_file} loongarch/t-crtstuff-la64"
+  ;;
+esac
+
 # Check if xtensa target is configured for windowed ABI and thus needs to use
 # custom unwind code.
 # This is after config.host so we can augment tmake_file.

Reply via email to