[PATCH 1/1] LoongArch: Add pointer mangling support.

caiyinyu caiyinyu@loongson.cn
Tue Aug 16 06:34:15 GMT 2022


在 2022/8/16 上午9:28, Xi Ruoyao 写道:
> On Thu, 2022-08-11 at 12:00 +0800, caiyinyu wrote:
>> +/* Load or store to/from a got-relative EXPR into/from 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); \
> Should this be "ld.d T, T, %got_pc_lo12(EXPR)"?  Or if OP is a store
> we'll store into GOT and break it.
>
> Or if we don't need to support store just rename it to "LD_GLOBAL".
>
>> +  OP       G, T, 0;
>> +
>> +/* Load or store to/from a pc-relative EXPR into/from 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);

My mistake. We don't need to support store here.

I thought you were ok with this patch so that it has been included.

I made the following change in next patch:

BTW,the macro REG_L can be ld.d for 64-bits system or ld.w for 32-bits and

now it's ld.d.

 >>>>>>>>>>>>>>

diff --git a/sysdeps/unix/sysv/linux/loongarch/sysdep.h 
b/sysdeps/unix/sysv/linux/loongarch/sysdep.h
index 157cbd6c6b..7acd31d024 100644
--- a/sysdeps/unix/sysv/linux/loongarch/sysdep.h
+++ b/sysdeps/unix/sysv/linux/loongarch/sysdep.h
@@ -316,18 +316,18 @@ 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) \
+#define LD_GLOBAL(G, T,  EXPR) \
    pcalau12i T, %got_pc_hi20(EXPR); \
-  OP       T, T, %got_pc_lo12(EXPR); \
-  OP       G, T, 0;
+  REG_L            T, T, %got_pc_lo12(EXPR); \
+  REG_L            G, T, 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) \
+#define LD_PCREL(G, T,  EXPR) \
    pcalau12i T, %pc_hi20(EXPR); \
-  OP       G, T, %pc_lo12(EXPR);
+  REG_L            G, T, %pc_lo12(EXPR);

  #if (IS_IN (rtld) \
       || (!defined SHARED && (IS_IN (libc) \
@@ -335,10 +335,10 @@ extern long int __syscall_error (long int neg_errno);

  #ifdef __ASSEMBLER__
  #define PTR_MANGLE(dst, src, guard, tmp) \
-  LDST_PCREL (REG_L, guard, tmp, __pointer_chk_guard_local); \
+  LD_PCREL (guard, tmp, __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); \
+  LD_PCREL (guard, tmp, __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) \
@@ -356,10 +356,10 @@ extern uintptr_t __pointer_chk_guard_local 
attribute_relro attribute_hidden;

  #ifdef __ASSEMBLER__
  #define PTR_MANGLE(dst, src, guard, tmp) \
-  LDST_GLOBAL (REG_L, guard, tmp, __pointer_chk_guard); \
+  LD_GLOBAL (guard, tmp, __pointer_chk_guard); \
    PTR_MANGLE2 (dst, src, guard);
  #define PTR_DEMANGLE(dst, src, guard, tmp) \
-  LDST_GLOBAL (REG_L, guard, tmp, __pointer_chk_guard); \
+  LD_GLOBAL (guard, tmp, __pointer_chk_guard); \
    PTR_DEMANGLE2 (dst, src, guard);
  /* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
  #define PTR_MANGLE2(dst, src, guard) \

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


>



More information about the Libc-alpha mailing list