Browse Source

Added support for creation of Static Position-Independent Executables (PIE) on aarch64

Updated config to allow compilation of rcrt1.o for aarch64 and modified it's crt1.S to relocate dynamic section prior to __uClibc_main.

Disabled stack protector when compiling reloc_static_pie.c to avoid TLS access prior to it being setup.

Signed-off-by: linted <linted@users.noreply.github.com>
linted 1 year ago
parent
commit
3e14288eaa
3 changed files with 16 additions and 2 deletions
  1. 1 1
      extra/Configs/Config.in
  2. 1 1
      libc/misc/internals/Makefile.in
  3. 14 0
      libc/sysdeps/linux/aarch64/crt1.S

+ 1 - 1
extra/Configs/Config.in

@@ -304,7 +304,7 @@ config DOPIC
 config STATIC_PIE
 	bool "Add support for Static Position Independent Executables (PIE)"
 	default n
-	depends on DOPIC && !UCLIBC_FORMAT_FDPIC_ELF && (TARGET_arm || TARGET_i386 || TARGET_x86_64)
+	depends on DOPIC && !UCLIBC_FORMAT_FDPIC_ELF && (TARGET_arm || TARGET_i386 || TARGET_x86_64 || TARGET_aarch64)
 
 config ARCH_HAS_NO_SHARED
 	bool

+ 1 - 1
libc/misc/internals/Makefile.in

@@ -17,7 +17,7 @@ MISC_INTERNALS_SRC := $(patsubst %.c,$(MISC_INTERNALS_DIR)/%.c,$(CSRC-y))
 MISC_INTERNALS_OBJ := $(patsubst %.c,$(MISC_INTERNALS_OUT)/%.o,$(CSRC-y))
 
 CFLAGS-__uClibc_main.c := $(SSP_DISABLE_FLAGS)
-
+CFLAGS-reloc_static_pie.c := $(SSP_DISABLE_FLAGS)
 
 libc-y += $(MISC_INTERNALS_OBJ)
 ifneq ($(UCLIBC_FORMAT_SHARED_FLAT),y)

+ 14 - 0
libc/sysdeps/linux/aarch64/crt1.S

@@ -48,6 +48,20 @@ _start:
 	mov	x29, #0
 	mov	x30, #0
 
+#ifdef L_rcrt1
+	/* Save off the atexit pointer */
+	mov     x19, x0
+
+	/* Calculate load address... idk how this works, but it does */
+	adrp    x0, _start
+
+	/* Do relocations */
+	bl reloc_static_pie
+
+	/* restore atexit pointer */
+	mov     x0, x19
+#endif
+
 	/* Setup _fini in argument register */
 	mov	x5, x0