Skip to content

Commit

Permalink
Merge pull request #118 from kent-mcleod/stretch-linking-defaultpie
Browse files Browse the repository at this point in the history
Fix linking on Debian Stretch (gcc-6)
  • Loading branch information
kent-mcleod committed Feb 15, 2018
2 parents 8fe40c8 + b3c1033 commit 94bdf32
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 8 deletions.
1 change: 1 addition & 0 deletions app-tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 $$@
Expand Down
2 changes: 1 addition & 1 deletion app-tools/cc.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app-tools/cookfs.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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}')
Expand Down
3 changes: 2 additions & 1 deletion app-tools/rumprun-bake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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} \
Expand Down
8 changes: 8 additions & 0 deletions build-rr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,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 ()
Expand Down
3 changes: 3 additions & 0 deletions global.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ INSTALLDIR= ${RROBJ}/dest.stage
else
INSTALLDIR= ${RRDEST}
endif

cc-option = $(shell if [ -z "`echo 'int p=1;' | $(CC) $(1) -S -o /dev/null -x c - 2>&1`" ]; \
then echo y; else echo n; fi)
6 changes: 5 additions & 1 deletion platform/hw/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ SRCS+= intr.c clock_subr.c kernel.c multiboot.c undefs.c
include ../Makefile.inc
include arch/${ARCHDIR}/Makefile.inc

# Disable PIE, but need to check if compiler supports it
LDFLAGS-$(call cc-option,-no-pie) += -no-pie
LDFLAGS += $(LDFLAGS-y)

OBJS:= $(patsubst %.c,${RROBJ}/platform/%.o,${SRCS}) \
$(patsubst %.S,${RROBJ}/platform/%.o,${ASMS})

Expand All @@ -54,7 +58,7 @@ ${RROBJ}/platform/%.o: %.S
${CC} -D_LOCORE ${CPPFLAGS} ${CFLAGS} -c $< -o $@

${MAINOBJ}: ${OBJS} platformlibs
${CC} -nostdlib ${CFLAGS} -Wl,-r ${OBJS} -o $@ \
${CC} -nostdlib ${CFLAGS} ${LDFLAGS} -Wl,-r ${OBJS} -o $@ \
-L${RROBJLIB}/libbmk_core -L${RROBJLIB}/libbmk_rumpuser \
-Wl,--whole-archive -lbmk_rumpuser -lbmk_core -Wl,--no-whole-archive
${OBJCOPY} -w -G bmk_* -G rumpuser_* -G jsmn_* \
Expand Down
4 changes: 4 additions & 0 deletions platform/xen/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ default: prepare links mini-os ${MAINOBJ} ${TARGETS}
CPPFLAGS+= -isystem xen/include
CPPFLAGS+= -no-integrated-cpp

# Disable PIE, but need to check if compiler supports it
LDFLAGS-$(call cc-option,-no-pie) += -no-pie
LDFLAGS += $(LDFLAGS-y)

CFLAGS += -fno-builtin

rump-src-y += rumphyper_bio.c
Expand Down
4 changes: 3 additions & 1 deletion platform/xen/xen/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ LDARCHLIB := -l$(ARCH_LIB_NAME)
LDSCRIPT := $(TARGET_ARCH_DIR)/minios-$(XEN_TARGET_ARCH).lds
LDFLAGS_FINAL := -T $(LDSCRIPT)

LDFLAGS := -L$(abspath $(OBJ_DIR)/$(TARGET_ARCH_DIR))
# Disable PIE, but need to check if compiler supports it
LDFLAGS-$(call cc-option,-no-pie) += -no-pie
LDFLAGS := -L$(abspath $(OBJ_DIR)/$(TARGET_ARCH_DIR)) $(LDFLAGS-y)

# Prefixes for global API names. All other symbols in mini-os are localised
# before linking with rumprun applications.
Expand Down
5 changes: 3 additions & 2 deletions platform/xen/xen/minios.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ debug = y
# Define some default flags.
# NB. '-Wcast-qual' is nasty, so I omitted it.
DEF_CFLAGS += -fno-builtin -Wall -Werror -Wredundant-decls -Wno-format -Wno-redundant-decls
DEF_CFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
DEF_CFLAGS += $(call cc-option,$(CC),-fgnu89-inline)
DEF_CFLAGS-$(call cc-option,-fno-stack-protector) += -fno-stack-protector
DEF_CFLAGS-$(call cc-option,-fgnu89-inline) += -fgnu89-inline
DEF_CFLAGS += $(DEF_CFLAGS-y)
DEF_CFLAGS += -Wstrict-prototypes -Wnested-externs -Wpointer-arith -Winline
DEF_CPPFLAGS += -D__XEN_INTERFACE_VERSION__=$(XEN_INTERFACE_VERSION)

Expand Down

0 comments on commit 94bdf32

Please sign in to comment.