--- a/Makefile 2016-10-01 18:59:31.920283338 +0200 +++ b/Makefile 2016-10-04 22:21:06.056623037 +0200 @@ -688,6 +684,12 @@ endif endif KBUILD_CFLAGS += $(stackp-flag) +# Check if compiler default to -fPIE/-fpie +ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-default-pie.sh $(CC)), y) + KBUILD_CFLAGS += -fno-PIE + KBUILD_AFLAGS += -fno-PIE +endif + ifdef CONFIG_KCOV ifeq ($(call cc-option, $(CFLAGS_KCOV)),) $(warning Cannot use CONFIG_KCOV: \ --- a/scripts/gcc-default-pie.sh 2016-10-04 22:42:53.676653594 +0200 +++ b/scripts/gcc-default-pie.sh 2016-10-04 22:03:43.816598681 +0200 @@ -0,0 +1,13 @@ +#!/bin/sh +# Test if gcc default to -fPIE/-fpie +# Copyright (C) 2016, Magnus Granberg + +cat << "END" | $@ -x c - -c -o /dev/null >/dev/null 2>&1 && echo "y" +int main(void) +{ +#if !(defined(__PIE__) || defined(__pie__)) +#error "Compiler don't default to PIE" +#endif + return 0; +} +END