Skip to content

Commit

Permalink
Add further -no-pie checks to Rumprun build tools
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
kent-mcleod committed Feb 14, 2018
1 parent 35d8119 commit 786946c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 5 additions & 1 deletion app-tools/cc.in
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,18 @@ compile)
;;
ferment)
meta1="$(${PRMETA} "${OUTFILE}" 2>/dev/null)"
nopieoption=
if [ -z "`echo 'int p=1;' | ${CC} -no-pie -S -o /dev/null -x c - 2>&1`" ]; then
nopieoption=-no-pie
fi

# Link the real (from user's PoV) output file as a relocatable object,
# with no rump components. '-u main' is necessary to pull in main if the
# user is linking it in from a library.
${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 \
${nopieoption} -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
Expand Down
9 changes: 7 additions & 2 deletions app-tools/cookfs.in
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ setfilevars ()
rf=_rumpfs_f${fn}
}

nopieoption=
if [ -z "`echo 'int p=1;' | ${RUMPRUN_COOKFS_CC} -no-pie -S -o /dev/null -x c - 2>&1`" ]; then
nopieoption=-no-pie
fi

processonefile ()
{

Expand All @@ -164,7 +169,7 @@ processonefile ()
ln -sf -- "${fabs}" ${LINKPATH}

${RUMPRUN_COOKFS_CC} !CFLAGS! !CPPFLAGS! -nostdlib \
-Wl,-r,-b,binary -o ${TMPDIR}/d${fn}.o ${LINKPATH}
${nopieoption} -Wl,-r,-b,binary -o ${TMPDIR}/d${fn}.o ${LINKPATH}

${RUMPRUN_COOKFS_OBJCOPY} \
--redefine-sym ${LINKPATH_BIN}_start=${rf}_start \
Expand Down Expand Up @@ -233,7 +238,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 ${nopieoption} -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}')
Expand Down
7 changes: 6 additions & 1 deletion app-tools/rumprun-bake.in
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,13 @@ done

MACHINE_GNU_ARCH=${RUMPBAKE_TUPLE%%-*}

nopieoption=
if [ -z "`echo 'int p=1;' | ${RUMPBAKE_BACKINGCC} -no-pie -S -o /dev/null -x c - 2>&1`" ]; then
nopieoption=-no-pie
fi

# Final link using cc to produce the unikernel image.
${runcmd} ${RUMPBAKE_BACKINGCC} ${RUMPBAKE_CFLAGS} \
${runcmd} ${RUMPBAKE_BACKINGCC} ${RUMPBAKE_CFLAGS} ${nopieoption} \
--sysroot ${RUMPBAKE_TOOLDIR}/rumprun-${MACHINE_GNU_ARCH} \
-specs=${RUMPBAKE_TOOLDIR}/rumprun-${MACHINE_GNU_ARCH}/lib/rumprun-${PLATFORM}/specs-bake \
-o ${OUTPUT} ${allobjs} \
Expand Down

0 comments on commit 786946c

Please sign in to comment.