From b3c1033b090b65e8e86999ddd063c174502aa3f0 Mon Sep 17 00:00:00 2001 From: Kent McLeod Date: Wed, 14 Feb 2018 16:43:16 +1100 Subject: [PATCH] Add further -no-pie checks to Rumprun build tools This builds upon the previous commit to add -no-pie anywhere the relocatable flag (-Wl,-r) is used to handle compilers that enable -pie by default (Such as Debian Stretch). --- app-tools/Makefile | 1 + app-tools/cc.in | 2 +- app-tools/cookfs.in | 4 ++-- app-tools/rumprun-bake.in | 3 ++- build-rr.sh | 8 ++++++++ 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app-tools/Makefile b/app-tools/Makefile index beb39b817..e355e0584 100644 --- a/app-tools/Makefile +++ b/app-tools/Makefile @@ -83,6 +83,7 @@ ${TOOLOBJ}/${2}: ${1} Makefile ${TOOLOBJ} -e 's#!PLATFORM!#$(PLATFORM)#g;' \ -e 's#!CPPFLAGS!#$(BUILDRUMP_TOOL_CPPFLAGS)#g;' \ -e 's#!CFLAGS!#$(BUILDRUMP_TOOL_CFLAGS)#g;' \ + -e 's#!EXTRACCFLAGS!#$(EXTRACCFLAGS)#g;' \ -e 's#!CXXFLAGS!#$(BUILDRUMP_TOOL_CXXFLAGS)#g;' \ -e 's#!LDFLAGS_BAKE!#$(LDFLAGS_BAKE)#g;' chmod 755 $$@ diff --git a/app-tools/cc.in b/app-tools/cc.in index ef0db9a2d..4ea20a847 100644 --- a/app-tools/cc.in +++ b/app-tools/cc.in @@ -96,7 +96,7 @@ ferment) ${CC} ${CFLAGS} -no-integrated-cpp \ --sysroot !DESTDIR!/rumprun-!MACHINE_GNU_ARCH! \ -specs=!DESTDIR!/rumprun-!MACHINE_GNU_ARCH!/lib/specs-compile_or_ferment \ - -Wl,-r -Wl,-u,main \ + !EXTRACCFLAGS! -Wl,-r -Wl,-u,main \ "$@" !DESTDIR!/rumprun-!MACHINE_GNU_ARCH!/share/!TOOLTUPLE!-recipe.s ${EXTRALIBS} || die # If the presumed output file did not change, and the compiler diff --git a/app-tools/cookfs.in b/app-tools/cookfs.in index 4972b3fd8..16d8b2bc5 100644 --- a/app-tools/cookfs.in +++ b/app-tools/cookfs.in @@ -164,7 +164,7 @@ processonefile () ln -sf -- "${fabs}" ${LINKPATH} ${RUMPRUN_COOKFS_CC} !CFLAGS! !CPPFLAGS! -nostdlib \ - -Wl,-r,-b,binary -o ${TMPDIR}/d${fn}.o ${LINKPATH} + !EXTRACCFLAGS! -Wl,-r,-b,binary -o ${TMPDIR}/d${fn}.o ${LINKPATH} ${RUMPRUN_COOKFS_OBJCOPY} \ --redefine-sym ${LINKPATH_BIN}_start=${rf}_start \ @@ -233,7 +233,7 @@ exec 1>&3 3>&- unset IFS ${RUMPRUN_COOKFS_CC} !CFLAGS! !CPPFLAGS! -I${RUMPRUN_COOKFS_INCDIR} \ - -nostdlib -Wl,-r -o ${TMPDIR}/fin.o ${TMPDIR}/d*.o ${TMPDIR}/constr.c + -nostdlib !EXTRACCFLAGS! -Wl,-r -o ${TMPDIR}/fin.o ${TMPDIR}/d*.o ${TMPDIR}/constr.c ${RUMPRUN_COOKFS_OBJCOPY} ${LSYM} ${TMPDIR}/fin.o ${OUTFILE} totsize=$(${RUMPRUN_COOKFS_SIZE} ${OUTFILE} | awk 'NR == 2{print $4}') diff --git a/app-tools/rumprun-bake.in b/app-tools/rumprun-bake.in index b43195a2f..3d82bae27 100644 --- a/app-tools/rumprun-bake.in +++ b/app-tools/rumprun-bake.in @@ -397,8 +397,9 @@ done MACHINE_GNU_ARCH=${RUMPBAKE_TUPLE%%-*} + # Final link using cc to produce the unikernel image. -${runcmd} ${RUMPBAKE_BACKINGCC} ${RUMPBAKE_CFLAGS} \ +${runcmd} ${RUMPBAKE_BACKINGCC} ${RUMPBAKE_CFLAGS} !EXTRACCFLAGS! \ --sysroot ${RUMPBAKE_TOOLDIR}/rumprun-${MACHINE_GNU_ARCH} \ -specs=${RUMPBAKE_TOOLDIR}/rumprun-${MACHINE_GNU_ARCH}/lib/rumprun-${PLATFORM}/specs-bake \ -o ${OUTPUT} ${allobjs} \ diff --git a/build-rr.sh b/build-rr.sh index e361c327d..832a9176a 100755 --- a/build-rr.sh +++ b/build-rr.sh @@ -493,6 +493,14 @@ makeconfig () else echo "CONFIG_CXX=no" >> ${1} fi + + # Check for if compiler supports -no-pie and save to EXTRACCFLAGS + gccnopie= + if [ -z "`echo 'int p=1;' | ${CC} -no-pie -S -o /dev/null -x c - 2>&1`" ]; then + gccnopie=-no-pie + fi + echo "EXTRACCFLAGS=${quote}${gccnopie}${quote}" >> ${1} + } dobuild ()