From bef017f5fe7f65491f7efb3c6217e96823f9649e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Tue, 26 Apr 2016 08:20:20 +0200 Subject: build: try to produce a statically linked position independent executable In theory this should be as simple as: $ cc -fPIE -pie --static helloworld.c But unfortunately by default this will always add a PT_INTERP referencing the dynamic loader/linker. On latest binutils >=2.26 this can be worked around by supplying --no-dynamic-linker. Also tweak the musl-gcc wrapper to use rcrt1.o as startup file. --- GNUmakefile | 2 ++ 1 file changed, 2 insertions(+) (limited to 'GNUmakefile') diff --git a/GNUmakefile b/GNUmakefile index 015ca92..99a2f75 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -51,6 +51,8 @@ dependency/build/libmusl-extract: dependency/sources/$(LIBMUSL).tar.gz | depende touch $@ dependency/build/libmusl-configure: dependency/build/libmusl-extract + # tweak musl gcc wrapper/spec file to support static PIE linking + sed -i 's#%{pie:S}crt1.o#%{pie:%{static:rcrt1.o%s;:Scrt1.o%s};:crt1.o%s}#' $(dir $<)/$(LIBMUSL)/tools/musl-gcc.specs.sh cd $(dir $<)/$(LIBMUSL) && ./configure --prefix=$(DEPS_PREFIX) --syslibdir=$(DEPS_PREFIX)/lib touch $@ -- cgit v1.2.3