From 9e854172e249a383d858fef70368af63a04a28a8 Mon Sep 17 00:00:00 2001 From: linted Date: Fri, 7 Oct 2022 22:49:12 -0400 Subject: Static pie support for ppc Modified config files and crt1.S to support static pie elf generation. Signed-off-by: linted --- extra/Configs/Config.in | 2 +- libc/sysdeps/linux/powerpc/crt1.S | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/extra/Configs/Config.in b/extra/Configs/Config.in index dd1beaadc..1c41d77ff 100644 --- a/extra/Configs/Config.in +++ b/extra/Configs/Config.in @@ -326,7 +326,7 @@ config STATIC_PIE default n depends on DOPIC && !UCLIBC_FORMAT_FDPIC_ELF && \ (TARGET_arm || TARGET_i386 || TARGET_x86_64 || TARGET_aarch64 || \ - TARGET_mips || TARGET_xtensa) + TARGET_mips || TARGET_xtensa || TARGET_powerpc) config ARCH_HAS_NO_SHARED bool diff --git a/libc/sysdeps/linux/powerpc/crt1.S b/libc/sysdeps/linux/powerpc/crt1.S index 3f5d056c0..3ac32636c 100644 --- a/libc/sysdeps/linux/powerpc/crt1.S +++ b/libc/sysdeps/linux/powerpc/crt1.S @@ -40,6 +40,9 @@ #ifndef __UCLIBC_CTOR_DTOR__ .weak _init .weak _fini +#endif +#ifdef L_rcrt1 + .type reloc_static_pie,%function #endif .type main,%function .type __uClibc_main,%function @@ -61,6 +64,22 @@ _start: # ifdef PPC_HAS_SECUREPLT mr 30,31 # endif +#ifdef L_rcrt1 + stwu r3, -4(r1) /* Save r3 */ + stwu r9, -16(r1) /* Save r9 */ + bcl 20,31,2f /* Jump to label 2 */ +2: mflr r3 /* Load lr into r3 */ + addis r3, r3, _DYNAMIC-2b@ha /* Add high half of _DYNAMIC to r3 */ + addi r3,r3,_DYNAMIC-2b@l /* Add low half of _DYNAMIC */ + lwz r4, 0(r31) /* load _DYNAMIC from the GOT */ + subf r3, r4, r3 /* sub _DYNAMIC@got and it's actual address */ + bl reloc_static_pie /* Call reloc_static_pie */ + lwzu r9, 0(r1) /* restore r9 */ + addi r1, r1, 16 /* update stack pointer */ + lwzu r3, 0(r1) /* restore r3 */ + addi r1, r1, 4 /* update stack pointer */ + li r5, 0 /* zero r5 */ +#endif #endif /* Set up the small data pointer in r13. */ #ifdef __PIC__ -- cgit v1.2.3