[1/1] LoongArch: Fix ptr mangling/demangling features.
Checks
Context |
Check |
Description |
dj/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
dj/TryBot-32bit |
success
|
Build for i686
|
Commit Message
Tested on LoongArch machine: gcc 13.0.0, Linux kernel 5.19.0 rc2,
binutils branch master 2eb132bdfb9.
This patch is ok with gcc 12.0.1, Linux kernel 5.19.0 rc5, binutils
2.39.
---
sysdeps/loongarch/__longjmp.S | 2 +-
sysdeps/loongarch/setjmp.S | 2 +-
sysdeps/unix/sysv/linux/loongarch/sysdep.h | 33 +++++++++++-----------
3 files changed, 18 insertions(+), 19 deletions(-)
Comments
On Thu, 2022-08-18 at 10:19 +0800, caiyinyu wrote:
> -/* Load or store to/from a pc-relative EXPR into/from G, using T.
> +/* Load a pc-relative EXPR into G, using T.
> Note G and T are register names. */
> -#define LDST_PCREL(OP, G, T, EXPR) \
> - pcalau12i T, %pc_hi20(EXPR); \
> - OP G, T, %pc_lo12(EXPR);
> +#define LD_PCREL(G, EXPR) \
> + la.pcrel G, EXPR; \
> + REG_L G, G, 0;
I'd write
#if HAVE_LOONGARCH_EXPLICIT_RELOCS
# define LDST_PCREL(OP, G, T, EXPR) \
pcalau12i T, %pc_hi20(EXPR); \
OP G, T, %pc_lo12(EXPR);
#else
# define LD_PCREL(G, EXPR) \
la.pcrel G, EXPR; \
REG_L G, G, 0;
#endif
And in configure.ac:
AC_CACHE_CHECK(whether explicit relocs can be used,
libc_cv_loongarch_explicit_relocs, [dnl
cat > conftest.s << EOF
x: pcalau12i $t0, %pc_hi20(x)
EOF
libc_cv_loongarch_explicit_relocs=no
if AC_TRY_COMMAND(${CC-cc} -c $CFLAGS conftest.s -o conftest.o 1>&AS_MESSAGE_LOG_FD); then
libc_cv_loongarch_explicit_relocs=yes
fi
rm -f conftest*])
if test $libc_cv_loongarch_explicit_relocs = yes; then
AC_DEFINE(HAVE_LOONGARCH_EXPLICIT_RELOCS)
fi
This is a micro optimization but two instructions is smaller than 3
instructions anyway :).
I have sent new patches and I made some changes to prevent
build errors.
https://sourceware.org/pipermail/libc-alpha/2022-August/141588.html
在 2022/8/21 下午9:29, Xi Ruoyao 写道:
> On Thu, 2022-08-18 at 10:19 +0800, caiyinyu wrote:
>> -/* Load or store to/from a pc-relative EXPR into/from G, using T.
>> +/* Load a pc-relative EXPR into G, using T.
>> Note G and T are register names. */
>> -#define LDST_PCREL(OP, G, T, EXPR) \
>> - pcalau12i T, %pc_hi20(EXPR); \
>> - OP G, T, %pc_lo12(EXPR);
>> +#define LD_PCREL(G, EXPR) \
>> + la.pcrel G, EXPR; \
>> + REG_L G, G, 0;
> I'd write
>
> #if HAVE_LOONGARCH_EXPLICIT_RELOCS
> # define LDST_PCREL(OP, G, T, EXPR) \
> pcalau12i T, %pc_hi20(EXPR); \
> OP G, T, %pc_lo12(EXPR);
> #else
> # define LD_PCREL(G, EXPR) \
> la.pcrel G, EXPR; \
> REG_L G, G, 0;
> #endif
>
> And in configure.ac:
>
> AC_CACHE_CHECK(whether explicit relocs can be used,
> libc_cv_loongarch_explicit_relocs, [dnl
> cat > conftest.s << EOF
> x: pcalau12i $t0, %pc_hi20(x)
> EOF
> libc_cv_loongarch_explicit_relocs=no
> if AC_TRY_COMMAND(${CC-cc} -c $CFLAGS conftest.s -o conftest.o 1>&AS_MESSAGE_LOG_FD); then
> libc_cv_loongarch_explicit_relocs=yes
> fi
> rm -f conftest*])
> if test $libc_cv_loongarch_explicit_relocs = yes; then
> AC_DEFINE(HAVE_LOONGARCH_EXPLICIT_RELOCS)
> fi
>
> This is a micro optimization but two instructions is smaller than 3
> instructions anyway :).
>
@@ -22,7 +22,7 @@
ENTRY (__longjmp)
#ifdef PTR_MANGLE
REG_L t0, a0, 0*SZREG
- PTR_DEMANGLE (ra, t0, t1, t2)
+ PTR_DEMANGLE (ra, t0, t1)
REG_L t0, a0, 1*SZREG
PTR_DEMANGLE2 (sp, t0, t1)
#else
@@ -30,7 +30,7 @@ END (setjmp)
ENTRY (__sigsetjmp)
#ifdef PTR_MANGLE
- PTR_MANGLE (t0, ra, t1, t2)
+ PTR_MANGLE (t0, ra, t1)
REG_S t0, a0, 0*SZREG
PTR_MANGLE2 (t0, sp, t1)
REG_S t0, a0, 1*SZREG
@@ -316,29 +316,28 @@ extern long int __syscall_error (long int neg_errno);
/* Pointer mangling is supported for LoongArch. */
-/* Load or store to/from a got-relative EXPR into/from G, using T.
+/* Load a got-relative EXPR into G, using T.
Note G and T are register names. */
-#define LDST_GLOBAL(OP, G, T, EXPR) \
- pcalau12i T, %got_pc_hi20(EXPR); \
- OP T, T, %got_pc_lo12(EXPR); \
- OP G, T, 0;
+#define LD_GLOBAL(G, EXPR) \
+ la.global G, EXPR; \
+ REG_L G, G, 0;
-/* Load or store to/from a pc-relative EXPR into/from G, using T.
+/* Load a pc-relative EXPR into G, using T.
Note G and T are register names. */
-#define LDST_PCREL(OP, G, T, EXPR) \
- pcalau12i T, %pc_hi20(EXPR); \
- OP G, T, %pc_lo12(EXPR);
+#define LD_PCREL(G, EXPR) \
+ la.pcrel G, EXPR; \
+ REG_L G, G, 0;
#if (IS_IN (rtld) \
|| (!defined SHARED && (IS_IN (libc) \
|| IS_IN (libpthread))))
#ifdef __ASSEMBLER__
-#define PTR_MANGLE(dst, src, guard, tmp) \
- LDST_PCREL (REG_L, guard, tmp, __pointer_chk_guard_local); \
+#define PTR_MANGLE(dst, src, guard) \
+ LD_PCREL (guard, __pointer_chk_guard_local); \
PTR_MANGLE2 (dst, src, guard);
-#define PTR_DEMANGLE(dst, src, guard, tmp) \
- LDST_PCREL (REG_L, guard, tmp, __pointer_chk_guard_local); \
+#define PTR_DEMANGLE(dst, src, guard) \
+ LD_PCREL (guard, __pointer_chk_guard_local); \
PTR_DEMANGLE2 (dst, src, guard);
/* Use PTR_MANGLE2 for efficiency if guard is already loaded. */
#define PTR_MANGLE2(dst, src, guard) \
@@ -355,11 +354,11 @@ extern uintptr_t __pointer_chk_guard_local attribute_relro attribute_hidden;
#else
#ifdef __ASSEMBLER__
-#define PTR_MANGLE(dst, src, guard, tmp) \
- LDST_GLOBAL (REG_L, guard, tmp, __pointer_chk_guard); \
+#define PTR_MANGLE(dst, src, guard) \
+ LD_GLOBAL (guard, __pointer_chk_guard); \
PTR_MANGLE2 (dst, src, guard);
-#define PTR_DEMANGLE(dst, src, guard, tmp) \
- LDST_GLOBAL (REG_L, guard, tmp, __pointer_chk_guard); \
+#define PTR_DEMANGLE(dst, src, guard) \
+ LD_GLOBAL (guard, __pointer_chk_guard); \
PTR_DEMANGLE2 (dst, src, guard);
/* Use PTR_MANGLE2 for efficiency if guard is already loaded. */
#define PTR_MANGLE2(dst, src, guard) \