LoongArch: Fix the issue of function jump out of range caused by crtbeginS.o [PR118844].

Message ID 20250212080126.21433-1-chenglulu@loongson.cn
State Committed
Commit ae14d7d04da8c6cb542269722638071f999f94d8
Headers
Series LoongArch: Fix the issue of function jump out of range caused by crtbeginS.o [PR118844]. |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gcc_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_simplebootstrap_build--master-aarch64-bootstrap success Build passed
linaro-tcwg-bot/tcwg_simplebootstrap_build--master-arm-bootstrap success Build passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 success Test passed

Commit Message

Lulu Cheng Feb. 12, 2025, 8:01 a.m. UTC
  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.

libgcc/ChangeLog:

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

---
 libgcc/config/loongarch/t-crtstuff | 6 ++++++
 1 file changed, 6 insertions(+)
  

Comments

Lulu Cheng Feb. 17, 2025, 2:18 a.m. UTC | #1
Pushed to r15-7581.

在 2025/2/12 下午4:01, Lulu Cheng 写道:
> 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.
>
> libgcc/ChangeLog:
>
> 	* config/loongarch/t-crtstuff: Add '-mcmodel=extreme'
> 	to CRTSTUFF_T_CFLAGS_S.
>
> ---
>   libgcc/config/loongarch/t-crtstuff | 6 ++++++
>   1 file changed, 6 insertions(+)
>
> diff --git a/libgcc/config/loongarch/t-crtstuff b/libgcc/config/loongarch/t-crtstuff
> index b8c36eb66b7..2a2489b7ef4 100644
> --- a/libgcc/config/loongarch/t-crtstuff
> +++ b/libgcc/config/loongarch/t-crtstuff
> @@ -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
  

Patch

diff --git a/libgcc/config/loongarch/t-crtstuff b/libgcc/config/loongarch/t-crtstuff
index b8c36eb66b7..2a2489b7ef4 100644
--- a/libgcc/config/loongarch/t-crtstuff
+++ b/libgcc/config/loongarch/t-crtstuff
@@ -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