!930 [sync] PR-928: LoongArch simplify static PIE configure and add thread_pointer support
From: @openeuler-sync-bot Reviewed-by: @liqingqing_1229 Signed-off-by: @liqingqing_1229
This commit is contained in:
commit
d2bc4b13bd
149
0001-LoongArch-Simplify-the-autoconf-check-for-static-PIE.patch
Normal file
149
0001-LoongArch-Simplify-the-autoconf-check-for-static-PIE.patch
Normal file
@ -0,0 +1,149 @@
|
||||
From 5cd98e8c42c34e4a1fc5b3979bcb01a29a2150d0 Mon Sep 17 00:00:00 2001
|
||||
From: Xing Li <lixing@loongson.cn>
|
||||
Date: Tue, 26 Nov 2024 19:40:02 +0800
|
||||
Subject: [PATCH 1/3] LoongArch: Simplify the autoconf check for static PIE
|
||||
|
||||
We are strictly requiring GAS >= 2.41 now, so we don't need to check
|
||||
assembler capability anymore.
|
||||
|
||||
Signed-off-by: Xi Ruoyao <xry111@xry111.site>
|
||||
---
|
||||
sysdeps/loongarch/configure | 37 ++++++++--------------------------
|
||||
sysdeps/loongarch/configure.ac | 31 +++++++++-------------------
|
||||
2 files changed, 18 insertions(+), 50 deletions(-)
|
||||
|
||||
diff --git a/sysdeps/loongarch/configure b/sysdeps/loongarch/configure
|
||||
index 73cf3b95..3ef8ea83 100644
|
||||
--- a/sysdeps/loongarch/configure
|
||||
+++ b/sysdeps/loongarch/configure
|
||||
@@ -4,21 +4,19 @@
|
||||
printf "%s\n" "#define HIDDEN_VAR_NEEDS_DYNAMIC_RELOC 1" >>confdefs.h
|
||||
|
||||
|
||||
-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if the toolchain is sufficient to build static PIE on LoongArch" >&5
|
||||
-printf %s "checking if the toolchain is sufficient to build static PIE on LoongArch... " >&6; }
|
||||
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if ${CC-cc} is sufficient to build static PIE on LoongArch" >&5
|
||||
+printf %s "checking if ${CC-cc} is sufficient to build static PIE on LoongArch... " >&6; }
|
||||
if test ${libc_cv_static_pie_on_loongarch+y}
|
||||
then :
|
||||
printf %s "(cached) " >&6
|
||||
else $as_nop
|
||||
|
||||
- cat > conftest1.S <<\EOF
|
||||
+ cat > conftest.S <<\EOF
|
||||
.global _start
|
||||
.type _start, @function
|
||||
_start:
|
||||
li.w $a7, 93
|
||||
- /* This ensures the assembler supports explicit reloc. */
|
||||
- pcalau12i $a0, %pc_hi20(x)
|
||||
- ld.w $a0, $a0, %pc_lo12(x)
|
||||
+ li.w $a0, 0
|
||||
syscall 0
|
||||
|
||||
.data
|
||||
@@ -27,41 +25,22 @@ x:
|
||||
/* This should produce an R_LARCH_RELATIVE in the static PIE. */
|
||||
.dword _start
|
||||
EOF
|
||||
- cat > conftest2.S <<\EOF
|
||||
-.global f
|
||||
-.type f, @function
|
||||
-f:
|
||||
- /* The linker should be able to handle this and produce a PLT entry. */
|
||||
- la.pcrel $t0, $t0, external_func
|
||||
- jirl $zero, $t0, 0
|
||||
-EOF
|
||||
|
||||
libc_cv_static_pie_on_loongarch=no
|
||||
- if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -static-pie -nostdlib -fPIE -o conftest1 conftest1.S'
|
||||
- { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
|
||||
- (eval $ac_try) 2>&5
|
||||
- ac_status=$?
|
||||
- printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
|
||||
- test $ac_status = 0; }; } \
|
||||
- && { ac_try='LC_ALL=C $READELF -Wr conftest1 | grep -q R_LARCH_RELATIVE'
|
||||
- { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
|
||||
- (eval $ac_try) 2>&5
|
||||
- ac_status=$?
|
||||
- printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
|
||||
- test $ac_status = 0; }; } \
|
||||
- && ! { ac_try='LC_ALL=C $READELF -Wl conftest1 | grep -q INTERP'
|
||||
+
|
||||
+ if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -static-pie -nostdlib -fPIE -o conftest conftest.S'
|
||||
{ { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
|
||||
test $ac_status = 0; }; } \
|
||||
- && { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -shared -fPIC -o conftest2.so conftest2.S'
|
||||
+ && { ac_try='LC_ALL=C $READELF -Wr conftest | grep -q R_LARCH_RELATIVE'
|
||||
{ { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
|
||||
test $ac_status = 0; }; } \
|
||||
- && { ac_try='LC_ALL=C $READELF -Wr conftest2.so | grep -q 'R_LARCH_JUMP_SLOT.*external_func''
|
||||
+ && ! { ac_try='LC_ALL=C $READELF -Wl conftest | grep -q INTERP'
|
||||
{ { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
diff --git a/sysdeps/loongarch/configure.ac b/sysdeps/loongarch/configure.ac
|
||||
index 878c5d64..6436037f 100644
|
||||
--- a/sysdeps/loongarch/configure.ac
|
||||
+++ b/sysdeps/loongarch/configure.ac
|
||||
@@ -8,19 +8,17 @@ AC_DEFINE(HIDDEN_VAR_NEEDS_DYNAMIC_RELOC)
|
||||
dnl Test if the toolchain is new enough for static PIE.
|
||||
dnl We need a GAS supporting explicit reloc (older GAS produces stack-based
|
||||
dnl reloc and triggers an internal error in the linker). And, we need GCC to
|
||||
-dnl pass the correct linker flags for static PIE. GCC >= 13 and GAS >= 2.40
|
||||
-dnl satisfy the requirement, but a distro may backport static PIE support into
|
||||
-dnl earlier GCC or Binutils releases as well.
|
||||
-AC_CACHE_CHECK([if the toolchain is sufficient to build static PIE on LoongArch],
|
||||
+dnl pass the correct linker flags for static PIE. We strictly require GAS >=
|
||||
+dnl 2.41 so we don't need to check the assembler capability, but we need to
|
||||
+dnl check if GCC is doing the correct thing.
|
||||
+AC_CACHE_CHECK([if ${CC-cc} is sufficient to build static PIE on LoongArch],
|
||||
libc_cv_static_pie_on_loongarch, [
|
||||
- cat > conftest1.S <<\EOF
|
||||
+ cat > conftest.S <<\EOF
|
||||
.global _start
|
||||
.type _start, @function
|
||||
_start:
|
||||
li.w $a7, 93
|
||||
- /* This ensures the assembler supports explicit reloc. */
|
||||
- pcalau12i $a0, %pc_hi20(x)
|
||||
- ld.w $a0, $a0, %pc_lo12(x)
|
||||
+ li.w $a0, 0
|
||||
syscall 0
|
||||
|
||||
.data
|
||||
@@ -29,21 +27,12 @@ x:
|
||||
/* This should produce an R_LARCH_RELATIVE in the static PIE. */
|
||||
.dword _start
|
||||
EOF
|
||||
- cat > conftest2.S <<\EOF
|
||||
-.global f
|
||||
-.type f, @function
|
||||
-f:
|
||||
- /* The linker should be able to handle this and produce a PLT entry. */
|
||||
- la.pcrel $t0, $t0, external_func
|
||||
- jirl $zero, $t0, 0
|
||||
-EOF
|
||||
|
||||
libc_cv_static_pie_on_loongarch=no
|
||||
- if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -static-pie -nostdlib -fPIE -o conftest1 conftest1.S]) \
|
||||
- && AC_TRY_COMMAND([LC_ALL=C $READELF -Wr conftest1 | grep -q R_LARCH_RELATIVE]) \
|
||||
- && ! AC_TRY_COMMAND([LC_ALL=C $READELF -Wl conftest1 | grep -q INTERP]) \
|
||||
- && AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -shared -fPIC -o conftest2.so conftest2.S]) \
|
||||
- && AC_TRY_COMMAND([LC_ALL=C $READELF -Wr conftest2.so | grep -q 'R_LARCH_JUMP_SLOT.*external_func'])
|
||||
+
|
||||
+ if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -static-pie -nostdlib -fPIE -o conftest conftest.S]) \
|
||||
+ && AC_TRY_COMMAND([LC_ALL=C $READELF -Wr conftest | grep -q R_LARCH_RELATIVE]) \
|
||||
+ && ! AC_TRY_COMMAND([LC_ALL=C $READELF -Wl conftest | grep -q INTERP])
|
||||
then
|
||||
libc_cv_static_pie_on_loongarch=yes
|
||||
fi
|
||||
--
|
||||
2.43.0
|
||||
|
||||
67
0002-nptl-Add-thread_pointer.h-for-LoongArch.patch
Normal file
67
0002-nptl-Add-thread_pointer.h-for-LoongArch.patch
Normal file
@ -0,0 +1,67 @@
|
||||
From 47319d002f7b5e37c179acb7d2a6d351cd112f97 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Jeanson <mjeanson@efficios.com>
|
||||
Date: Wed, 23 Oct 2024 16:18:06 -0400
|
||||
Subject: [PATCH 2/3] nptl: Add <thread_pointer.h> for LoongArch
|
||||
|
||||
This will be required by the rseq extensible ABI implementation on all
|
||||
Linux architectures exposing the '__rseq_size' and '__rseq_offset'
|
||||
symbols to set the initial value of the 'cpu_id' field which can be used
|
||||
by applications to test if rseq is available and registered. As long as
|
||||
the symbols are exposed it is valid for an application to perform this
|
||||
test even if rseq is not yet implemented in libc for this architecture.
|
||||
|
||||
Both code paths are compile tested with build-many-glibcs.py but I don't
|
||||
have access to any hardware to run the tests.
|
||||
|
||||
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
|
||||
Reviewed-by: Arjun Shankar <arjun@redhat.com>
|
||||
---
|
||||
sysdeps/loongarch/nptl/thread_pointer.h | 36 +++++++++++++++++++++++++
|
||||
1 file changed, 36 insertions(+)
|
||||
create mode 100644 sysdeps/loongarch/nptl/thread_pointer.h
|
||||
|
||||
diff --git a/sysdeps/loongarch/nptl/thread_pointer.h b/sysdeps/loongarch/nptl/thread_pointer.h
|
||||
new file mode 100644
|
||||
index 00000000..5dec2ef4
|
||||
--- /dev/null
|
||||
+++ b/sysdeps/loongarch/nptl/thread_pointer.h
|
||||
@@ -0,0 +1,36 @@
|
||||
+/* __thread_pointer definition. loongarch version.
|
||||
+ Copyright (C) 2021-2024 Free Software Foundation, Inc.
|
||||
+ This file is part of the GNU C Library.
|
||||
+
|
||||
+ The GNU C Library is free software; you can redistribute it and/or
|
||||
+ modify it under the terms of the GNU Lesser General Public
|
||||
+ License as published by the Free Software Foundation; either
|
||||
+ version 2.1 of the License, or (at your option) any later version.
|
||||
+
|
||||
+ The GNU C Library is distributed in the hope that it will be useful,
|
||||
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
+ Lesser General Public License for more details.
|
||||
+
|
||||
+ You should have received a copy of the GNU Lesser General Public
|
||||
+ License along with the GNU C Library. If not, see
|
||||
+ <https://www.gnu.org/licenses/>. */
|
||||
+
|
||||
+#ifndef _SYS_THREAD_POINTER_H
|
||||
+#define _SYS_THREAD_POINTER_H
|
||||
+
|
||||
+#include <sys/cdefs.h>
|
||||
+
|
||||
+static inline void *
|
||||
+__thread_pointer (void)
|
||||
+{
|
||||
+#if __glibc_has_builtin (__builtin_thread_pointer)
|
||||
+ return __builtin_thread_pointer ();
|
||||
+#else
|
||||
+ void *__thread_register;
|
||||
+ __asm__ ("move %0, $tp" : "=r" (__thread_register));
|
||||
+ return __thread_register;
|
||||
+#endif
|
||||
+}
|
||||
+
|
||||
+#endif /* _SYS_THREAD_POINTER_H */
|
||||
--
|
||||
2.43.0
|
||||
|
||||
@ -0,0 +1,53 @@
|
||||
From 4fc83ec7003cd216c651d7695e78910b0d0400f2 Mon Sep 17 00:00:00 2001
|
||||
From: caiyinyu <caiyinyu@loongson.cn>
|
||||
Date: Wed, 6 Nov 2024 10:06:21 +0800
|
||||
Subject: [PATCH 3/3] nptl: fix __builtin_thread_pointer detection on LoongArch
|
||||
|
||||
Signed-off-by: caiyinyu <caiyinyu@loongson.cn>
|
||||
---
|
||||
sysdeps/loongarch/nptl/thread_pointer.h | 10 ++--------
|
||||
sysdeps/loongarch/nptl/tls.h | 2 +-
|
||||
2 files changed, 3 insertions(+), 9 deletions(-)
|
||||
|
||||
diff --git a/sysdeps/loongarch/nptl/thread_pointer.h b/sysdeps/loongarch/nptl/thread_pointer.h
|
||||
index 5dec2ef4..cc96062c 100644
|
||||
--- a/sysdeps/loongarch/nptl/thread_pointer.h
|
||||
+++ b/sysdeps/loongarch/nptl/thread_pointer.h
|
||||
@@ -19,18 +19,12 @@
|
||||
#ifndef _SYS_THREAD_POINTER_H
|
||||
#define _SYS_THREAD_POINTER_H
|
||||
|
||||
-#include <sys/cdefs.h>
|
||||
+register void *__thread_self asm ("$tp");
|
||||
|
||||
static inline void *
|
||||
__thread_pointer (void)
|
||||
{
|
||||
-#if __glibc_has_builtin (__builtin_thread_pointer)
|
||||
- return __builtin_thread_pointer ();
|
||||
-#else
|
||||
- void *__thread_register;
|
||||
- __asm__ ("move %0, $tp" : "=r" (__thread_register));
|
||||
- return __thread_register;
|
||||
-#endif
|
||||
+ return __thread_self;
|
||||
}
|
||||
|
||||
#endif /* _SYS_THREAD_POINTER_H */
|
||||
diff --git a/sysdeps/loongarch/nptl/tls.h b/sysdeps/loongarch/nptl/tls.h
|
||||
index c52ede4d..6356a54d 100644
|
||||
--- a/sysdeps/loongarch/nptl/tls.h
|
||||
+++ b/sysdeps/loongarch/nptl/tls.h
|
||||
@@ -26,8 +26,8 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <dl-dtv.h>
|
||||
+#include "thread_pointer.h"
|
||||
|
||||
-register void *__thread_self asm ("$tp");
|
||||
#define READ_THREAD_POINTER() ({ __thread_self; })
|
||||
|
||||
/* Get system call information. */
|
||||
--
|
||||
2.43.0
|
||||
|
||||
@ -67,7 +67,7 @@
|
||||
##############################################################################
|
||||
Name: glibc
|
||||
Version: 2.38
|
||||
Release: 41
|
||||
Release: 42
|
||||
Summary: The GNU libc libraries
|
||||
License: %{all_license}
|
||||
URL: http://www.gnu.org/software/glibc/
|
||||
@ -240,6 +240,9 @@ Patch150: 0012-LoongArch-Undef-__NR_fstat-and-__NR_newfstatat.patch
|
||||
Patch151: 0013-From-Adhemerval-Zanella-adhemerval.zanella-linaro.or.patch
|
||||
Patch152: 0014-loongarch-Remove-duplicate-strnlen-in-libc.a-BZ-3178.patch
|
||||
Patch153: 0015-LoongArch-Change-tunable-for-2.38.patch
|
||||
Patch154: 0001-LoongArch-Simplify-the-autoconf-check-for-static-PIE.patch
|
||||
Patch155: 0002-nptl-Add-thread_pointer.h-for-LoongArch.patch
|
||||
Patch156: 0003-nptl-fix-__builtin_thread_pointer-detection-on-Loong.patch
|
||||
|
||||
#openEuler patch list
|
||||
Patch9000: turn-default-value-of-x86_rep_stosb_threshold_form_2K_to_1M.patch
|
||||
@ -1461,6 +1464,9 @@ fi
|
||||
%endif
|
||||
|
||||
%changelog
|
||||
* Wed Nov 27 2024 lixing <lixing@loongson.cn> - 2.38-42
|
||||
- LoongArch: Simplify static-pie support and change nptl support
|
||||
|
||||
* Wed Nov 6 2024 lixing <lixing@loongson.cn> - 2.38-41
|
||||
- update LoongArch with tlsdec and tunable support
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user