]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
LoongArch: Fix the issue of function jump out of range caused by crtbeginS.o [PR118844].
authorLulu Cheng <chenglulu@loongson.cn>
Wed, 12 Feb 2025 06:29:58 +0000 (14:29 +0800)
committerLulu Cheng <chenglulu@loongson.cn>
Mon, 17 Feb 2025 02:15:39 +0000 (10:15 +0800)
Due to the presence of R_LARCH_B26 in
/usr/lib/gcc/loongarch64-linux-gnu/14/crtbeginS.o, its addressing
range is [PC-128MiB, PC+128MiB-4]. This means that when the code
segment size exceeds 128MB, linking with lld will definitely fail
(ld will not fail because the order of the two is different).

The linking order:
  lld: crtbeginS.o + .text + .plt
  ld : .plt + crtbeginS.o + .text

To solve this issue, add '-mcmodel=extreme' when compiling crtbeginS.o.

PR target/118844

libgcc/ChangeLog:

* config/loongarch/t-crtstuff: Add '-mcmodel=extreme'
to CRTSTUFF_T_CFLAGS_S.

libgcc/config/loongarch/t-crtstuff

index b8c36eb66b78ea6e46e799ea585e0232be5d7190..2a2489b7ef4e6c83d096e48786ae9391ae9c343a 100644 (file)
@@ -3,3 +3,9 @@
 # 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=extreme