Skip to content

Commit 94bdf32

Browse files
authored
Merge pull request #118 from kent-mcleod/stretch-linking-defaultpie
Fix linking on Debian Stretch (gcc-6)
2 parents 8fe40c8 + b3c1033 commit 94bdf32

10 files changed

Lines changed: 32 additions & 8 deletions

File tree

app-tools/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ ${TOOLOBJ}/${2}: ${1} Makefile ${TOOLOBJ}
8383
-e 's#!PLATFORM!#$(PLATFORM)#g;' \
8484
-e 's#!CPPFLAGS!#$(BUILDRUMP_TOOL_CPPFLAGS)#g;' \
8585
-e 's#!CFLAGS!#$(BUILDRUMP_TOOL_CFLAGS)#g;' \
86+
-e 's#!EXTRACCFLAGS!#$(EXTRACCFLAGS)#g;' \
8687
-e 's#!CXXFLAGS!#$(BUILDRUMP_TOOL_CXXFLAGS)#g;' \
8788
-e 's#!LDFLAGS_BAKE!#$(LDFLAGS_BAKE)#g;'
8889
chmod 755 $$@

app-tools/cc.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ ferment)
9696
${CC} ${CFLAGS} -no-integrated-cpp \
9797
--sysroot !DESTDIR!/rumprun-!MACHINE_GNU_ARCH! \
9898
-specs=!DESTDIR!/rumprun-!MACHINE_GNU_ARCH!/lib/specs-compile_or_ferment \
99-
-Wl,-r -Wl,-u,main \
99+
!EXTRACCFLAGS! -Wl,-r -Wl,-u,main \
100100
"$@" !DESTDIR!/rumprun-!MACHINE_GNU_ARCH!/share/!TOOLTUPLE!-recipe.s ${EXTRALIBS} || die
101101

102102
# If the presumed output file did not change, and the compiler

app-tools/cookfs.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ processonefile ()
164164
ln -sf -- "${fabs}" ${LINKPATH}
165165

166166
${RUMPRUN_COOKFS_CC} !CFLAGS! !CPPFLAGS! -nostdlib \
167-
-Wl,-r,-b,binary -o ${TMPDIR}/d${fn}.o ${LINKPATH}
167+
!EXTRACCFLAGS! -Wl,-r,-b,binary -o ${TMPDIR}/d${fn}.o ${LINKPATH}
168168

169169
${RUMPRUN_COOKFS_OBJCOPY} \
170170
--redefine-sym ${LINKPATH_BIN}_start=${rf}_start \
@@ -233,7 +233,7 @@ exec 1>&3 3>&-
233233
unset IFS
234234

235235
${RUMPRUN_COOKFS_CC} !CFLAGS! !CPPFLAGS! -I${RUMPRUN_COOKFS_INCDIR} \
236-
-nostdlib -Wl,-r -o ${TMPDIR}/fin.o ${TMPDIR}/d*.o ${TMPDIR}/constr.c
236+
-nostdlib !EXTRACCFLAGS! -Wl,-r -o ${TMPDIR}/fin.o ${TMPDIR}/d*.o ${TMPDIR}/constr.c
237237
${RUMPRUN_COOKFS_OBJCOPY} ${LSYM} ${TMPDIR}/fin.o ${OUTFILE}
238238

239239
totsize=$(${RUMPRUN_COOKFS_SIZE} ${OUTFILE} | awk 'NR == 2{print $4}')

app-tools/rumprun-bake.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,9 @@ done
397397

398398
MACHINE_GNU_ARCH=${RUMPBAKE_TUPLE%%-*}
399399

400+
400401
# Final link using cc to produce the unikernel image.
401-
${runcmd} ${RUMPBAKE_BACKINGCC} ${RUMPBAKE_CFLAGS} \
402+
${runcmd} ${RUMPBAKE_BACKINGCC} ${RUMPBAKE_CFLAGS} !EXTRACCFLAGS! \
402403
--sysroot ${RUMPBAKE_TOOLDIR}/rumprun-${MACHINE_GNU_ARCH} \
403404
-specs=${RUMPBAKE_TOOLDIR}/rumprun-${MACHINE_GNU_ARCH}/lib/rumprun-${PLATFORM}/specs-bake \
404405
-o ${OUTPUT} ${allobjs} \

build-rr.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,14 @@ makeconfig ()
500500
else
501501
echo "CONFIG_CXX=no" >> ${1}
502502
fi
503+
504+
# Check for if compiler supports -no-pie and save to EXTRACCFLAGS
505+
gccnopie=
506+
if [ -z "`echo 'int p=1;' | ${CC} -no-pie -S -o /dev/null -x c - 2>&1`" ]; then
507+
gccnopie=-no-pie
508+
fi
509+
echo "EXTRACCFLAGS=${quote}${gccnopie}${quote}" >> ${1}
510+
503511
}
504512

505513
dobuild ()

global.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ INSTALLDIR= ${RROBJ}/dest.stage
2323
else
2424
INSTALLDIR= ${RRDEST}
2525
endif
26+
27+
cc-option = $(shell if [ -z "`echo 'int p=1;' | $(CC) $(1) -S -o /dev/null -x c - 2>&1`" ]; \
28+
then echo y; else echo n; fi)

platform/hw/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ SRCS+= intr.c clock_subr.c kernel.c multiboot.c undefs.c
3131
include ../Makefile.inc
3232
include arch/${ARCHDIR}/Makefile.inc
3333

34+
# Disable PIE, but need to check if compiler supports it
35+
LDFLAGS-$(call cc-option,-no-pie) += -no-pie
36+
LDFLAGS += $(LDFLAGS-y)
37+
3438
OBJS:= $(patsubst %.c,${RROBJ}/platform/%.o,${SRCS}) \
3539
$(patsubst %.S,${RROBJ}/platform/%.o,${ASMS})
3640

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

5660
${MAINOBJ}: ${OBJS} platformlibs
57-
${CC} -nostdlib ${CFLAGS} -Wl,-r ${OBJS} -o $@ \
61+
${CC} -nostdlib ${CFLAGS} ${LDFLAGS} -Wl,-r ${OBJS} -o $@ \
5862
-L${RROBJLIB}/libbmk_core -L${RROBJLIB}/libbmk_rumpuser \
5963
-Wl,--whole-archive -lbmk_rumpuser -lbmk_core -Wl,--no-whole-archive
6064
${OBJCOPY} -w -G bmk_* -G rumpuser_* -G jsmn_* \

platform/xen/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ default: prepare links mini-os ${MAINOBJ} ${TARGETS}
2424
CPPFLAGS+= -isystem xen/include
2525
CPPFLAGS+= -no-integrated-cpp
2626

27+
# Disable PIE, but need to check if compiler supports it
28+
LDFLAGS-$(call cc-option,-no-pie) += -no-pie
29+
LDFLAGS += $(LDFLAGS-y)
30+
2731
CFLAGS += -fno-builtin
2832

2933
rump-src-y += rumphyper_bio.c

platform/xen/xen/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ LDARCHLIB := -l$(ARCH_LIB_NAME)
3333
LDSCRIPT := $(TARGET_ARCH_DIR)/minios-$(XEN_TARGET_ARCH).lds
3434
LDFLAGS_FINAL := -T $(LDSCRIPT)
3535

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

3840
# Prefixes for global API names. All other symbols in mini-os are localised
3941
# before linking with rumprun applications.

platform/xen/xen/minios.mk

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ debug = y
77
# Define some default flags.
88
# NB. '-Wcast-qual' is nasty, so I omitted it.
99
DEF_CFLAGS += -fno-builtin -Wall -Werror -Wredundant-decls -Wno-format -Wno-redundant-decls
10-
DEF_CFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
11-
DEF_CFLAGS += $(call cc-option,$(CC),-fgnu89-inline)
10+
DEF_CFLAGS-$(call cc-option,-fno-stack-protector) += -fno-stack-protector
11+
DEF_CFLAGS-$(call cc-option,-fgnu89-inline) += -fgnu89-inline
12+
DEF_CFLAGS += $(DEF_CFLAGS-y)
1213
DEF_CFLAGS += -Wstrict-prototypes -Wnested-externs -Wpointer-arith -Winline
1314
DEF_CPPFLAGS += -D__XEN_INTERFACE_VERSION__=$(XEN_INTERFACE_VERSION)
1415

0 commit comments

Comments
 (0)