Browse Source

Static pie support for ppc

Modified config files and crt1.S to support static pie elf generation.

Signed-off-by: linted <linted@users.noreply.github.com>
linted 1 year ago
parent
commit
9e854172e2
2 changed files with 20 additions and 1 deletions
  1. 1 1
      extra/Configs/Config.in
  2. 19 0
      libc/sysdeps/linux/powerpc/crt1.S

+ 1 - 1
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

+ 19 - 0
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__