From dc031ee0b1ba11baa00cd7f0769e461a5f396c71 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Tue, 26 May 2015 03:37:41 -0400 Subject: add rcrt1 start file for fully static-linked PIE static-linked PIE files need startup code to relocate themselves, much like the dynamic linker does. rcrt1.c reuses the code in dlstart.c, stage 1 of the dynamic linker, which in turn reuses crt_arch.h, to achieve static PIE with no new code. only relative relocations are supported. existing toolchains that don't yet support static PIE directly can be repurposed by passing "-shared -Wl,-Bstatic -Wl,-Bsymbolic" instead of "-static -pie" and substituting rcrt1.o in place of crt1.o. all libraries being linked must be built as PIC/PIE; TEXTRELs are not supported at this time. --- crt/rcrt1.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 crt/rcrt1.c (limited to 'crt') diff --git a/crt/rcrt1.c b/crt/rcrt1.c new file mode 100644 index 00000000..5ac612db --- /dev/null +++ b/crt/rcrt1.c @@ -0,0 +1,15 @@ +#define SHARED +#define START "_start" +#define _dlstart_c _start_c +#include "../src/ldso/dlstart.c" + +int main(); +void _init() __attribute__((weak)); +void _fini() __attribute__((weak)); +_Noreturn int __libc_start_main(int (*)(), int, char **, + void (*)(), void(*)(), void(*)()); + +_Noreturn void __dls2(unsigned char *base, size_t *sp) +{ + __libc_start_main(main, *sp, (void *)(sp+1), _init, _fini, 0); +} -- cgit v1.2.1