mirror of
git://git.yoctoproject.org/poky
synced 2026-09-08 22:11:05 +00:00
compiler can only use fortify options when some level of optimization is on, otherwise it ends up sending some warnings. warning: _FORTIFY_SOURCE requires compiling with optimization (-O) [-W#warnings] this is usually OK, since -O<level> would be added via CFLAGS to compiler cmdline in normal compile stages, however during configure there are problems when CC,CPP,CXX are probed alone in configure tests which results in above warning, which confuses the configure results and autotools 2.70+ detects it as error e.g. configure:17292: error: C preprocessor "riscv32-yoe-linux-clang -target riscv32-yoe-linux -mlittle-endian -mno-relax -Qunused-arguments -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/mnt/b/yoe/master/build/tmp/work/riscv32-yoe-linux/ndpi/3.4-r0/recipe-sysroot -E" fails sanity check See `config.log' for more details therefore adding a -O ( which actually is -O1 ) to lcl_maybe_fortify means we can properly test these configure tests and real -O<level> will still override -O added here, so overrall behavior improves (From OE-Core rev: b6113dd68caa46d56cf3c8293119f2b9d8b137fd) Signed-off-by: Khem Raj <raj.khem@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
70 lines
2.9 KiB
PHP
70 lines
2.9 KiB
PHP
# Setup extra CFLAGS and LDFLAGS which have 'security' benefits. These
|
|
# don't work universally, there are recipes which can't use one, the other
|
|
# or both so a blacklist is maintained here. The idea would be over
|
|
# time to reduce this list to nothing.
|
|
# From a Yocto Project perspective, this file is included and tested
|
|
# in the DISTRO="poky" configuration.
|
|
|
|
GCCPIE ?= "--enable-default-pie"
|
|
# If static PIE is known to work well, GLIBCPIE="--enable-static-pie" can be set
|
|
|
|
# _FORTIFY_SOURCE requires -O1 or higher, so disable in debug builds as they use
|
|
# -O0 which then results in a compiler warning.
|
|
lcl_maybe_fortify ?= "${@oe.utils.conditional('DEBUG_BUILD','1','','-O -D_FORTIFY_SOURCE=2',d)}"
|
|
|
|
# Error on use of format strings that represent possible security problems
|
|
SECURITY_STRINGFORMAT ?= "-Wformat -Wformat-security -Werror=format-security"
|
|
|
|
# Inject pie flags into compiler flags if not configured with gcc itself
|
|
# especially useful with external toolchains
|
|
SECURITY_PIE_CFLAGS ?= "${@'' if '${GCCPIE}' else '-pie -fPIE'}"
|
|
|
|
SECURITY_NOPIE_CFLAGS ?= "-no-pie -fno-PIE"
|
|
|
|
SECURITY_STACK_PROTECTOR ?= "-fstack-protector-strong"
|
|
|
|
SECURITY_CFLAGS ?= "${SECURITY_STACK_PROTECTOR} ${SECURITY_PIE_CFLAGS} ${lcl_maybe_fortify} ${SECURITY_STRINGFORMAT}"
|
|
SECURITY_NO_PIE_CFLAGS ?= "${SECURITY_STACK_PROTECTOR} ${lcl_maybe_fortify} ${SECURITY_STRINGFORMAT}"
|
|
|
|
SECURITY_LDFLAGS ?= "-Wl,-z,relro,-z,now"
|
|
SECURITY_X_LDFLAGS ?= "-Wl,-z,relro"
|
|
|
|
# powerpc does not get on with pie for reasons not looked into as yet
|
|
GCCPIE_powerpc = ""
|
|
GLIBCPIE_powerpc = ""
|
|
SECURITY_CFLAGS_remove_powerpc = "${SECURITY_PIE_CFLAGS}"
|
|
SECURITY_CFLAGS_pn-libgcc_powerpc = ""
|
|
|
|
SECURITY_CFLAGS_pn-glibc = ""
|
|
SECURITY_CFLAGS_pn-glibc-testsuite = ""
|
|
SECURITY_CFLAGS_pn-gcc-runtime = ""
|
|
SECURITY_CFLAGS_pn-grub = ""
|
|
SECURITY_CFLAGS_pn-grub-efi = ""
|
|
SECURITY_CFLAGS_pn-mkelfimage_x86 = ""
|
|
|
|
SECURITY_CFLAGS_pn-valgrind = "${SECURITY_NOPIE_CFLAGS}"
|
|
SECURITY_LDFLAGS_pn-valgrind = ""
|
|
SECURITY_CFLAGS_pn-sysklogd = "${SECURITY_NOPIE_CFLAGS}"
|
|
SECURITY_LDFLAGS_pn-sysklogd = ""
|
|
|
|
# Recipes which fail to compile when elevating -Wformat-security to an error
|
|
SECURITY_STRINGFORMAT_pn-busybox = ""
|
|
SECURITY_STRINGFORMAT_pn-gcc = ""
|
|
|
|
TARGET_CC_ARCH_append_class-target = " ${SECURITY_CFLAGS}"
|
|
TARGET_LDFLAGS_append_class-target = " ${SECURITY_LDFLAGS}"
|
|
TARGET_CC_ARCH_append_class-cross-canadian = " ${SECURITY_CFLAGS}"
|
|
TARGET_LDFLAGS_append_class-cross-canadian = " ${SECURITY_LDFLAGS}"
|
|
|
|
SECURITY_STACK_PROTECTOR_pn-gcc-runtime = ""
|
|
SECURITY_STACK_PROTECTOR_pn-glibc = ""
|
|
SECURITY_STACK_PROTECTOR_pn-glibc-testsuite = ""
|
|
# All xorg module drivers need to be linked this way as well and are
|
|
# handled in recipes-graphics/xorg-driver/xorg-driver-common.inc
|
|
SECURITY_LDFLAGS_pn-xserver-xorg = "${SECURITY_X_LDFLAGS}"
|
|
|
|
TARGET_CC_ARCH_append_pn-binutils = " ${SELECTED_OPTIMIZATION}"
|
|
TARGET_CC_ARCH_append_pn-gcc = " ${SELECTED_OPTIMIZATION}"
|
|
TARGET_CC_ARCH_append_pn-gdb = " ${SELECTED_OPTIMIZATION}"
|
|
TARGET_CC_ARCH_append_pn-perf = " ${SELECTED_OPTIMIZATION}"
|