diff options
author | Xi Ruoyao <xry111@xry111.site> | 2022-09-24 15:45:34 +0800 |
---|---|---|
committer | caiyinyu <caiyinyu@loongson.cn> | 2022-09-30 11:51:58 +0800 |
commit | 8b10727a9af3e2aa4b27dff0116bb8d3c9afce3d (patch) | |
tree | ca69377c35c0950a0cb5409c4eb558840734be23 /sysdeps/loongarch/start.S | |
parent | 5eb21c62cea9e5879e7637ac6713ba2cb5993ca5 (diff) | |
download | glibc-8b10727a9af3e2aa4b27dff0116bb8d3c9afce3d.tar.gz glibc-8b10727a9af3e2aa4b27dff0116bb8d3c9afce3d.tar.xz glibc-8b10727a9af3e2aa4b27dff0116bb8d3c9afce3d.zip |
LoongArch: Add static PIE support
If the compiler is new enough, enable static PIE support. In the static PIE version of _start (in rcrt1.o), use la.pcrel instead of la.got because in a static PIE we cannot use GOT entries until the dynamic relocations for GOT are resolved.
Diffstat (limited to 'sysdeps/loongarch/start.S')
-rw-r--r-- | sysdeps/loongarch/start.S | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/sysdeps/loongarch/start.S b/sysdeps/loongarch/start.S index e66af16d57..05cabd9b96 100644 --- a/sysdeps/loongarch/start.S +++ b/sysdeps/loongarch/start.S @@ -60,9 +60,17 @@ ENTRY (ENTRY_POINT) cfi_undefined (1) or a5, a0, zero /* rtld_fini */ +#if defined(PIC) && !defined(SHARED) +/* For static PIE, the GOT cannot be used in _start because the GOT entries are + offsets instead of real addresses before __libc_start_main. */ +# define LA la.pcrel +#else /* We must get symbol main through GOT table, since main may not be local. For instance: googletest defines main in dynamic library. */ - la.got a0, t0, main +# define LA la.got +#endif + + LA a0, t0, main REG_L a1, sp, 0 ADDI a2, sp, SZREG @@ -73,9 +81,9 @@ ENTRY (ENTRY_POINT) move a4, zero /* used to be fini */ or a6, sp, zero /* stack_end */ - la.got ra, t0, __libc_start_main + LA ra, t0, __libc_start_main jirl ra, ra, 0 - la.got ra, t0, abort + LA ra, t0, abort jirl ra, ra, 0 END (ENTRY_POINT) |