This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH][RFC] aarch64: fix start code for static pie


with upcoming static pie patches there are three flavors of the crt startup code:

1) crt1.o used for non-pie static linking (executable has no relocs),
2) Scrt1.o used for dynamic linking (dynamic linker relocates),
3) rcrt1.o used for static pie linking (self relocation is needed)

when crt1.o and rcrt1.o is built in the --enable-static-pie case -DPIC is passed,
when Scrt1.o is built then -DPIC -DSHARED is passed.

(crt1.o gets a dummy _dl_relocate_static_pie that interposes the one in
libc so no self-relocation is done in that case in __libc_start_main)

the Scrt1.o code is position independent but it relies on GOT entries that
need to be relocated which happens later and the static linker cannot relax
the GOT loads, so rcrt1.o needs separate implementation.

This implementation works with .text <= 4G files, which is fine, currently
the toolchain does not support larger position independent executables.

tests pass with ld/22269 and ld/22263 binutils bugs fixed.
this patch is on top of master but assumes the static pie patches.

2017-11-24  Szabolcs Nagy  <szabolcs.nagy@arm.com>

	* sysdeps/aarch64/start.S (_start): Handle PIC && !SHARED case.

diff --git a/sysdeps/aarch64/start.S b/sysdeps/aarch64/start.S
index c20433ad73..cd7ba7df3e 100644
--- a/sysdeps/aarch64/start.S
+++ b/sysdeps/aarch64/start.S
@@ -60,7 +60,8 @@ _start:
 	/* Setup stack limit in argument register */
 	mov	x6, sp
 
-#ifdef SHARED
+#ifdef PIC
+# ifdef SHARED
         adrp    x0, :got:main
 	ldr     PTR_REG (0), [x0, #:got_lo12:main]
 
@@ -69,6 +70,15 @@ _start:
 
         adrp    x4, :got:__libc_csu_fini
 	ldr     PTR_REG (4), [x4, #:got_lo12:__libc_csu_fini]
+
+# else
+	adrp	x0, main
+	add	x0, x0, :lo12:main
+	adrp	x3, __libc_csu_init
+	add	x3, x3, :lo12:__libc_csu_init
+	adrp	x4, __libc_csu_fini
+	add	x4, x4, :lo12:__libc_csu_fini
+# endif
 #else
 	/* Set up the other arguments in registers */
 	MOVL (0, main)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]