kbuild: remove cc-option test of -fno-stack-protector
Subsystems (22)
PATCH 1/2 kbuild: remove cc-option test of -fno-stack-protector
Some Makefiles already pass -fno-stack-protector unconditionally. For example, arch/arm64/kernel/vdso/Makefile, arch/x86/xen/Makefile. No problem report so far about hard-coding this option. So, we can assume all supported compilers know -fno-stack-protector.
GCC 4.8 and Clang support this option (https://godbolt.org/z/_HDGzN)
Get rid of cc-option from -fno-stack-protector.
Remove CONFIG_CC_HAS_STACKPROTECTOR_NONE, which should always be 'y'.
Note:arch/mips/vdso/Makefile adds -fno-stack-protector twice, first unconditionally, and second conditionally. I removed the second one.
---
Documentation/kbuild/kconfig-language.rst | 4 ++-- Makefile | 2 +- arch/Kconfig | 3 --- arch/arm/boot/compressed/Makefile | 3 +-- arch/mips/vdso/Makefile | 3 +-- arch/powerpc/kernel/Makefile | 2 +- arch/powerpc/platforms/powermac/Makefile | 2 +- arch/sparc/vdso/Makefile | 4 ++-- arch/um/Makefile | 3 +-- arch/x86/Makefile | 2 +- arch/x86/boot/compressed/Makefile | 2 +- arch/x86/entry/vdso/Makefile | 4 ++-- arch/x86/kernel/cpu/Makefile | 3 +-- arch/x86/lib/Makefile | 2 +- arch/x86/mm/Makefile | 7 +++---- arch/x86/power/Makefile | 3 +-- arch/x86/purgatory/Makefile | 2 +- arch/x86/um/vdso/Makefile | 2 +- arch/x86/xen/Makefile | 5 ++--- drivers/firmware/efi/libstub/Makefile | 2 +- drivers/xen/Makefile | 3 +-- kernel/kcsan/Makefile | 3 +-- lib/Makefile | 4 ++-- mm/kasan/Makefile | 2 +- 24 files changed, 30 insertions(+), 42 deletions(-)
Documentation/kbuild/kconfig-language.rst +2 -2
@@ -540,8 +540,8 @@ followed by a test macro:: If you need to expose a compiler capability to makefiles and/or C source files, `CC_HAS_` is the recommended prefix for the config option:: - config CC_HAS_STACKPROTECTOR_NONE - def_bool $(cc-option,-fno-stack-protector) + config CC_HAS_ASM_GOTO + def_bool $(success,$(srctree)/scripts/gcc-goto.sh $(CC)) Build as module only ~~~~~~~~~~~~~~~~~~~~
Makefile +1 -1
@@ -762,7 +762,7 @@ ifneq ($(CONFIG_FRAME_WARN),0) KBUILD_CFLAGS += -Wframe-larger-than=$(CONFIG_FRAME_WARN) endif -stackp-flags-$(CONFIG_CC_HAS_STACKPROTECTOR_NONE) := -fno-stack-protector +stackp-flags-y := -fno-stack-protector stackp-flags-$(CONFIG_STACKPROTECTOR) := -fstack-protector stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strong
arch/Kconfig +0 -3
@@ -478,9 +478,6 @@ config HAVE_STACKPROTECTOR An arch should select this symbol if: - it has implemented a stack canary (e.g. __stack_chk_guard) -config CC_HAS_STACKPROTECTOR_NONE - def_bool $(cc-option,-fno-stack-protector) - config STACKPROTECTOR bool "Stack Protector buffer overflow detection" depends on HAVE_STACKPROTECTOR
arch/arm/boot/compressed/Makefile +1 -2
@@ -84,9 +84,8 @@ endif # -fstack-protector-strong triggers protection checks in this code, # but it is being used too early to link to meaningful stack_chk logic. -nossp-flags-$(CONFIG_CC_HAS_STACKPROTECTOR_NONE) := -fno-stack-protector $(foreach o, $(libfdt_objs) atags_to_fdt.o, \ - $(eval CFLAGS_$(o) := -I $(srctree)/scripts/dtc/libfdt $(nossp-flags-y))) + $(eval CFLAGS_$(o) := -I $(srctree)/scripts/dtc/libfdt -fno-stack-protector)) # These were previously generated C files. When you are building the kernel # with O=, make sure to remove the stale files in the output tree. Otherwise,
arch/mips/vdso/Makefile +1 -2
@@ -35,8 +35,7 @@ cflags-vdso := $(ccflags-vdso) \ -O3 -g -fPIC -fno-strict-aliasing -fno-common -fno-builtin -G 0 \ -mrelax-pic-calls $(call cc-option, -mexplicit-relocs) \ -fno-stack-protector -fno-jump-tables -DDISABLE_BRANCH_PROFILING \ - $(call cc-option, -fno-asynchronous-unwind-tables) \ - $(call cc-option, -fno-stack-protector) + $(call cc-option, -fno-asynchronous-unwind-tables) aflags-vdso := $(ccflags-vdso) \ -D__ASSEMBLY__ -Wa,-gdwarf-2
arch/powerpc/kernel/Makefile +1 -1
@@ -16,7 +16,7 @@ CFLAGS_prom_init.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) CFLAGS_btext.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) CFLAGS_prom.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) -CFLAGS_prom_init.o += $(call cc-option, -fno-stack-protector) +CFLAGS_prom_init.o += -fno-stack-protector CFLAGS_prom_init.o += -DDISABLE_BRANCH_PROFILING CFLAGS_prom_init.o += -ffreestanding
arch/powerpc/platforms/powermac/Makefile +1 -1
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 CFLAGS_bootx_init.o += -fPIC -CFLAGS_bootx_init.o += $(call cc-option, -fno-stack-protector) +CFLAGS_bootx_init.o += -fno-stack-protector KASAN_SANITIZE_bootx_init.o := n
arch/sparc/vdso/Makefile +2 -2
@@ -54,7 +54,7 @@ $(obj)/vdso-image-%.c: $(obj)/vdso%.so.dbg $(obj)/vdso%.so $(obj)/vdso2c FORCE # optimize sibling calls. # CFL := $(PROFILING) -mcmodel=medlow -fPIC -O2 -fasynchronous-unwind-tables -m64 \ - $(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \ + $(filter -g%,$(KBUILD_CFLAGS)) -fno-stack-protector \ -fno-omit-frame-pointer -foptimize-sibling-calls \ -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO
@@ -93,7 +93,7 @@ KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(SPARC_REG_CFLAGS),$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 += -m32 -msoft-float -fpic -KBUILD_CFLAGS_32 += $(call cc-option, -fno-stack-protector) +KBUILD_CFLAGS_32 += -fno-stack-protector KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls) KBUILD_CFLAGS_32 += -fno-omit-frame-pointer KBUILD_CFLAGS_32 += -DDISABLE_BRANCH_PROFILING
arch/um/Makefile +1 -2
@@ -121,8 +121,7 @@ LINK-$(CONFIG_LD_SCRIPT_STATIC) += -static LINK-$(CONFIG_LD_SCRIPT_DYN) += -Wl,-rpath,/lib $(call cc-option, -no-pie) CFLAGS_NO_HARDENING := $(call cc-option, -fno-PIC,) $(call cc-option, -fno-pic,) \ - $(call cc-option, -fno-stack-protector,) \ - $(call cc-option, -fno-stack-protector-all,) + -fno-stack-protector $(call cc-option, -fno-stack-protector-all) # Options used by linker script export LDS_START := $(START)
arch/x86/Makefile +1 -1
@@ -37,7 +37,7 @@ REALMODE_CFLAGS := $(M16_CFLAGS) -g -Os -DDISABLE_BRANCH_PROFILING \ -mno-mmx -mno-sse REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -ffreestanding) -REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -fno-stack-protector) +REALMODE_CFLAGS += -fno-stack-protector REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -Wno-address-of-packed-member) REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), $(cc_stack_align4)) export REALMODE_CFLAGS
arch/x86/boot/compressed/Makefile +1 -1
@@ -36,7 +36,7 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small KBUILD_CFLAGS += $(cflags-y) KBUILD_CFLAGS += -mno-mmx -mno-sse KBUILD_CFLAGS += $(call cc-option,-ffreestanding) -KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector) +KBUILD_CFLAGS += -fno-stack-protector KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) KBUILD_CFLAGS += $(call cc-disable-warning, gnu) KBUILD_CFLAGS += -Wno-pointer-sign
arch/x86/entry/vdso/Makefile +2 -2
@@ -82,7 +82,7 @@ $(obj)/vdso-image-%.c: $(obj)/vdso%.so.dbg $(obj)/vdso%.so $(obj)/vdso2c FORCE # optimize sibling calls. # CFL := $(PROFILING) -mcmodel=small -fPIC -O2 -fasynchronous-unwind-tables -m64 \ - $(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \ + $(filter -g%,$(KBUILD_CFLAGS)) -fno-stack-protector \ -fno-omit-frame-pointer -foptimize-sibling-calls \ -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO
@@ -151,7 +151,7 @@ KBUILD_CFLAGS_32 := $(filter-out -mfentry,$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 += -m32 -msoft-float -mregparm=0 -fpic -KBUILD_CFLAGS_32 += $(call cc-option, -fno-stack-protector) +KBUILD_CFLAGS_32 += -fno-stack-protector KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls) KBUILD_CFLAGS_32 += -fno-omit-frame-pointer KBUILD_CFLAGS_32 += -DDISABLE_BRANCH_PROFILING
arch/x86/kernel/cpu/Makefile +1 -2
@@ -17,8 +17,7 @@ KCOV_INSTRUMENT_perf_event.o := n KCSAN_SANITIZE_common.o := n # Make sure load_percpu_segment has no stackprotector -nostackp := $(call cc-option, -fno-stack-protector) -CFLAGS_common.o := $(nostackp) +CFLAGS_common.o := -fno-stack-protector obj-y := cacheinfo.o scattered.o topology.o obj-y += common.o
arch/x86/lib/Makefile +1 -1
@@ -24,7 +24,7 @@ ifdef CONFIG_FUNCTION_TRACER CFLAGS_REMOVE_cmdline.o = -pg endif -CFLAGS_cmdline.o := $(call cc-option, -fno-stack-protector) +CFLAGS_cmdline.o := -fno-stack-protector endif inat_tables_script = $(srctree)/arch/x86/tools/gen-insn-attr-x86.awk
arch/x86/mm/Makefile +3 -4
@@ -22,10 +22,9 @@ obj-y := init.o init_$(BITS).o fault.o ioremap.o extable.o mmap.o \ obj-y += pat/ # Make sure __phys_addr has no stackprotector -nostackp := $(call cc-option, -fno-stack-protector) -CFLAGS_physaddr.o := $(nostackp) -CFLAGS_setup_nx.o := $(nostackp) -CFLAGS_mem_encrypt_identity.o := $(nostackp) +CFLAGS_physaddr.o := -fno-stack-protector +CFLAGS_setup_nx.o := -fno-stack-protector +CFLAGS_mem_encrypt_identity.o := -fno-stack-protector CFLAGS_fault.o := -I $(srctree)/$(src)/../include/asm/trace
arch/x86/power/Makefile +1 -2
@@ -3,8 +3,7 @@ OBJECT_FILES_NON_STANDARD_hibernate_asm_$(BITS).o := y # __restore_processor_state() restores %gs after S3 resume and so should not # itself be stack-protected -nostackp := $(call cc-option, -fno-stack-protector) -CFLAGS_cpu.o := $(nostackp) +CFLAGS_cpu.o := -fno-stack-protector obj-$(CONFIG_PM_SLEEP) += cpu.o obj-$(CONFIG_HIBERNATION) += hibernate_$(BITS).o hibernate_asm_$(BITS).o hibernate.o
arch/x86/purgatory/Makefile +1 -1
@@ -34,7 +34,7 @@ KCOV_INSTRUMENT := n PURGATORY_CFLAGS_REMOVE := -mcmodel=kernel PURGATORY_CFLAGS := -mcmodel=large -ffreestanding -fno-zero-initialized-in-bss PURGATORY_CFLAGS += $(DISABLE_STACKLEAK_PLUGIN) -DDISABLE_BRANCH_PROFILING -PURGATORY_CFLAGS += $(call cc-option,-fno-stack-protector) +PURGATORY_CFLAGS += -fno-stack-protector # Default KBUILD_CFLAGS can have -pg option set when FTRACE is enabled. That # in turn leaves some undefined symbols like __fentry__ in purgatory and not
arch/x86/um/vdso/Makefile +1 -1
@@ -42,7 +42,7 @@ $(obj)/%.so: $(obj)/%.so.dbg FORCE # optimize sibling calls. # CFL := $(PROFILING) -mcmodel=small -fPIC -O2 -fasynchronous-unwind-tables -m64 \ - $(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \ + $(filter -g%,$(KBUILD_CFLAGS)) -fno-stack-protector \ -fno-omit-frame-pointer -foptimize-sibling-calls $(vobjs): KBUILD_CFLAGS += $(CFL)
arch/x86/xen/Makefile +2 -3
@@ -9,9 +9,8 @@ CFLAGS_REMOVE_irq.o = -pg endif # Make sure early boot has no stackprotector -nostackp := $(call cc-option, -fno-stack-protector) -CFLAGS_enlighten_pv.o := $(nostackp) -CFLAGS_mmu_pv.o := $(nostackp) +CFLAGS_enlighten_pv.o := -fno-stack-protector +CFLAGS_mmu_pv.o := -fno-stack-protector obj-y += enlighten.o obj-y += mmu.o
drivers/firmware/efi/libstub/Makefile +1 -1
@@ -29,7 +29,7 @@ KBUILD_CFLAGS := $(cflags-y) -Os -DDISABLE_BRANCH_PROFILING \ -include $(srctree)/drivers/firmware/efi/libstub/hidden.h \ -D__NO_FORTIFY \ $(call cc-option,-ffreestanding) \ - $(call cc-option,-fno-stack-protector) \ + -fno-stack-protector \ $(call cc-option,-fno-addrsig) \ -D__DISABLE_EXPORTS
drivers/xen/Makefile +1 -2
@@ -5,8 +5,7 @@ obj-y += mem-reservation.o obj-y += events/ obj-y += xenbus/ -nostackp := $(call cc-option, -fno-stack-protector) -CFLAGS_features.o := $(nostackp) +CFLAGS_features.o := -fno-stack-protector dom0-$(CONFIG_ARM64) += arm-device.o dom0-$(CONFIG_PCI) += pci.o
kernel/kcsan/Makefile +1 -2
@@ -7,8 +7,7 @@ CFLAGS_REMOVE_core.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_debugfs.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_report.o = $(CC_FLAGS_FTRACE) -CFLAGS_core.o := $(call cc-option,-fno-conserve-stack,) \ - $(call cc-option,-fno-stack-protector,) +CFLAGS_core.o := $(call cc-option,-fno-conserve-stack,) -fno-stack-protector obj-y := core.o debugfs.o report.o obj-$(CONFIG_KCSAN_SELFTEST) += test.o
lib/Makefile +2 -2
@@ -22,7 +22,7 @@ KCOV_INSTRUMENT_fault-inject.o := n ifdef CONFIG_AMD_MEM_ENCRYPT KASAN_SANITIZE_string.o := n -CFLAGS_string.o := $(call cc-option, -fno-stack-protector) +CFLAGS_string.o := -fno-stack-protector endif # Used by KCSAN while enabled, avoid recursion.
@@ -300,7 +300,7 @@ endif UBSAN_SANITIZE_ubsan.o := n KASAN_SANITIZE_ubsan.o := n KCSAN_SANITIZE_ubsan.o := n -CFLAGS_ubsan.o := $(call cc-option, -fno-stack-protector) $(DISABLE_STACKLEAK_PLUGIN) +CFLAGS_ubsan.o := -fno-stack-protector $(DISABLE_STACKLEAK_PLUGIN) obj-$(CONFIG_SBITMAP) += sbitmap.o
mm/kasan/Makefile +1 -1
@@ -16,7 +16,7 @@ CFLAGS_REMOVE_tags_report.o = $(CC_FLAGS_FTRACE) # Function splitter causes unnecessary splits in __asan_load1/__asan_store1 # see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63533 CC_FLAGS_KASAN_RUNTIME := $(call cc-option, -fno-conserve-stack) -CC_FLAGS_KASAN_RUNTIME += $(call cc-option, -fno-stack-protector) +CC_FLAGS_KASAN_RUNTIME += -fno-stack-protector # Disable branch tracing to avoid recursion. CC_FLAGS_KASAN_RUNTIME += -DDISABLE_BRANCH_PROFILING
Signature · 1 line
2.25.1
PATCH 2/2 kbuild: remove cc-option test of -ffreestanding
Some Makefiles already pass -ffreestanding unconditionally. For example, arch/arm64/lib/Makefile, arch/x86/purgatory/Makefile. No problem report so far about hard-coding this option. So, we can assume all supported compilers know -ffreestanding.
I confirmed GCC 4.8 and Clang manuals document this option.
Get rid of cc-option from -ffreestanding.
---
arch/s390/Makefile | 2 +- arch/x86/Makefile | 2 +- arch/x86/boot/compressed/Makefile | 2 +- drivers/firmware/efi/libstub/Makefile | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
arch/s390/Makefile +1 -1
@@ -27,7 +27,7 @@ KBUILD_CFLAGS_DECOMPRESSOR := $(CLANG_FLAGS) -m64 -O2 KBUILD_CFLAGS_DECOMPRESSOR += -DDISABLE_BRANCH_PROFILING -D__NO_FORTIFY KBUILD_CFLAGS_DECOMPRESSOR += -fno-delete-null-pointer-checks -msoft-float KBUILD_CFLAGS_DECOMPRESSOR += -fno-asynchronous-unwind-tables -KBUILD_CFLAGS_DECOMPRESSOR += $(call cc-option,-ffreestanding) +KBUILD_CFLAGS_DECOMPRESSOR += -ffreestanding KBUILD_CFLAGS_DECOMPRESSOR += $(call cc-disable-warning, address-of-packed-member) KBUILD_CFLAGS_DECOMPRESSOR += $(if $(CONFIG_DEBUG_INFO),-g) KBUILD_CFLAGS_DECOMPRESSOR += $(if $(CONFIG_DEBUG_INFO_DWARF4), $(call cc-option, -gdwarf-4,))
arch/x86/Makefile +1 -1
@@ -36,7 +36,7 @@ REALMODE_CFLAGS := $(M16_CFLAGS) -g -Os -DDISABLE_BRANCH_PROFILING \ -fno-strict-aliasing -fomit-frame-pointer -fno-pic \ -mno-mmx -mno-sse -REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -ffreestanding) +REALMODE_CFLAGS += -ffreestanding REALMODE_CFLAGS += -fno-stack-protector REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -Wno-address-of-packed-member) REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), $(cc_stack_align4))
arch/x86/boot/compressed/Makefile +1 -1
@@ -35,7 +35,7 @@ cflags-$(CONFIG_X86_32) := -march=i386 cflags-$(CONFIG_X86_64) := -mcmodel=small KBUILD_CFLAGS += $(cflags-y) KBUILD_CFLAGS += -mno-mmx -mno-sse -KBUILD_CFLAGS += $(call cc-option,-ffreestanding) +KBUILD_CFLAGS += -ffreestanding KBUILD_CFLAGS += -fno-stack-protector KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) KBUILD_CFLAGS += $(call cc-disable-warning, gnu)
drivers/firmware/efi/libstub/Makefile +1 -1
@@ -28,7 +28,7 @@ cflags-$(CONFIG_EFI_GENERIC_STUB) += -I$(srctree)/scripts/dtc/libfdt KBUILD_CFLAGS := $(cflags-y) -Os -DDISABLE_BRANCH_PROFILING \ -include $(srctree)/drivers/firmware/efi/libstub/hidden.h \ -D__NO_FORTIFY \ - $(call cc-option,-ffreestanding) \ + -ffreestanding \ -fno-stack-protector \ $(call cc-option,-fno-addrsig) \ -D__DISABLE_EXPORTS
Signature · 1 line
2.25.1
Re: [PATCH 2/2] kbuild: remove cc-option test of -ffreestanding
Quoted 11 lines · Masahiro Yamada
Some Makefiles already pass -ffreestanding unconditionally. For example,
arch/arm64/lib/Makefile,arch/x86/purgatory/Makefile. No problem report so far about hard-coding this option. So, we can assume all supported compilers know -ffreestanding.I confirmed GCC 4.8 and Clang manuals document this option.
Get rid of cc-option from -ffreestanding.
Signed-off-by Masahiro Yamada <[email protected]>
Quoted 26 lines
---
arch/s390/Makefile | 2 +- arch/x86/Makefile | 2 +- arch/x86/boot/compressed/Makefile | 2 +- drivers/firmware/efi/libstub/Makefile | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)arch/s390/Makefile +1
-1@@ -27,7 +27,7 @@ KBUILD_CFLAGS_DECOMPRESSOR := $(CLANG_FLAGS) -m64 -O2 KBUILD_CFLAGS_DECOMPRESSOR += -DDISABLE_BRANCH_PROFILING -D__NO_FORTIFY KBUILD_CFLAGS_DECOMPRESSOR += -fno-delete-null-pointer-checks -msoft-float KBUILD_CFLAGS_DECOMPRESSOR += -fno-asynchronous-unwind-tables -KBUILD_CFLAGS_DECOMPRESSOR += $(call cc-option,-ffreestanding) +KBUILD_CFLAGS_DECOMPRESSOR += -ffreestanding KBUILD_CFLAGS_DECOMPRESSOR += $(call cc-disable-warning, address-of-packed-member) KBUILD_CFLAGS_DECOMPRESSOR += $(if $(CONFIG_DEBUG_INFO),-g) KBUILD_CFLAGS_DECOMPRESSOR += $(if $(CONFIG_DEBUG_INFO_DWARF4), $(call cc-option, -gdwarf-4,))arch/x86/Makefile +0
-0
arch/x86/Makefile REALMODE_CFLAGS := $(M16_CFLAGS) -g -Os -DDISABLE_BRANCH_PROFILING \ · line 39
Quoted 5 lines
arch/x86/Makefile +1
-1@@ -36,7 +36,7 @@ REALMODE_CFLAGS := $(M16_CFLAGS) -g -Os -DDISABLE_BRANCH_PROFILING \ -fno-strict-aliasing -fomit-frame-pointer -fno-pic \ -mno-mmx -mno-sse -REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -ffreestanding) +REALMODE_CFLAGS += -ffreestanding
See also
commit 032a2c4f65a2 ("x86/build: Use __cc-option for boot code compiler options")
for additional context (to fellow reviewers).
Quoted 30 lines
arch/x86/Makefile +0
-0REALMODE_CFLAGS += -fno-stack-protector REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -Wno-address-of-packed-member) REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), $(cc_stack_align4))arch/x86/boot/compressed/Makefile +1
-1@@ -35,7 +35,7 @@ cflags-$(CONFIG_X86_32) := -march=i386 cflags-$(CONFIG_X86_64) := -mcmodel=small KBUILD_CFLAGS += $(cflags-y) KBUILD_CFLAGS += -mno-mmx -mno-sse -KBUILD_CFLAGS += $(call cc-option,-ffreestanding) +KBUILD_CFLAGS += -ffreestanding KBUILD_CFLAGS += -fno-stack-protector KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) KBUILD_CFLAGS += $(call cc-disable-warning, gnu)drivers/firmware/efi/libstub/Makefile +1
-2@@ -28,7 +28,7 @@ cflags-$(CONFIG_EFI_GENERIC_STUB) += -I$(srctree)/scripts/dtc/libfdt KBUILD_CFLAGS := $(cflags-y) -Os -DDISABLE_BRANCH_PROFILING \ -include $(srctree)/drivers/firmware/efi/libstub/hidden.h \ -D__NO_FORTIFY \ - $(call cc-option,-ffreestanding) \ + -ffreestanding \ -fno-stack-protector \ $(call cc-option,-fno-addrsig) \ -D__DISABLE_EXPORTS --
Signature · 2 lines
Thanks, ~Nick Desaulniers
Re: [PATCH 2/2] kbuild: remove cc-option test of -ffreestanding
In reply to Masahiro YamadaQuoted 10 lines · Masahiro Yamada
Some Makefiles already pass -ffreestanding unconditionally. For example,
arch/arm64/lib/Makefile,arch/x86/purgatory/Makefile. No problem report so far about hard-coding this option. So, we can assume all supported compilers know -ffreestanding.I confirmed GCC 4.8 and Clang manuals document this option.
Get rid of cc-option from -ffreestanding.
Signed-off-by Masahiro Yamada <[email protected]>
Signature · 1 line
Kees Cook
Re: [PATCH 2/2] kbuild: remove cc-option test of -ffreestanding
In reply to Masahiro YamadaQuoted 11 lines · Masahiro Yamada
Some Makefiles already pass -ffreestanding unconditionally. For example,
arch/arm64/lib/Makefile,arch/x86/purgatory/Makefile. No problem report so far about hard-coding this option. So, we can assume all supported compilers know -ffreestanding.I confirmed GCC 4.8 and Clang manuals document this option.
Get rid of cc-option from -ffreestanding.
Signed-off-by Masahiro Yamada <[email protected]>
Quoted 63 lines
---
arch/s390/Makefile | 2 +- arch/x86/Makefile | 2 +- arch/x86/boot/compressed/Makefile | 2 +- drivers/firmware/efi/libstub/Makefile | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)arch/s390/Makefile +1
-1@@ -27,7 +27,7 @@ KBUILD_CFLAGS_DECOMPRESSOR := $(CLANG_FLAGS) -m64 -O2 KBUILD_CFLAGS_DECOMPRESSOR += -DDISABLE_BRANCH_PROFILING -D__NO_FORTIFY KBUILD_CFLAGS_DECOMPRESSOR += -fno-delete-null-pointer-checks -msoft-float KBUILD_CFLAGS_DECOMPRESSOR += -fno-asynchronous-unwind-tables -KBUILD_CFLAGS_DECOMPRESSOR += $(call cc-option,-ffreestanding) +KBUILD_CFLAGS_DECOMPRESSOR += -ffreestanding KBUILD_CFLAGS_DECOMPRESSOR += $(call cc-disable-warning, address-of-packed-member) KBUILD_CFLAGS_DECOMPRESSOR += $(if $(CONFIG_DEBUG_INFO),-g) KBUILD_CFLAGS_DECOMPRESSOR += $(if $(CONFIG_DEBUG_INFO_DWARF4), $(call cc-option, -gdwarf-4,))arch/x86/Makefile +1
-1@@ -36,7 +36,7 @@ REALMODE_CFLAGS := $(M16_CFLAGS) -g -Os -DDISABLE_BRANCH_PROFILING \ -fno-strict-aliasing -fomit-frame-pointer -fno-pic \ -mno-mmx -mno-sse -REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -ffreestanding) +REALMODE_CFLAGS += -ffreestanding REALMODE_CFLAGS += -fno-stack-protector REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -Wno-address-of-packed-member) REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), $(cc_stack_align4))arch/x86/boot/compressed/Makefile +1
-1@@ -35,7 +35,7 @@ cflags-$(CONFIG_X86_32) := -march=i386 cflags-$(CONFIG_X86_64) := -mcmodel=small KBUILD_CFLAGS += $(cflags-y) KBUILD_CFLAGS += -mno-mmx -mno-sse -KBUILD_CFLAGS += $(call cc-option,-ffreestanding) +KBUILD_CFLAGS += -ffreestanding KBUILD_CFLAGS += -fno-stack-protector KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) KBUILD_CFLAGS += $(call cc-disable-warning, gnu)drivers/firmware/efi/libstub/Makefile +1
-2@@ -28,7 +28,7 @@ cflags-$(CONFIG_EFI_GENERIC_STUB) += -I$(srctree)/scripts/dtc/libfdt KBUILD_CFLAGS := $(cflags-y) -Os -DDISABLE_BRANCH_PROFILING \ -include $(srctree)/drivers/firmware/efi/libstub/hidden.h \ -D__NO_FORTIFY \ - $(call cc-option,-ffreestanding) \ + -ffreestanding \ -fno-stack-protector \ $(call cc-option,-fno-addrsig) \ -D__DISABLE_EXPORTS --2.25.1
Quoted 168 lines · Masahiro Yamada
Some Makefiles already pass -fno-stack-protector unconditionally. For example,
arch/arm64/kernel/vdso/Makefile,arch/x86/xen/Makefile. No problem report so far about hard-coding this option. So, we can assume all supported compilers know -fno-stack-protector.GCC 4.8 and Clang support this option (https://godbolt.org/z/_HDGzN)
Get rid of cc-option from -fno-stack-protector.
Remove
CONFIG_CC_HAS_STACKPROTECTOR_NONE, which should always be 'y'.Note:
arch/mips/vdso/Makefileadds -fno-stack-protector twice, first unconditionally, and second conditionally. I removed the second one.Signed-off-by Masahiro Yamada <[email protected]>---
Documentation/kbuild/kconfig-language.rst | 4 ++-- Makefile | 2 +- arch/Kconfig | 3 --- arch/arm/boot/compressed/Makefile | 3 +-- arch/mips/vdso/Makefile | 3 +-- arch/powerpc/kernel/Makefile | 2 +- arch/powerpc/platforms/powermac/Makefile | 2 +- arch/sparc/vdso/Makefile | 4 ++-- arch/um/Makefile | 3 +-- arch/x86/Makefile | 2 +- arch/x86/boot/compressed/Makefile | 2 +- arch/x86/entry/vdso/Makefile | 4 ++-- arch/x86/kernel/cpu/Makefile | 3 +-- arch/x86/lib/Makefile | 2 +- arch/x86/mm/Makefile | 7 +++---- arch/x86/power/Makefile | 3 +-- arch/x86/purgatory/Makefile | 2 +- arch/x86/um/vdso/Makefile | 2 +- arch/x86/xen/Makefile | 5 ++--- drivers/firmware/efi/libstub/Makefile | 2 +- drivers/xen/Makefile | 3 +-- kernel/kcsan/Makefile | 3 +-- lib/Makefile | 4 ++-- mm/kasan/Makefile | 2 +- 24 files changed, 30 insertions(+), 42 deletions(-)Documentation/kbuild/kconfig-language.rst +2
-2@@ -540,8 +540,8 @@ followed by a test macro:: If you need to expose a compiler capability to makefiles and/or C source files, `CC_HAS_` is the recommended prefix for the config option:: - config CC_HAS_STACKPROTECTOR_NONE - def_bool $(cc-option,-fno-stack-protector) + config CC_HAS_ASM_GOTO + def_bool $(success,$(srctree)/scripts/gcc-goto.sh $(CC)) Build as module only ~~~~~~~~~~~~~~~~~~~~Makefile +1
-1@@ -762,7 +762,7 @@ ifneq ($(CONFIG_FRAME_WARN),0) KBUILD_CFLAGS += -Wframe-larger-than=$(CONFIG_FRAME_WARN) endif -stackp-flags-$(CONFIG_CC_HAS_STACKPROTECTOR_NONE) := -fno-stack-protector +stackp-flags-y := -fno-stack-protector stackp-flags-$(CONFIG_STACKPROTECTOR) := -fstack-protector stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strongarch/Kconfig +0
-3@@ -478,9 +478,6 @@ config HAVE_STACKPROTECTOR An arch should select this symbol if: - it has implemented a stack canary (e.g. __stack_chk_guard) -config CC_HAS_STACKPROTECTOR_NONE - def_bool $(cc-option,-fno-stack-protector) - config STACKPROTECTOR bool "Stack Protector buffer overflow detection" depends on HAVE_STACKPROTECTORarch/arm/boot/compressed/Makefile +1
-2@@ -84,9 +84,8 @@ endif # -fstack-protector-strong triggers protection checks in this code, # but it is being used too early to link to meaningful stack_chk logic. -nossp-flags-$(CONFIG_CC_HAS_STACKPROTECTOR_NONE) := -fno-stack-protector $(foreach o, $(libfdt_objs) atags_to_fdt.o, \ - $(eval CFLAGS_$(o) := -I $(srctree)/scripts/dtc/libfdt $(nossp-flags-y))) + $(eval CFLAGS_$(o) := -I $(srctree)/scripts/dtc/libfdt -fno-stack-protector)) # These were previously generated C files. When you are building the kernel # with O=, make sure to remove the stale files in the output tree. Otherwise,arch/mips/vdso/Makefile +1
-2@@ -35,8 +35,7 @@ cflags-vdso := $(ccflags-vdso) \ -O3 -g -fPIC -fno-strict-aliasing -fno-common -fno-builtin -G 0 \ -mrelax-pic-calls $(call cc-option, -mexplicit-relocs) \ -fno-stack-protector -fno-jump-tables -DDISABLE_BRANCH_PROFILING \ - $(call cc-option, -fno-asynchronous-unwind-tables) \ - $(call cc-option, -fno-stack-protector) + $(call cc-option, -fno-asynchronous-unwind-tables) aflags-vdso := $(ccflags-vdso) \ -D__ASSEMBLY__ -Wa,-gdwarf-2arch/powerpc/kernel/Makefile +1
-1@@ -16,7 +16,7 @@ CFLAGS_prom_init.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) CFLAGS_btext.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) CFLAGS_prom.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) -CFLAGS_prom_init.o += $(call cc-option, -fno-stack-protector) +CFLAGS_prom_init.o += -fno-stack-protector CFLAGS_prom_init.o += -DDISABLE_BRANCH_PROFILING CFLAGS_prom_init.o += -ffreestandingarch/powerpc/platforms/powermac/Makefile +1
-1@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 CFLAGS_bootx_init.o += -fPIC -CFLAGS_bootx_init.o += $(call cc-option, -fno-stack-protector) +CFLAGS_bootx_init.o += -fno-stack-protector KASAN_SANITIZE_bootx_init.o := narch/sparc/vdso/Makefile +2
-2@@ -54,7 +54,7 @@ $(obj)/vdso-image-%.c: $(obj)/vdso%.so.dbg $(obj)/vdso%.so $(obj)/vdso2c FORCE # optimize sibling calls. # CFL := $(PROFILING) -mcmodel=medlow -fPIC -O2 -fasynchronous-unwind-tables -m64 \ - $(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \ + $(filter -g%,$(KBUILD_CFLAGS)) -fno-stack-protector \ -fno-omit-frame-pointer -foptimize-sibling-calls \ -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO@@ -93,7 +93,7 @@ KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(SPARC_REG_CFLAGS),$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 += -m32 -msoft-float -fpic -KBUILD_CFLAGS_32 += $(call cc-option, -fno-stack-protector) +KBUILD_CFLAGS_32 += -fno-stack-protector KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls) KBUILD_CFLAGS_32 += -fno-omit-frame-pointer KBUILD_CFLAGS_32 += -DDISABLE_BRANCH_PROFILINGarch/um/Makefile +0
-0
arch/um/Makefile LINK-$(CONFIG_LD_SCRIPT_STATIC) += -static · line 124
Quoted 6 lines
arch/um/Makefile +1
-2@@ -121,8 +121,7 @@ LINK-$(CONFIG_LD_SCRIPT_STATIC) += -static LINK-$(CONFIG_LD_SCRIPT_DYN) += -Wl,-rpath,/lib $(call cc-option, -no-pie) CFLAGS_NO_HARDENING := $(call cc-option, -fno-PIC,) $(call cc-option, -fno-pic,) \ - $(call cc-option, -fno-stack-protector,) \ - $(call cc-option, -fno-stack-protector-all,) + -fno-stack-protector $(call cc-option, -fno-stack-protector-all)
Just curious, looks like we could do the same for -fno-stack-protector-all, here or tree-wide, right? Wait, what compiler recognizes -fno-stack-protector-all?
https://godbolt.org/z/QFQKE_
Quoted 235 lines
arch/um/Makefile +0
-0# Options used by linker script export LDS_START := $(START)arch/x86/Makefile +1
-1@@ -37,7 +37,7 @@ REALMODE_CFLAGS := $(M16_CFLAGS) -g -Os -DDISABLE_BRANCH_PROFILING \ -mno-mmx -mno-sse REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -ffreestanding) -REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -fno-stack-protector) +REALMODE_CFLAGS += -fno-stack-protector REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -Wno-address-of-packed-member) REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), $(cc_stack_align4)) export REALMODE_CFLAGSarch/x86/boot/compressed/Makefile +1
-1@@ -36,7 +36,7 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small KBUILD_CFLAGS += $(cflags-y) KBUILD_CFLAGS += -mno-mmx -mno-sse KBUILD_CFLAGS += $(call cc-option,-ffreestanding) -KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector) +KBUILD_CFLAGS += -fno-stack-protector KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) KBUILD_CFLAGS += $(call cc-disable-warning, gnu) KBUILD_CFLAGS += -Wno-pointer-signarch/x86/entry/vdso/Makefile +2
-2@@ -82,7 +82,7 @@ $(obj)/vdso-image-%.c: $(obj)/vdso%.so.dbg $(obj)/vdso%.so $(obj)/vdso2c FORCE # optimize sibling calls. # CFL := $(PROFILING) -mcmodel=small -fPIC -O2 -fasynchronous-unwind-tables -m64 \ - $(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \ + $(filter -g%,$(KBUILD_CFLAGS)) -fno-stack-protector \ -fno-omit-frame-pointer -foptimize-sibling-calls \ -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO@@ -151,7 +151,7 @@ KBUILD_CFLAGS_32 := $(filter-out -mfentry,$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 += -m32 -msoft-float -mregparm=0 -fpic -KBUILD_CFLAGS_32 += $(call cc-option, -fno-stack-protector) +KBUILD_CFLAGS_32 += -fno-stack-protector KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls) KBUILD_CFLAGS_32 += -fno-omit-frame-pointer KBUILD_CFLAGS_32 += -DDISABLE_BRANCH_PROFILINGarch/x86/kernel/cpu/Makefile +1
-2@@ -17,8 +17,7 @@ KCOV_INSTRUMENT_perf_event.o := n KCSAN_SANITIZE_common.o := n # Make sure load_percpu_segment has no stackprotector -nostackp := $(call cc-option, -fno-stack-protector) -CFLAGS_common.o := $(nostackp) +CFLAGS_common.o := -fno-stack-protector obj-y := cacheinfo.o scattered.o topology.o obj-y += common.oarch/x86/lib/Makefile +1
-1@@ -24,7 +24,7 @@ ifdef CONFIG_FUNCTION_TRACER CFLAGS_REMOVE_cmdline.o = -pg endif -CFLAGS_cmdline.o := $(call cc-option, -fno-stack-protector) +CFLAGS_cmdline.o := -fno-stack-protector endif inat_tables_script = $(srctree)/arch/x86/tools/gen-insn-attr-x86.awkarch/x86/mm/Makefile +3
-4@@ -22,10 +22,9 @@ obj-y := init.o init_$(BITS).o fault.o ioremap.o extable.o mmap.o \ obj-y += pat/ # Make sure __phys_addr has no stackprotector -nostackp := $(call cc-option, -fno-stack-protector) -CFLAGS_physaddr.o := $(nostackp) -CFLAGS_setup_nx.o := $(nostackp) -CFLAGS_mem_encrypt_identity.o := $(nostackp) +CFLAGS_physaddr.o := -fno-stack-protector +CFLAGS_setup_nx.o := -fno-stack-protector +CFLAGS_mem_encrypt_identity.o := -fno-stack-protector CFLAGS_fault.o := -I $(srctree)/$(src)/../include/asm/tracearch/x86/power/Makefile +1
-2@@ -3,8 +3,7 @@ OBJECT_FILES_NON_STANDARD_hibernate_asm_$(BITS).o := y # __restore_processor_state() restores %gs after S3 resume and so should not # itself be stack-protected -nostackp := $(call cc-option, -fno-stack-protector) -CFLAGS_cpu.o := $(nostackp) +CFLAGS_cpu.o := -fno-stack-protector obj-$(CONFIG_PM_SLEEP) += cpu.o obj-$(CONFIG_HIBERNATION) += hibernate_$(BITS).o hibernate_asm_$(BITS).o hibernate.oarch/x86/purgatory/Makefile +1
-1@@ -34,7 +34,7 @@ KCOV_INSTRUMENT := n PURGATORY_CFLAGS_REMOVE := -mcmodel=kernel PURGATORY_CFLAGS := -mcmodel=large -ffreestanding -fno-zero-initialized-in-bss PURGATORY_CFLAGS += $(DISABLE_STACKLEAK_PLUGIN) -DDISABLE_BRANCH_PROFILING -PURGATORY_CFLAGS += $(call cc-option,-fno-stack-protector) +PURGATORY_CFLAGS += -fno-stack-protector # Default KBUILD_CFLAGS can have -pg option set when FTRACE is enabled. That # in turn leaves some undefined symbols like __fentry__ in purgatory and notarch/x86/um/vdso/Makefile +1
-1@@ -42,7 +42,7 @@ $(obj)/%.so: $(obj)/%.so.dbg FORCE # optimize sibling calls. # CFL := $(PROFILING) -mcmodel=small -fPIC -O2 -fasynchronous-unwind-tables -m64 \ - $(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \ + $(filter -g%,$(KBUILD_CFLAGS)) -fno-stack-protector \ -fno-omit-frame-pointer -foptimize-sibling-calls $(vobjs): KBUILD_CFLAGS += $(CFL)arch/x86/xen/Makefile +2
-3@@ -9,9 +9,8 @@ CFLAGS_REMOVE_irq.o = -pg endif # Make sure early boot has no stackprotector -nostackp := $(call cc-option, -fno-stack-protector) -CFLAGS_enlighten_pv.o := $(nostackp) -CFLAGS_mmu_pv.o := $(nostackp) +CFLAGS_enlighten_pv.o := -fno-stack-protector +CFLAGS_mmu_pv.o := -fno-stack-protector obj-y += enlighten.o obj-y += mmu.odrivers/firmware/efi/libstub/Makefile +1
-1@@ -29,7 +29,7 @@ KBUILD_CFLAGS := $(cflags-y) -Os -DDISABLE_BRANCH_PROFILING \ -include $(srctree)/drivers/firmware/efi/libstub/hidden.h \ -D__NO_FORTIFY \ $(call cc-option,-ffreestanding) \ - $(call cc-option,-fno-stack-protector) \ + -fno-stack-protector \ $(call cc-option,-fno-addrsig) \ -D__DISABLE_EXPORTSdrivers/xen/Makefile +1
-2@@ -5,8 +5,7 @@ obj-y += mem-reservation.o obj-y += events/ obj-y += xenbus/ -nostackp := $(call cc-option, -fno-stack-protector) -CFLAGS_features.o := $(nostackp) +CFLAGS_features.o := -fno-stack-protector dom0-$(CONFIG_ARM64) += arm-device.o dom0-$(CONFIG_PCI) += pci.okernel/kcsan/Makefile +1
-2@@ -7,8 +7,7 @@ CFLAGS_REMOVE_core.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_debugfs.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_report.o = $(CC_FLAGS_FTRACE) -CFLAGS_core.o := $(call cc-option,-fno-conserve-stack,) \ - $(call cc-option,-fno-stack-protector,) +CFLAGS_core.o := $(call cc-option,-fno-conserve-stack,) -fno-stack-protector obj-y := core.o debugfs.o report.o obj-$(CONFIG_KCSAN_SELFTEST) += test.olib/Makefile +2
-2@@ -22,7 +22,7 @@ KCOV_INSTRUMENT_fault-inject.o := n ifdef CONFIG_AMD_MEM_ENCRYPT KASAN_SANITIZE_string.o := n -CFLAGS_string.o := $(call cc-option, -fno-stack-protector) +CFLAGS_string.o := -fno-stack-protector endif # Used by KCSAN while enabled, avoid recursion.@@ -300,7 +300,7 @@ endif UBSAN_SANITIZE_ubsan.o := n KASAN_SANITIZE_ubsan.o := n KCSAN_SANITIZE_ubsan.o := n -CFLAGS_ubsan.o := $(call cc-option, -fno-stack-protector) $(DISABLE_STACKLEAK_PLUGIN) +CFLAGS_ubsan.o := -fno-stack-protector $(DISABLE_STACKLEAK_PLUGIN) obj-$(CONFIG_SBITMAP) += sbitmap.omm/kasan/Makefile +1
-2@@ -16,7 +16,7 @@ CFLAGS_REMOVE_tags_report.o = $(CC_FLAGS_FTRACE) # Function splitter causes unnecessary splits in __asan_load1/__asan_store1 # see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63533 CC_FLAGS_KASAN_RUNTIME := $(call cc-option, -fno-conserve-stack) -CC_FLAGS_KASAN_RUNTIME += $(call cc-option, -fno-stack-protector) +CC_FLAGS_KASAN_RUNTIME += -fno-stack-protector # Disable branch tracing to avoid recursion. CC_FLAGS_KASAN_RUNTIME += -DDISABLE_BRANCH_PROFILING --2.25.1
--
You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20200626185913.92890-1-masahiroy%40kernel.org.
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 172 lines · Nick Desaulniers
Quoted 170 lines · Masahiro Yamada
Some Makefiles already pass -fno-stack-protector unconditionally. For example,
arch/arm64/kernel/vdso/Makefile,arch/x86/xen/Makefile. No problem report so far about hard-coding this option. So, we can assume all supported compilers know -fno-stack-protector.GCC 4.8 and Clang support this option (https://godbolt.org/z/_HDGzN)
Get rid of cc-option from -fno-stack-protector.
Remove
CONFIG_CC_HAS_STACKPROTECTOR_NONE, which should always be 'y'.Note:
arch/mips/vdso/Makefileadds -fno-stack-protector twice, first unconditionally, and second conditionally. I removed the second one.Signed-off-by Masahiro Yamada <[email protected]>---
Documentation/kbuild/kconfig-language.rst | 4 ++-- Makefile | 2 +- arch/Kconfig | 3 --- arch/arm/boot/compressed/Makefile | 3 +-- arch/mips/vdso/Makefile | 3 +-- arch/powerpc/kernel/Makefile | 2 +- arch/powerpc/platforms/powermac/Makefile | 2 +- arch/sparc/vdso/Makefile | 4 ++-- arch/um/Makefile | 3 +-- arch/x86/Makefile | 2 +- arch/x86/boot/compressed/Makefile | 2 +- arch/x86/entry/vdso/Makefile | 4 ++-- arch/x86/kernel/cpu/Makefile | 3 +-- arch/x86/lib/Makefile | 2 +- arch/x86/mm/Makefile | 7 +++---- arch/x86/power/Makefile | 3 +-- arch/x86/purgatory/Makefile | 2 +- arch/x86/um/vdso/Makefile | 2 +- arch/x86/xen/Makefile | 5 ++--- drivers/firmware/efi/libstub/Makefile | 2 +- drivers/xen/Makefile | 3 +-- kernel/kcsan/Makefile | 3 +-- lib/Makefile | 4 ++-- mm/kasan/Makefile | 2 +- 24 files changed, 30 insertions(+), 42 deletions(-)Documentation/kbuild/kconfig-language.rst +2
-2@@ -540,8 +540,8 @@ followed by a test macro:: If you need to expose a compiler capability to makefiles and/or C source files, `CC_HAS_` is the recommended prefix for the config option:: - config CC_HAS_STACKPROTECTOR_NONE - def_bool $(cc-option,-fno-stack-protector) + config CC_HAS_ASM_GOTO + def_bool $(success,$(srctree)/scripts/gcc-goto.sh $(CC)) Build as module only ~~~~~~~~~~~~~~~~~~~~Makefile +1
-1@@ -762,7 +762,7 @@ ifneq ($(CONFIG_FRAME_WARN),0) KBUILD_CFLAGS += -Wframe-larger-than=$(CONFIG_FRAME_WARN) endif -stackp-flags-$(CONFIG_CC_HAS_STACKPROTECTOR_NONE) := -fno-stack-protector +stackp-flags-y := -fno-stack-protector stackp-flags-$(CONFIG_STACKPROTECTOR) := -fstack-protector stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strongarch/Kconfig +0
-3@@ -478,9 +478,6 @@ config HAVE_STACKPROTECTOR An arch should select this symbol if: - it has implemented a stack canary (e.g. __stack_chk_guard) -config CC_HAS_STACKPROTECTOR_NONE - def_bool $(cc-option,-fno-stack-protector) - config STACKPROTECTOR bool "Stack Protector buffer overflow detection" depends on HAVE_STACKPROTECTORarch/arm/boot/compressed/Makefile +1
-2@@ -84,9 +84,8 @@ endif # -fstack-protector-strong triggers protection checks in this code, # but it is being used too early to link to meaningful stack_chk logic. -nossp-flags-$(CONFIG_CC_HAS_STACKPROTECTOR_NONE) := -fno-stack-protector $(foreach o, $(libfdt_objs) atags_to_fdt.o, \ - $(eval CFLAGS_$(o) := -I $(srctree)/scripts/dtc/libfdt $(nossp-flags-y))) + $(eval CFLAGS_$(o) := -I $(srctree)/scripts/dtc/libfdt -fno-stack-protector)) # These were previously generated C files. When you are building the kernel # with O=, make sure to remove the stale files in the output tree. Otherwise,arch/mips/vdso/Makefile +1
-2@@ -35,8 +35,7 @@ cflags-vdso := $(ccflags-vdso) \ -O3 -g -fPIC -fno-strict-aliasing -fno-common -fno-builtin -G 0 \ -mrelax-pic-calls $(call cc-option, -mexplicit-relocs) \ -fno-stack-protector -fno-jump-tables -DDISABLE_BRANCH_PROFILING \ - $(call cc-option, -fno-asynchronous-unwind-tables) \ - $(call cc-option, -fno-stack-protector) + $(call cc-option, -fno-asynchronous-unwind-tables) aflags-vdso := $(ccflags-vdso) \ -D__ASSEMBLY__ -Wa,-gdwarf-2arch/powerpc/kernel/Makefile +1
-1@@ -16,7 +16,7 @@ CFLAGS_prom_init.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) CFLAGS_btext.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) CFLAGS_prom.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) -CFLAGS_prom_init.o += $(call cc-option, -fno-stack-protector) +CFLAGS_prom_init.o += -fno-stack-protector CFLAGS_prom_init.o += -DDISABLE_BRANCH_PROFILING CFLAGS_prom_init.o += -ffreestandingarch/powerpc/platforms/powermac/Makefile +1
-1@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 CFLAGS_bootx_init.o += -fPIC -CFLAGS_bootx_init.o += $(call cc-option, -fno-stack-protector) +CFLAGS_bootx_init.o += -fno-stack-protector KASAN_SANITIZE_bootx_init.o := narch/sparc/vdso/Makefile +2
-2@@ -54,7 +54,7 @@ $(obj)/vdso-image-%.c: $(obj)/vdso%.so.dbg $(obj)/vdso%.so $(obj)/vdso2c FORCE # optimize sibling calls. # CFL := $(PROFILING) -mcmodel=medlow -fPIC -O2 -fasynchronous-unwind-tables -m64 \ - $(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \ + $(filter -g%,$(KBUILD_CFLAGS)) -fno-stack-protector \ -fno-omit-frame-pointer -foptimize-sibling-calls \ -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO@@ -93,7 +93,7 @@ KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(SPARC_REG_CFLAGS),$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 += -m32 -msoft-float -fpic -KBUILD_CFLAGS_32 += $(call cc-option, -fno-stack-protector) +KBUILD_CFLAGS_32 += -fno-stack-protector KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls) KBUILD_CFLAGS_32 += -fno-omit-frame-pointer KBUILD_CFLAGS_32 += -DDISABLE_BRANCH_PROFILINGarch/um/Makefile +0
-0@@ -121,8 +121,7 @@ LINK-$(CONFIG_LD_SCRIPT_STATIC) += -static LINK-$(CONFIG_LD_SCRIPT_DYN) += -Wl,-rpath,/lib $(call cc-option, -no-pie)
Quoted 9 lines
arch/um/Makefile LINK-$(CONFIG_LD_SCRIPT_STATIC) += -static · line 124
Quoted 4 lines
arch/um/Makefile +1
-2CFLAGS_NO_HARDENING := $(call cc-option, -fno-PIC,) $(call cc-option, -fno-pic,) \ - $(call cc-option, -fno-stack-protector,) \ - $(call cc-option, -fno-stack-protector-all,) + -fno-stack-protector $(call cc-option, -fno-stack-protector-all)Just curious, looks like we could do the same for
-fno-stack-protector-all, here or tree-wide, right? Wait, what compiler recognizes -fno-stack-protector-all?
https://godbolt.org/z/QFQKE_
-fstack-protector
-fstack-protector-strong
-fstack-protector-all
are supported.
But,
-fno-stack-protector-strong
-fno-stack-protector-all
are unsupported.
Perheps, -fno-stack-protector is enough
to disable all variants of stack-protector.
Signature · 2 lines
Best Regards Masahiro Yamada
Quoted 10 lines · Nick Desaulniers
arch/um/Makefile LINK-$(CONFIG_LD_SCRIPT_STATIC) += -static · line 124
Quoted 4 lines · Masahiro Yamada
CFLAGS_NO_HARDENING:= $(call cc-option, -fno-PIC,) $(call cc-option, -fno-pic,) \arch/um/Makefile +1
-2- $(call cc-option, -fno-stack-protector,) \ - $(call cc-option, -fno-stack-protector-all,) + -fno-stack-protector $(call cc-option, -fno-stack-protector-all)Just curious, looks like we could do the same for
-fno-stack-protector-all, here or tree-wide, right? Wait, what compiler recognizes -fno-stack-protector-all?
https://godbolt.org/z/QFQKE_
That is from ancient times, IIRC. -fno-stack-protector should be sufficient.
Signature · 1 line
Kees Cook
Quoted 10 lines · Masahiro Yamada
Some Makefiles already pass -fno-stack-protector unconditionally. For example,
arch/arm64/kernel/vdso/Makefile,arch/x86/xen/Makefile. No problem report so far about hard-coding this option. So, we can assume all supported compilers know -fno-stack-protector.GCC 4.8 and Clang support this option (https://godbolt.org/z/_HDGzN)
Get rid of cc-option from -fno-stack-protector.
Quoted 7 lines
Remove
CONFIG_CC_HAS_STACKPROTECTOR_NONE, which should always be 'y'.Note:
arch/mips/vdso/Makefileadds -fno-stack-protector twice, first unconditionally, and second conditionally. I removed the second one.Signed-off-by Masahiro Yamada <[email protected]>
Generally looks pretty good, just a few more questions before adding my tag explicitly.
Quoted 48 lines
---
Documentation/kbuild/kconfig-language.rst | 4 ++-- Makefile | 2 +- arch/Kconfig | 3 --- arch/arm/boot/compressed/Makefile | 3 +-- arch/mips/vdso/Makefile | 3 +-- arch/powerpc/kernel/Makefile | 2 +- arch/powerpc/platforms/powermac/Makefile | 2 +- arch/sparc/vdso/Makefile | 4 ++-- arch/um/Makefile | 3 +-- arch/x86/Makefile | 2 +- arch/x86/boot/compressed/Makefile | 2 +- arch/x86/entry/vdso/Makefile | 4 ++-- arch/x86/kernel/cpu/Makefile | 3 +-- arch/x86/lib/Makefile | 2 +- arch/x86/mm/Makefile | 7 +++---- arch/x86/power/Makefile | 3 +-- arch/x86/purgatory/Makefile | 2 +- arch/x86/um/vdso/Makefile | 2 +- arch/x86/xen/Makefile | 5 ++--- drivers/firmware/efi/libstub/Makefile | 2 +- drivers/xen/Makefile | 3 +-- kernel/kcsan/Makefile | 3 +-- lib/Makefile | 4 ++-- mm/kasan/Makefile | 2 +- 24 files changed, 30 insertions(+), 42 deletions(-)Documentation/kbuild/kconfig-language.rst +2
-2@@ -540,8 +540,8 @@ followed by a test macro:: If you need to expose a compiler capability to makefiles and/or C source files, `CC_HAS_` is the recommended prefix for the config option:: - config CC_HAS_STACKPROTECTOR_NONE - def_bool $(cc-option,-fno-stack-protector) + config CC_HAS_ASM_GOTO + def_bool $(success,$(srctree)/scripts/gcc-goto.sh $(CC)) Build as module only ~~~~~~~~~~~~~~~~~~~~Makefile +0
-0
Makefile ifneq ($(CONFIG_FRAME_WARN),0) · line 767
Quoted 7 lines
Makefile +1
-1@@ -762,7 +762,7 @@ ifneq ($(CONFIG_FRAME_WARN),0) KBUILD_CFLAGS += -Wframe-larger-than=$(CONFIG_FRAME_WARN) endif -stackp-flags-$(CONFIG_CC_HAS_STACKPROTECTOR_NONE) := -fno-stack-protector +stackp-flags-y := -fno-stack-protector stackp-flags-$(CONFIG_STACKPROTECTOR) := -fstack-protector stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strong
So it looks like the previous behavior always added -fno-stack-protector (since CONFIG_CC_HAS_STACKPROTECTOR_NONE was always true), but then we append either -fstack-protector or -fstack-protector-strong based on configs. While that's ok, and you patch doesn't change that behavior, and it's good to be explicit to set the stack protector or not...it seems weird to have -fno-stack-protector -fstack-protector in the command line flags. I would prefer if we checked for not having CONFIG_STACKPROTECTOR or CONFIG_STACKPROTECTOR_STRONG before adding -fno-stack-protector. That doesn't have to be done in this patch, per se.
Quoted 158 lines
arch/Kconfig +0
-3@@ -478,9 +478,6 @@ config HAVE_STACKPROTECTOR An arch should select this symbol if: - it has implemented a stack canary (e.g. __stack_chk_guard) -config CC_HAS_STACKPROTECTOR_NONE - def_bool $(cc-option,-fno-stack-protector) - config STACKPROTECTOR bool "Stack Protector buffer overflow detection" depends on HAVE_STACKPROTECTORarch/arm/boot/compressed/Makefile +1
-2@@ -84,9 +84,8 @@ endif # -fstack-protector-strong triggers protection checks in this code, # but it is being used too early to link to meaningful stack_chk logic. -nossp-flags-$(CONFIG_CC_HAS_STACKPROTECTOR_NONE) := -fno-stack-protector $(foreach o, $(libfdt_objs) atags_to_fdt.o, \ - $(eval CFLAGS_$(o) := -I $(srctree)/scripts/dtc/libfdt $(nossp-flags-y))) + $(eval CFLAGS_$(o) := -I $(srctree)/scripts/dtc/libfdt -fno-stack-protector)) # These were previously generated C files. When you are building the kernel # with O=, make sure to remove the stale files in the output tree. Otherwise,arch/mips/vdso/Makefile +1
-2@@ -35,8 +35,7 @@ cflags-vdso := $(ccflags-vdso) \ -O3 -g -fPIC -fno-strict-aliasing -fno-common -fno-builtin -G 0 \ -mrelax-pic-calls $(call cc-option, -mexplicit-relocs) \ -fno-stack-protector -fno-jump-tables -DDISABLE_BRANCH_PROFILING \ - $(call cc-option, -fno-asynchronous-unwind-tables) \ - $(call cc-option, -fno-stack-protector) + $(call cc-option, -fno-asynchronous-unwind-tables) aflags-vdso := $(ccflags-vdso) \ -D__ASSEMBLY__ -Wa,-gdwarf-2arch/powerpc/kernel/Makefile +1
-1@@ -16,7 +16,7 @@ CFLAGS_prom_init.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) CFLAGS_btext.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) CFLAGS_prom.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) -CFLAGS_prom_init.o += $(call cc-option, -fno-stack-protector) +CFLAGS_prom_init.o += -fno-stack-protector CFLAGS_prom_init.o += -DDISABLE_BRANCH_PROFILING CFLAGS_prom_init.o += -ffreestandingarch/powerpc/platforms/powermac/Makefile +1
-1@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 CFLAGS_bootx_init.o += -fPIC -CFLAGS_bootx_init.o += $(call cc-option, -fno-stack-protector) +CFLAGS_bootx_init.o += -fno-stack-protector KASAN_SANITIZE_bootx_init.o := narch/sparc/vdso/Makefile +2
-2@@ -54,7 +54,7 @@ $(obj)/vdso-image-%.c: $(obj)/vdso%.so.dbg $(obj)/vdso%.so $(obj)/vdso2c FORCE # optimize sibling calls. # CFL := $(PROFILING) -mcmodel=medlow -fPIC -O2 -fasynchronous-unwind-tables -m64 \ - $(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \ + $(filter -g%,$(KBUILD_CFLAGS)) -fno-stack-protector \ -fno-omit-frame-pointer -foptimize-sibling-calls \ -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO@@ -93,7 +93,7 @@ KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(SPARC_REG_CFLAGS),$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 += -m32 -msoft-float -fpic -KBUILD_CFLAGS_32 += $(call cc-option, -fno-stack-protector) +KBUILD_CFLAGS_32 += -fno-stack-protector KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls) KBUILD_CFLAGS_32 += -fno-omit-frame-pointer KBUILD_CFLAGS_32 += -DDISABLE_BRANCH_PROFILINGarch/um/Makefile +1
-2@@ -121,8 +121,7 @@ LINK-$(CONFIG_LD_SCRIPT_STATIC) += -static LINK-$(CONFIG_LD_SCRIPT_DYN) += -Wl,-rpath,/lib $(call cc-option, -no-pie) CFLAGS_NO_HARDENING := $(call cc-option, -fno-PIC,) $(call cc-option, -fno-pic,) \ - $(call cc-option, -fno-stack-protector,) \ - $(call cc-option, -fno-stack-protector-all,) + -fno-stack-protector $(call cc-option, -fno-stack-protector-all) # Options used by linker script export LDS_START := $(START)arch/x86/Makefile +1
-1@@ -37,7 +37,7 @@ REALMODE_CFLAGS := $(M16_CFLAGS) -g -Os -DDISABLE_BRANCH_PROFILING \ -mno-mmx -mno-sse REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -ffreestanding) -REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -fno-stack-protector) +REALMODE_CFLAGS += -fno-stack-protector REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -Wno-address-of-packed-member) REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), $(cc_stack_align4)) export REALMODE_CFLAGSarch/x86/boot/compressed/Makefile +1
-1@@ -36,7 +36,7 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small KBUILD_CFLAGS += $(cflags-y) KBUILD_CFLAGS += -mno-mmx -mno-sse KBUILD_CFLAGS += $(call cc-option,-ffreestanding) -KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector) +KBUILD_CFLAGS += -fno-stack-protector KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) KBUILD_CFLAGS += $(call cc-disable-warning, gnu) KBUILD_CFLAGS += -Wno-pointer-signarch/x86/entry/vdso/Makefile +2
-2@@ -82,7 +82,7 @@ $(obj)/vdso-image-%.c: $(obj)/vdso%.so.dbg $(obj)/vdso%.so $(obj)/vdso2c FORCE # optimize sibling calls. # CFL := $(PROFILING) -mcmodel=small -fPIC -O2 -fasynchronous-unwind-tables -m64 \ - $(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \ + $(filter -g%,$(KBUILD_CFLAGS)) -fno-stack-protector \ -fno-omit-frame-pointer -foptimize-sibling-calls \ -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO@@ -151,7 +151,7 @@ KBUILD_CFLAGS_32 := $(filter-out -mfentry,$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 += -m32 -msoft-float -mregparm=0 -fpic -KBUILD_CFLAGS_32 += $(call cc-option, -fno-stack-protector) +KBUILD_CFLAGS_32 += -fno-stack-protector KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls) KBUILD_CFLAGS_32 += -fno-omit-frame-pointer KBUILD_CFLAGS_32 += -DDISABLE_BRANCH_PROFILINGarch/x86/kernel/cpu/Makefile +0
-0
arch/x86/kernel/cpu/Makefile KCOV_INSTRUMENT_perf_event.o := n · line 20
Quoted 6 lines
arch/x86/kernel/cpu/Makefile +1
-2@@ -17,8 +17,7 @@ KCOV_INSTRUMENT_perf_event.o := n KCSAN_SANITIZE_common.o := n # Make sure load_percpu_segment has no stackprotector -nostackp := $(call cc-option, -fno-stack-protector) -CFLAGS_common.o := $(nostackp) +CFLAGS_common.o := -fno-stack-protector
Any time I see := assignment to a CFLAGS variable, it's a red flag for overwriting existing CFLAGS, which is a common source of bugs. I recognize the kernel is current a mix and match for:
CFLAGS_<file>.o
rules to either use += or :=, but I wish we were consistent, and consistent in our use of +=. For those rules, is there a difference between the use of += and := like there is for the more general case of appending to KBUILD_CFLAGS? If not, it's ok to match the existing style, but it's curious to me in this patch to see a mixed use of += and :=.
Quoted 167 lines
arch/x86/kernel/cpu/Makefile +0
-0obj-y := cacheinfo.o scattered.o topology.o obj-y += common.oarch/x86/lib/Makefile +1
-1@@ -24,7 +24,7 @@ ifdef CONFIG_FUNCTION_TRACER CFLAGS_REMOVE_cmdline.o = -pg endif -CFLAGS_cmdline.o := $(call cc-option, -fno-stack-protector) +CFLAGS_cmdline.o := -fno-stack-protector endif inat_tables_script = $(srctree)/arch/x86/tools/gen-insn-attr-x86.awkarch/x86/mm/Makefile +3
-4@@ -22,10 +22,9 @@ obj-y := init.o init_$(BITS).o fault.o ioremap.o extable.o mmap.o \ obj-y += pat/ # Make sure __phys_addr has no stackprotector -nostackp := $(call cc-option, -fno-stack-protector) -CFLAGS_physaddr.o := $(nostackp) -CFLAGS_setup_nx.o := $(nostackp) -CFLAGS_mem_encrypt_identity.o := $(nostackp) +CFLAGS_physaddr.o := -fno-stack-protector +CFLAGS_setup_nx.o := -fno-stack-protector +CFLAGS_mem_encrypt_identity.o := -fno-stack-protector CFLAGS_fault.o := -I $(srctree)/$(src)/../include/asm/tracearch/x86/power/Makefile +1
-2@@ -3,8 +3,7 @@ OBJECT_FILES_NON_STANDARD_hibernate_asm_$(BITS).o := y # __restore_processor_state() restores %gs after S3 resume and so should not # itself be stack-protected -nostackp := $(call cc-option, -fno-stack-protector) -CFLAGS_cpu.o := $(nostackp) +CFLAGS_cpu.o := -fno-stack-protector obj-$(CONFIG_PM_SLEEP) += cpu.o obj-$(CONFIG_HIBERNATION) += hibernate_$(BITS).o hibernate_asm_$(BITS).o hibernate.oarch/x86/purgatory/Makefile +1
-1@@ -34,7 +34,7 @@ KCOV_INSTRUMENT := n PURGATORY_CFLAGS_REMOVE := -mcmodel=kernel PURGATORY_CFLAGS := -mcmodel=large -ffreestanding -fno-zero-initialized-in-bss PURGATORY_CFLAGS += $(DISABLE_STACKLEAK_PLUGIN) -DDISABLE_BRANCH_PROFILING -PURGATORY_CFLAGS += $(call cc-option,-fno-stack-protector) +PURGATORY_CFLAGS += -fno-stack-protector # Default KBUILD_CFLAGS can have -pg option set when FTRACE is enabled. That # in turn leaves some undefined symbols like __fentry__ in purgatory and notarch/x86/um/vdso/Makefile +1
-1@@ -42,7 +42,7 @@ $(obj)/%.so: $(obj)/%.so.dbg FORCE # optimize sibling calls. # CFL := $(PROFILING) -mcmodel=small -fPIC -O2 -fasynchronous-unwind-tables -m64 \ - $(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \ + $(filter -g%,$(KBUILD_CFLAGS)) -fno-stack-protector \ -fno-omit-frame-pointer -foptimize-sibling-calls $(vobjs): KBUILD_CFLAGS += $(CFL)arch/x86/xen/Makefile +2
-3@@ -9,9 +9,8 @@ CFLAGS_REMOVE_irq.o = -pg endif # Make sure early boot has no stackprotector -nostackp := $(call cc-option, -fno-stack-protector) -CFLAGS_enlighten_pv.o := $(nostackp) -CFLAGS_mmu_pv.o := $(nostackp) +CFLAGS_enlighten_pv.o := -fno-stack-protector +CFLAGS_mmu_pv.o := -fno-stack-protector obj-y += enlighten.o obj-y += mmu.odrivers/firmware/efi/libstub/Makefile +1
-1@@ -29,7 +29,7 @@ KBUILD_CFLAGS := $(cflags-y) -Os -DDISABLE_BRANCH_PROFILING \ -include $(srctree)/drivers/firmware/efi/libstub/hidden.h \ -D__NO_FORTIFY \ $(call cc-option,-ffreestanding) \ - $(call cc-option,-fno-stack-protector) \ + -fno-stack-protector \ $(call cc-option,-fno-addrsig) \ -D__DISABLE_EXPORTSdrivers/xen/Makefile +1
-2@@ -5,8 +5,7 @@ obj-y += mem-reservation.o obj-y += events/ obj-y += xenbus/ -nostackp := $(call cc-option, -fno-stack-protector) -CFLAGS_features.o := $(nostackp) +CFLAGS_features.o := -fno-stack-protector dom0-$(CONFIG_ARM64) += arm-device.o dom0-$(CONFIG_PCI) += pci.okernel/kcsan/Makefile +1
-2@@ -7,8 +7,7 @@ CFLAGS_REMOVE_core.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_debugfs.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_report.o = $(CC_FLAGS_FTRACE) -CFLAGS_core.o := $(call cc-option,-fno-conserve-stack,) \ - $(call cc-option,-fno-stack-protector,) +CFLAGS_core.o := $(call cc-option,-fno-conserve-stack,) -fno-stack-protector obj-y := core.o debugfs.o report.o obj-$(CONFIG_KCSAN_SELFTEST) += test.olib/Makefile +2
-2@@ -22,7 +22,7 @@ KCOV_INSTRUMENT_fault-inject.o := n ifdef CONFIG_AMD_MEM_ENCRYPT KASAN_SANITIZE_string.o := n -CFLAGS_string.o := $(call cc-option, -fno-stack-protector) +CFLAGS_string.o := -fno-stack-protector endif # Used by KCSAN while enabled, avoid recursion.@@ -300,7 +300,7 @@ endif UBSAN_SANITIZE_ubsan.o := n KASAN_SANITIZE_ubsan.o := n KCSAN_SANITIZE_ubsan.o := n -CFLAGS_ubsan.o := $(call cc-option, -fno-stack-protector) $(DISABLE_STACKLEAK_PLUGIN) +CFLAGS_ubsan.o := -fno-stack-protector $(DISABLE_STACKLEAK_PLUGIN) obj-$(CONFIG_SBITMAP) += sbitmap.omm/kasan/Makefile +1
-2@@ -16,7 +16,7 @@ CFLAGS_REMOVE_tags_report.o = $(CC_FLAGS_FTRACE) # Function splitter causes unnecessary splits in __asan_load1/__asan_store1 # see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63533 CC_FLAGS_KASAN_RUNTIME := $(call cc-option, -fno-conserve-stack) -CC_FLAGS_KASAN_RUNTIME += $(call cc-option, -fno-stack-protector) +CC_FLAGS_KASAN_RUNTIME += -fno-stack-protector # Disable branch tracing to avoid recursion. CC_FLAGS_KASAN_RUNTIME += -DDISABLE_BRANCH_PROFILING --
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 7 lines · Nick Desaulniers
Quoted 6 lines · Masahiro Yamada
+++ b/Makefile
Makefile +0
-0@@ -762,7 +762,7 @@ ifneq ($(CONFIG_FRAME_WARN),0) KBUILD_CFLAGS += -Wframe-larger-than=$(CONFIG_FRAME_WARN) endif
Quoted 15 lines
Makefile ifneq ($(CONFIG_FRAME_WARN),0) · line 767
Quoted 4 lines
Makefile +1
-1-stackp-flags-$(CONFIG_CC_HAS_STACKPROTECTOR_NONE) := -fno-stack-protector +stackp-flags-y := -fno-stack-protector stackp-flags-$(CONFIG_STACKPROTECTOR) := -fstack-protector stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strongSo it looks like the previous behavior always added
-fno-stack-protector(sinceCONFIG_CC_HAS_STACKPROTECTOR_NONEwas always true), but then we append either-fstack-protectoror-fstack-protector-strongbased on configs. While that's ok, and you patch doesn't change that behavior, and it's good to be explicit to set the stack protector or not...it seems weird to have-fno-stack-protector -fstack-protectorin the command line flags. I would prefer if we checked for not havingCONFIG_STACKPROTECTORorCONFIG_STACKPROTECTOR_STRONGbefore adding-fno-stack-protector. That doesn't have to be done in this patch, per se.
No, it would add only what was latest and most selected. (They're all ":=" assignments.) If CONFIG_STACKPROTECTOR_STRONG, only -fstack-protector-strong is set. If only CONFIG_STACKPROTECTOR, only -fstack-protector is set. Otherwise -fno-stack-protector.
Signature · 1 line
Kees Cook
Quoted 27 lines · Kees Cook
Quoted 7 lines · Nick Desaulniers
Quoted 6 lines · Masahiro Yamada
+++ b/Makefile
Makefile +0
-0@@ -762,7 +762,7 @@ ifneq ($(CONFIG_FRAME_WARN),0) KBUILD_CFLAGS += -Wframe-larger-than=$(CONFIG_FRAME_WARN) endifQuoted 15 lines
Makefile ifneq ($(CONFIG_FRAME_WARN),0) · line 767
Quoted 4 lines
Makefile +1
-1-stackp-flags-$(CONFIG_CC_HAS_STACKPROTECTOR_NONE) := -fno-stack-protector +stackp-flags-y := -fno-stack-protector stackp-flags-$(CONFIG_STACKPROTECTOR) := -fstack-protector stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strongSo it looks like the previous behavior always added
-fno-stack-protector(sinceCONFIG_CC_HAS_STACKPROTECTOR_NONEwas always true), but then we append either-fstack-protectoror-fstack-protector-strongbased on configs. While that's ok, and you patch doesn't change that behavior, and it's good to be explicit to set the stack protector or not...it seems weird to have-fno-stack-protector -fstack-protectorin the command line flags. I would prefer if we checked for not havingCONFIG_STACKPROTECTORorCONFIG_STACKPROTECTOR_STRONGbefore adding-fno-stack-protector. That doesn't have to be done in this patch, per se.No, it would add only what was latest and most selected. (They're all ":=" assignments.) If
CONFIG_STACKPROTECTOR_STRONG, only
Review
Quoted 2 lines
(quoted diff) +0
-2-fstack-protector-strong is set. If only CONFIG_STACKPROTECTOR, only -fstack-protector is set. Otherwise -fno-stack-protector.
Ah, right. Thanks for pointing that out. I'm still curious if the CFLAGS_<file>.o rules get appended or overwrite all flags for that translation unit?
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 3 lines · Nick Desaulniers
Ah, right. Thanks for pointing that out. I'm still curious if the CFLAGS_<file>.o rules get appended or overwrite all flags for that translation unit?
CFLAGS_file.o gets appended to the CFLAGS. For example, after my updated patch[1], the command line for syscall_64.o looks like this:
gcc -Wp,-MMD,arch/x86/entry/.syscall_64.o.d -nostdinc -isystem \
...
-Wframe-larger-than=2048 -fstack-protector-strong \
...
-fno-stack-protector -Wno-override-init \
-DKBUILD_MODFILE='"arch/x86/entry/syscall_64"' \
-DKBUILD_BASENAME='"syscall_64"' \
-DKBUILD_MODNAME='"syscall_64"' \
-c -o arch/x86/entry/syscall_64.o \arch/x86/entry/syscall_64.c
-Kees
[1] https://lore.kernel.org/lkml/202006261333.585319CA6B@keescook/
Signature · 1 line
Kees Cook
Quoted 259 lines · Nick Desaulniers
Quoted 10 lines · Masahiro Yamada
Some Makefiles already pass -fno-stack-protector unconditionally. For example,
arch/arm64/kernel/vdso/Makefile,arch/x86/xen/Makefile. No problem report so far about hard-coding this option. So, we can assume all supported compilers know -fno-stack-protector.GCC 4.8 and Clang support this option (https://godbolt.org/z/_HDGzN)
Get rid of cc-option from -fno-stack-protector.
Quoted 7 lines
Remove
CONFIG_CC_HAS_STACKPROTECTOR_NONE, which should always be 'y'.Note:
arch/mips/vdso/Makefileadds -fno-stack-protector twice, first unconditionally, and second conditionally. I removed the second one.Signed-off-by Masahiro Yamada <[email protected]>Generally looks pretty good, just a few more questions before adding my tag explicitly.
Quoted 48 lines
---
Documentation/kbuild/kconfig-language.rst | 4 ++-- Makefile | 2 +- arch/Kconfig | 3 --- arch/arm/boot/compressed/Makefile | 3 +-- arch/mips/vdso/Makefile | 3 +-- arch/powerpc/kernel/Makefile | 2 +- arch/powerpc/platforms/powermac/Makefile | 2 +- arch/sparc/vdso/Makefile | 4 ++-- arch/um/Makefile | 3 +-- arch/x86/Makefile | 2 +- arch/x86/boot/compressed/Makefile | 2 +- arch/x86/entry/vdso/Makefile | 4 ++-- arch/x86/kernel/cpu/Makefile | 3 +-- arch/x86/lib/Makefile | 2 +- arch/x86/mm/Makefile | 7 +++---- arch/x86/power/Makefile | 3 +-- arch/x86/purgatory/Makefile | 2 +- arch/x86/um/vdso/Makefile | 2 +- arch/x86/xen/Makefile | 5 ++--- drivers/firmware/efi/libstub/Makefile | 2 +- drivers/xen/Makefile | 3 +-- kernel/kcsan/Makefile | 3 +-- lib/Makefile | 4 ++-- mm/kasan/Makefile | 2 +- 24 files changed, 30 insertions(+), 42 deletions(-)Documentation/kbuild/kconfig-language.rst +2
-2@@ -540,8 +540,8 @@ followed by a test macro:: If you need to expose a compiler capability to makefiles and/or C source files, `CC_HAS_` is the recommended prefix for the config option:: - config CC_HAS_STACKPROTECTOR_NONE - def_bool $(cc-option,-fno-stack-protector) + config CC_HAS_ASM_GOTO + def_bool $(success,$(srctree)/scripts/gcc-goto.sh $(CC)) Build as module only ~~~~~~~~~~~~~~~~~~~~Makefile +0
-0Makefile ifneq ($(CONFIG_FRAME_WARN),0) · line 767
Quoted 7 lines
Makefile +1
-1@@ -762,7 +762,7 @@ ifneq ($(CONFIG_FRAME_WARN),0) KBUILD_CFLAGS += -Wframe-larger-than=$(CONFIG_FRAME_WARN) endif -stackp-flags-$(CONFIG_CC_HAS_STACKPROTECTOR_NONE) := -fno-stack-protector +stackp-flags-y := -fno-stack-protector stackp-flags-$(CONFIG_STACKPROTECTOR) := -fstack-protector stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strongSo it looks like the previous behavior always added
-fno-stack-protector(sinceCONFIG_CC_HAS_STACKPROTECTOR_NONEwas always true), but then we append either-fstack-protectoror-fstack-protector-strongbased on configs. While that's ok, and you patch doesn't change that behavior, and it's good to be explicit to set the stack protector or not...it seems weird to have-fno-stack-protector -fstack-protectorin the command line flags. I would prefer if we checked for not havingCONFIG_STACKPROTECTORorCONFIG_STACKPROTECTOR_STRONGbefore adding-fno-stack-protector. That doesn't have to be done in this patch, per se.Quoted 158 lines
arch/Kconfig +0
-3@@ -478,9 +478,6 @@ config HAVE_STACKPROTECTOR An arch should select this symbol if: - it has implemented a stack canary (e.g. __stack_chk_guard) -config CC_HAS_STACKPROTECTOR_NONE - def_bool $(cc-option,-fno-stack-protector) - config STACKPROTECTOR bool "Stack Protector buffer overflow detection" depends on HAVE_STACKPROTECTORarch/arm/boot/compressed/Makefile +1
-2@@ -84,9 +84,8 @@ endif # -fstack-protector-strong triggers protection checks in this code, # but it is being used too early to link to meaningful stack_chk logic. -nossp-flags-$(CONFIG_CC_HAS_STACKPROTECTOR_NONE) := -fno-stack-protector $(foreach o, $(libfdt_objs) atags_to_fdt.o, \ - $(eval CFLAGS_$(o) := -I $(srctree)/scripts/dtc/libfdt $(nossp-flags-y))) + $(eval CFLAGS_$(o) := -I $(srctree)/scripts/dtc/libfdt -fno-stack-protector)) # These were previously generated C files. When you are building the kernel # with O=, make sure to remove the stale files in the output tree. Otherwise,arch/mips/vdso/Makefile +1
-2@@ -35,8 +35,7 @@ cflags-vdso := $(ccflags-vdso) \ -O3 -g -fPIC -fno-strict-aliasing -fno-common -fno-builtin -G 0 \ -mrelax-pic-calls $(call cc-option, -mexplicit-relocs) \ -fno-stack-protector -fno-jump-tables -DDISABLE_BRANCH_PROFILING \ - $(call cc-option, -fno-asynchronous-unwind-tables) \ - $(call cc-option, -fno-stack-protector) + $(call cc-option, -fno-asynchronous-unwind-tables) aflags-vdso := $(ccflags-vdso) \ -D__ASSEMBLY__ -Wa,-gdwarf-2arch/powerpc/kernel/Makefile +1
-1@@ -16,7 +16,7 @@ CFLAGS_prom_init.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) CFLAGS_btext.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) CFLAGS_prom.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) -CFLAGS_prom_init.o += $(call cc-option, -fno-stack-protector) +CFLAGS_prom_init.o += -fno-stack-protector CFLAGS_prom_init.o += -DDISABLE_BRANCH_PROFILING CFLAGS_prom_init.o += -ffreestandingarch/powerpc/platforms/powermac/Makefile +1
-1@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 CFLAGS_bootx_init.o += -fPIC -CFLAGS_bootx_init.o += $(call cc-option, -fno-stack-protector) +CFLAGS_bootx_init.o += -fno-stack-protector KASAN_SANITIZE_bootx_init.o := narch/sparc/vdso/Makefile +2
-2@@ -54,7 +54,7 @@ $(obj)/vdso-image-%.c: $(obj)/vdso%.so.dbg $(obj)/vdso%.so $(obj)/vdso2c FORCE # optimize sibling calls. # CFL := $(PROFILING) -mcmodel=medlow -fPIC -O2 -fasynchronous-unwind-tables -m64 \ - $(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \ + $(filter -g%,$(KBUILD_CFLAGS)) -fno-stack-protector \ -fno-omit-frame-pointer -foptimize-sibling-calls \ -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO@@ -93,7 +93,7 @@ KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(SPARC_REG_CFLAGS),$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 += -m32 -msoft-float -fpic -KBUILD_CFLAGS_32 += $(call cc-option, -fno-stack-protector) +KBUILD_CFLAGS_32 += -fno-stack-protector KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls) KBUILD_CFLAGS_32 += -fno-omit-frame-pointer KBUILD_CFLAGS_32 += -DDISABLE_BRANCH_PROFILINGarch/um/Makefile +1
-2@@ -121,8 +121,7 @@ LINK-$(CONFIG_LD_SCRIPT_STATIC) += -static LINK-$(CONFIG_LD_SCRIPT_DYN) += -Wl,-rpath,/lib $(call cc-option, -no-pie) CFLAGS_NO_HARDENING := $(call cc-option, -fno-PIC,) $(call cc-option, -fno-pic,) \ - $(call cc-option, -fno-stack-protector,) \ - $(call cc-option, -fno-stack-protector-all,) + -fno-stack-protector $(call cc-option, -fno-stack-protector-all) # Options used by linker script export LDS_START := $(START)arch/x86/Makefile +1
-1@@ -37,7 +37,7 @@ REALMODE_CFLAGS := $(M16_CFLAGS) -g -Os -DDISABLE_BRANCH_PROFILING \ -mno-mmx -mno-sse REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -ffreestanding) -REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -fno-stack-protector) +REALMODE_CFLAGS += -fno-stack-protector REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -Wno-address-of-packed-member) REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), $(cc_stack_align4)) export REALMODE_CFLAGSarch/x86/boot/compressed/Makefile +1
-1@@ -36,7 +36,7 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small KBUILD_CFLAGS += $(cflags-y) KBUILD_CFLAGS += -mno-mmx -mno-sse KBUILD_CFLAGS += $(call cc-option,-ffreestanding) -KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector) +KBUILD_CFLAGS += -fno-stack-protector KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) KBUILD_CFLAGS += $(call cc-disable-warning, gnu) KBUILD_CFLAGS += -Wno-pointer-signarch/x86/entry/vdso/Makefile +2
-2@@ -82,7 +82,7 @@ $(obj)/vdso-image-%.c: $(obj)/vdso%.so.dbg $(obj)/vdso%.so $(obj)/vdso2c FORCE # optimize sibling calls. # CFL := $(PROFILING) -mcmodel=small -fPIC -O2 -fasynchronous-unwind-tables -m64 \ - $(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \ + $(filter -g%,$(KBUILD_CFLAGS)) -fno-stack-protector \ -fno-omit-frame-pointer -foptimize-sibling-calls \ -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO@@ -151,7 +151,7 @@ KBUILD_CFLAGS_32 := $(filter-out -mfentry,$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 += -m32 -msoft-float -mregparm=0 -fpic -KBUILD_CFLAGS_32 += $(call cc-option, -fno-stack-protector) +KBUILD_CFLAGS_32 += -fno-stack-protector KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls) KBUILD_CFLAGS_32 += -fno-omit-frame-pointer KBUILD_CFLAGS_32 += -DDISABLE_BRANCH_PROFILINGarch/x86/kernel/cpu/Makefile +0
-0arch/x86/kernel/cpu/Makefile KCOV_INSTRUMENT_perf_event.o := n · line 20
Quoted 6 lines
arch/x86/kernel/cpu/Makefile +1
-2@@ -17,8 +17,7 @@ KCOV_INSTRUMENT_perf_event.o := n KCSAN_SANITIZE_common.o := n # Make sure load_percpu_segment has no stackprotector -nostackp := $(call cc-option, -fno-stack-protector) -CFLAGS_common.o := $(nostackp) +CFLAGS_common.o := -fno-stack-protectorAny time I see
:=assignment to a CFLAGS variable, it's a red flag for overwriting existing CFLAGS, which is a common source of bugs. I recognize the kernel is current a mix and match for:
Quoted 8 lines
CFLAGS_<file>.o
rules to either use
+=or:=, but I wish we were consistent, and consistent in our use of+=. For those rules, is there a difference between the use of+=and:=like there is for the more general case of appending toKBUILD_CFLAGS? If not, it's ok to match the existing style, but it's curious to me in this patch to see a mixed use of+=and:=.
I think Kees mostly answered your question.
Let me add some comments.
'+=' is the most used in kernel Makefiles, but
':=' and '=' are also used.
So, you are right, we are inconsistent.
This applies to not only CFLAGS_<file>.o, but also obj-y, etc.
For example,
https://github.com/torvalds/linux/blob/v5.7/arch/arm64/kernel/Makefile#L15
'obj-y :=' works since it is the first assignment to obj-y in that file. 'obj-y +=' also works, of course.
We can consistently use '+=' everywhere, but I do not send patches for churn.
You can use any assignment operator to CFLAGS_<file>.o if it is the first assignment in the Makefile.
Using '+=' is robust for future code insertion/removal, though.
If the right-hand side contains variable references, there is important difference in the behavior.
You may know two flavors in variables
(https://www.gnu.org/software/make/manual/make.html#Flavors)
CFLAGS_foo.o := $(call cc-option,-fno-stack-protector) The cc-option is expanded immediately when this line is parsed. (So, the compiler is invoked for 'make clean' too)
CFLAGS_foo.o += $(call cc-option,-fno-stack-protector) If this is the first assignment in the file, '+=' act as '=', so the evaluation of cc-option is delayed until $(CFLAGS_foo.o) is expanded. (So, the compiler is NOT invoked for 'make clean')
Signature · 2 lines
Best Regards Masahiro Yamada
Nick Desaulniers
Reviewed-byQuoted 297 lines · Masahiro Yamada
Quoted 259 lines · Nick Desaulniers
Quoted 10 lines · Masahiro Yamada
Some Makefiles already pass -fno-stack-protector unconditionally. For example,
arch/arm64/kernel/vdso/Makefile,arch/x86/xen/Makefile. No problem report so far about hard-coding this option. So, we can assume all supported compilers know -fno-stack-protector.GCC 4.8 and Clang support this option (https://godbolt.org/z/_HDGzN)
Get rid of cc-option from -fno-stack-protector.
Quoted 7 lines
Remove
CONFIG_CC_HAS_STACKPROTECTOR_NONE, which should always be 'y'.Note:
arch/mips/vdso/Makefileadds -fno-stack-protector twice, first unconditionally, and second conditionally. I removed the second one.Signed-off-by Masahiro Yamada <[email protected]>Generally looks pretty good, just a few more questions before adding my tag explicitly.
Quoted 48 lines
---
Documentation/kbuild/kconfig-language.rst | 4 ++-- Makefile | 2 +- arch/Kconfig | 3 --- arch/arm/boot/compressed/Makefile | 3 +-- arch/mips/vdso/Makefile | 3 +-- arch/powerpc/kernel/Makefile | 2 +- arch/powerpc/platforms/powermac/Makefile | 2 +- arch/sparc/vdso/Makefile | 4 ++-- arch/um/Makefile | 3 +-- arch/x86/Makefile | 2 +- arch/x86/boot/compressed/Makefile | 2 +- arch/x86/entry/vdso/Makefile | 4 ++-- arch/x86/kernel/cpu/Makefile | 3 +-- arch/x86/lib/Makefile | 2 +- arch/x86/mm/Makefile | 7 +++---- arch/x86/power/Makefile | 3 +-- arch/x86/purgatory/Makefile | 2 +- arch/x86/um/vdso/Makefile | 2 +- arch/x86/xen/Makefile | 5 ++--- drivers/firmware/efi/libstub/Makefile | 2 +- drivers/xen/Makefile | 3 +-- kernel/kcsan/Makefile | 3 +-- lib/Makefile | 4 ++-- mm/kasan/Makefile | 2 +- 24 files changed, 30 insertions(+), 42 deletions(-)Documentation/kbuild/kconfig-language.rst +2
-2@@ -540,8 +540,8 @@ followed by a test macro:: If you need to expose a compiler capability to makefiles and/or C source files, `CC_HAS_` is the recommended prefix for the config option:: - config CC_HAS_STACKPROTECTOR_NONE - def_bool $(cc-option,-fno-stack-protector) + config CC_HAS_ASM_GOTO + def_bool $(success,$(srctree)/scripts/gcc-goto.sh $(CC)) Build as module only ~~~~~~~~~~~~~~~~~~~~Makefile +0
-0Makefile ifneq ($(CONFIG_FRAME_WARN),0) · line 767
Quoted 7 lines
Makefile +1
-1@@ -762,7 +762,7 @@ ifneq ($(CONFIG_FRAME_WARN),0) KBUILD_CFLAGS += -Wframe-larger-than=$(CONFIG_FRAME_WARN) endif -stackp-flags-$(CONFIG_CC_HAS_STACKPROTECTOR_NONE) := -fno-stack-protector +stackp-flags-y := -fno-stack-protector stackp-flags-$(CONFIG_STACKPROTECTOR) := -fstack-protector stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strongSo it looks like the previous behavior always added
-fno-stack-protector(sinceCONFIG_CC_HAS_STACKPROTECTOR_NONEwas always true), but then we append either-fstack-protectoror-fstack-protector-strongbased on configs. While that's ok, and you patch doesn't change that behavior, and it's good to be explicit to set the stack protector or not...it seems weird to have-fno-stack-protector -fstack-protectorin the command line flags. I would prefer if we checked for not havingCONFIG_STACKPROTECTORorCONFIG_STACKPROTECTOR_STRONGbefore adding-fno-stack-protector. That doesn't have to be done in this patch, per se.Quoted 158 lines
arch/Kconfig +0
-3@@ -478,9 +478,6 @@ config HAVE_STACKPROTECTOR An arch should select this symbol if: - it has implemented a stack canary (e.g. __stack_chk_guard) -config CC_HAS_STACKPROTECTOR_NONE - def_bool $(cc-option,-fno-stack-protector) - config STACKPROTECTOR bool "Stack Protector buffer overflow detection" depends on HAVE_STACKPROTECTORarch/arm/boot/compressed/Makefile +1
-2@@ -84,9 +84,8 @@ endif # -fstack-protector-strong triggers protection checks in this code, # but it is being used too early to link to meaningful stack_chk logic. -nossp-flags-$(CONFIG_CC_HAS_STACKPROTECTOR_NONE) := -fno-stack-protector $(foreach o, $(libfdt_objs) atags_to_fdt.o, \ - $(eval CFLAGS_$(o) := -I $(srctree)/scripts/dtc/libfdt $(nossp-flags-y))) + $(eval CFLAGS_$(o) := -I $(srctree)/scripts/dtc/libfdt -fno-stack-protector)) # These were previously generated C files. When you are building the kernel # with O=, make sure to remove the stale files in the output tree. Otherwise,arch/mips/vdso/Makefile +1
-2@@ -35,8 +35,7 @@ cflags-vdso := $(ccflags-vdso) \ -O3 -g -fPIC -fno-strict-aliasing -fno-common -fno-builtin -G 0 \ -mrelax-pic-calls $(call cc-option, -mexplicit-relocs) \ -fno-stack-protector -fno-jump-tables -DDISABLE_BRANCH_PROFILING \ - $(call cc-option, -fno-asynchronous-unwind-tables) \ - $(call cc-option, -fno-stack-protector) + $(call cc-option, -fno-asynchronous-unwind-tables) aflags-vdso := $(ccflags-vdso) \ -D__ASSEMBLY__ -Wa,-gdwarf-2arch/powerpc/kernel/Makefile +1
-1@@ -16,7 +16,7 @@ CFLAGS_prom_init.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) CFLAGS_btext.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) CFLAGS_prom.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) -CFLAGS_prom_init.o += $(call cc-option, -fno-stack-protector) +CFLAGS_prom_init.o += -fno-stack-protector CFLAGS_prom_init.o += -DDISABLE_BRANCH_PROFILING CFLAGS_prom_init.o += -ffreestandingarch/powerpc/platforms/powermac/Makefile +1
-1@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 CFLAGS_bootx_init.o += -fPIC -CFLAGS_bootx_init.o += $(call cc-option, -fno-stack-protector) +CFLAGS_bootx_init.o += -fno-stack-protector KASAN_SANITIZE_bootx_init.o := narch/sparc/vdso/Makefile +2
-2@@ -54,7 +54,7 @@ $(obj)/vdso-image-%.c: $(obj)/vdso%.so.dbg $(obj)/vdso%.so $(obj)/vdso2c FORCE # optimize sibling calls. # CFL := $(PROFILING) -mcmodel=medlow -fPIC -O2 -fasynchronous-unwind-tables -m64 \ - $(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \ + $(filter -g%,$(KBUILD_CFLAGS)) -fno-stack-protector \ -fno-omit-frame-pointer -foptimize-sibling-calls \ -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO@@ -93,7 +93,7 @@ KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(SPARC_REG_CFLAGS),$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 += -m32 -msoft-float -fpic -KBUILD_CFLAGS_32 += $(call cc-option, -fno-stack-protector) +KBUILD_CFLAGS_32 += -fno-stack-protector KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls) KBUILD_CFLAGS_32 += -fno-omit-frame-pointer KBUILD_CFLAGS_32 += -DDISABLE_BRANCH_PROFILINGarch/um/Makefile +1
-2@@ -121,8 +121,7 @@ LINK-$(CONFIG_LD_SCRIPT_STATIC) += -static LINK-$(CONFIG_LD_SCRIPT_DYN) += -Wl,-rpath,/lib $(call cc-option, -no-pie) CFLAGS_NO_HARDENING := $(call cc-option, -fno-PIC,) $(call cc-option, -fno-pic,) \ - $(call cc-option, -fno-stack-protector,) \ - $(call cc-option, -fno-stack-protector-all,) + -fno-stack-protector $(call cc-option, -fno-stack-protector-all) # Options used by linker script export LDS_START := $(START)arch/x86/Makefile +1
-1@@ -37,7 +37,7 @@ REALMODE_CFLAGS := $(M16_CFLAGS) -g -Os -DDISABLE_BRANCH_PROFILING \ -mno-mmx -mno-sse REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -ffreestanding) -REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -fno-stack-protector) +REALMODE_CFLAGS += -fno-stack-protector REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -Wno-address-of-packed-member) REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), $(cc_stack_align4)) export REALMODE_CFLAGSarch/x86/boot/compressed/Makefile +1
-1@@ -36,7 +36,7 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small KBUILD_CFLAGS += $(cflags-y) KBUILD_CFLAGS += -mno-mmx -mno-sse KBUILD_CFLAGS += $(call cc-option,-ffreestanding) -KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector) +KBUILD_CFLAGS += -fno-stack-protector KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) KBUILD_CFLAGS += $(call cc-disable-warning, gnu) KBUILD_CFLAGS += -Wno-pointer-signarch/x86/entry/vdso/Makefile +2
-2@@ -82,7 +82,7 @@ $(obj)/vdso-image-%.c: $(obj)/vdso%.so.dbg $(obj)/vdso%.so $(obj)/vdso2c FORCE # optimize sibling calls. # CFL := $(PROFILING) -mcmodel=small -fPIC -O2 -fasynchronous-unwind-tables -m64 \ - $(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \ + $(filter -g%,$(KBUILD_CFLAGS)) -fno-stack-protector \ -fno-omit-frame-pointer -foptimize-sibling-calls \ -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO@@ -151,7 +151,7 @@ KBUILD_CFLAGS_32 := $(filter-out -mfentry,$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 += -m32 -msoft-float -mregparm=0 -fpic -KBUILD_CFLAGS_32 += $(call cc-option, -fno-stack-protector) +KBUILD_CFLAGS_32 += -fno-stack-protector KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls) KBUILD_CFLAGS_32 += -fno-omit-frame-pointer KBUILD_CFLAGS_32 += -DDISABLE_BRANCH_PROFILINGarch/x86/kernel/cpu/Makefile +0
-0arch/x86/kernel/cpu/Makefile KCOV_INSTRUMENT_perf_event.o := n · line 20
Quoted 6 lines
arch/x86/kernel/cpu/Makefile +1
-2@@ -17,8 +17,7 @@ KCOV_INSTRUMENT_perf_event.o := n KCSAN_SANITIZE_common.o := n # Make sure load_percpu_segment has no stackprotector -nostackp := $(call cc-option, -fno-stack-protector) -CFLAGS_common.o := $(nostackp) +CFLAGS_common.o := -fno-stack-protectorAny time I see
:=assignment to a CFLAGS variable, it's a red flag for overwriting existing CFLAGS, which is a common source of bugs. I recognize the kernel is current a mix and match for:Quoted 8 lines
CFLAGS_<file>.o
rules to either use
+=or:=, but I wish we were consistent, and consistent in our use of+=. For those rules, is there a difference between the use of+=and:=like there is for the more general case of appending toKBUILD_CFLAGS? If not, it's ok to match the existing style, but it's curious to me in this patch to see a mixed use of+=and:=.I think Kees mostly answered your question.
Let me add some comments.
'+=' is the most used in kernel Makefiles, but
':=' and '=' are also used.So, you are right, we are inconsistent.
This applies to not only CFLAGS_<file>.o, but also obj-y, etc.For example,
https://github.com/torvalds/linux/blob/v5.7/arch/arm64/kernel/Makefile#L15
'obj-y :=' works since it is the first assignment to obj-y in that file. 'obj-y +=' also works, of course.We can consistently use '+=' everywhere, but I do not send patches for churn.
You can use any assignment operator to CFLAGS_<file>.o if it is the first assignment in the
Makefile.
Using '+=' is robust for future code insertion/removal, though.
Quoted 5 lines
If the right-hand side contains variable references, there is important difference in the behavior.
You may know two flavors in variables
(https://www.gnu.org/software/make/manual/make.html#Flavors)
Cool, thanks for all the info. With that, I'm happy with this patch.
Quoted 10 lines
CFLAGS_foo.o := $(call cc-option,-fno-stack-protector) The cc-option is expanded immediately when this line is parsed. (So, the compiler is invoked for 'make clean' too)
CFLAGS_foo.o += $(call cc-option,-fno-stack-protector) If this is the first assignment in the file, '+=' act as '=', so the evaluation of cc-option is delayed until $(CFLAGS_foo.o) is expanded. (So, the compiler is NOT invoked for 'make clean')
Ah, I think that may explain: I've been seeing the occasional warning from $(NM) when running make clean for ARCH=arm, I'll bet that's where this is coming from then. Next time I reproduce it, I'll try to find maybe where we're using := or = with $(NM).
Maybe arch/arm/boot/compressed/Makefile, KBSS_SZ is evaluated for make clean? (If you start an arm build, but kill it before vmlinux is created, then make clean I suspect that KBSS_SZ is evaluated?)
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 81 lines · Nick Desaulniers
Quoted 57 lines · Masahiro Yamada
Quoted 19 lines · Nick Desaulniers
arch/x86/kernel/cpu/Makefile KCOV_INSTRUMENT_perf_event.o := n · line 20
Quoted 12 lines · Masahiro Yamada
arch/x86/kernel/cpu/Makefile +1
-2@@ -17,8 +17,7 @@ KCOV_INSTRUMENT_perf_event.o := n KCSAN_SANITIZE_common.o := n # Make sure load_percpu_segment has no stackprotector -nostackp := $(call cc-option, -fno-stack-protector) -CFLAGS_common.o := $(nostackp) +CFLAGS_common.o := -fno-stack-protectorAny time I see
:=assignment to a CFLAGS variable, it's a red flag for overwriting existing CFLAGS, which is a common source of bugs. I recognize the kernel is current a mix and match for:Quoted 8 lines
CFLAGS_<file>.o
rules to either use
+=or:=, but I wish we were consistent, and consistent in our use of+=. For those rules, is there a difference between the use of+=and:=like there is for the more general case of appending toKBUILD_CFLAGS? If not, it's ok to match the existing style, but it's curious to me in this patch to see a mixed use of+=and:=.I think Kees mostly answered your question.
Let me add some comments.
'+=' is the most used in kernel Makefiles, but
':=' and '=' are also used.So, you are right, we are inconsistent.
This applies to not only CFLAGS_<file>.o, but also obj-y, etc.For example,
https://github.com/torvalds/linux/blob/v5.7/arch/arm64/kernel/Makefile#L15
'obj-y :=' works since it is the first assignment to obj-y in that file. 'obj-y +=' also works, of course.We can consistently use '+=' everywhere, but I do not send patches for churn.
You can use any assignment operator to CFLAGS_<file>.o if it is the first assignment in the
Makefile.
Using '+=' is robust for future code insertion/removal, though.Quoted 5 lines
If the right-hand side contains variable references, there is important difference in the behavior.
You may know two flavors in variables
(https://www.gnu.org/software/make/manual/make.html#Flavors)Cool, thanks for all the info. With that, I'm happy with this patch.
Reviewed-by Nick Desaulniers <[email protected]>Quoted 10 lines
CFLAGS_foo.o := $(call cc-option,-fno-stack-protector) The cc-option is expanded immediately when this line is parsed. (So, the compiler is invoked for 'make clean' too)
CFLAGS_foo.o += $(call cc-option,-fno-stack-protector) If this is the first assignment in the file, '+=' act as '=', so the evaluation of cc-option is delayed until $(CFLAGS_foo.o) is expanded. (So, the compiler is NOT invoked for 'make clean')
Quoted 8 lines
Ah, I think that may explain: I've been seeing the occasional warning from $(NM) when running
make cleanfor ARCH=arm, I'll bet that's where this is coming from then. Next time I reproduce it, I'll try to find maybe where we're using:=or=with$(NM).Maybe
arch/arm/boot/compressed/Makefile,KBSS_SZis evaluated formake clean? (If you start an arm build, but kill it before vmlinux is created, thenmake cleanI suspect thatKBSS_SZis evaluated?)
$ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make LLVM=1 -j71 $ rm vmlinux $ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make LLVM=1 -j71 clean llvm-nm: error: arch/arm/boot/compressed/../../../../vmlinux: No such file or directory.
I suspect I see this from doing an ARCH=arm build, then building a different ARCH and killing the build before vmlinux is produced or make clean for a different ARCH, then run a make clean for ARCH=arm.
Is the above (regarding lazy evaluation) not true for LDFLAGS_vmlinux? I would have thought this would work:
(quoted diff) +0 -0
b/arch/arm/boot/compressed/Makefile
index 00602a6fba04..9e7343ccc279 100644
arch/arm/boot/compressed/Makefile +0 -0
@@ -113,10 +113,9 @@ ccflags-y := -fpic $(call
cc-option,-mno-single-pic-base,) -fno-builtin \
asflags-y := -DZIMAGE
# Supply kernel BSS size to the decompressor via a linker symbol.
-KBSS_SZ = $(shell echo $$(($$($(NM) $(obj)/../../../../vmlinux | \
+LDFLAGS_vmlinux = --defsym _kernel_bss_size=$(shell echo $$(($$($(NM)
$(obj)/../../../../vmlinux | \
sed -n -e 's/^\([^ ]*\) [AB] __bss_start$$/-0x\1/p' \- -e 's/^\([^ ]*\) [AB] __bss_stop$$/+0x\1/p') )) )
-LDFLAGS_vmlinux = --defsym _kernel_bss_size=$(KBSS_SZ)
+ -e 's/^\([^ ]*\) [AB]
__bss_stop$$/+0x\1/p') )) )
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 93 lines · Nick Desaulniers
Quoted 81 lines · Nick Desaulniers
Quoted 57 lines · Masahiro Yamada
Quoted 19 lines · Nick Desaulniers
arch/x86/kernel/cpu/Makefile KCOV_INSTRUMENT_perf_event.o := n · line 20
Quoted 12 lines · Masahiro Yamada
arch/x86/kernel/cpu/Makefile +1
-2@@ -17,8 +17,7 @@ KCOV_INSTRUMENT_perf_event.o := n KCSAN_SANITIZE_common.o := n # Make sure load_percpu_segment has no stackprotector -nostackp := $(call cc-option, -fno-stack-protector) -CFLAGS_common.o := $(nostackp) +CFLAGS_common.o := -fno-stack-protectorAny time I see
:=assignment to a CFLAGS variable, it's a red flag for overwriting existing CFLAGS, which is a common source of bugs. I recognize the kernel is current a mix and match for:Quoted 8 lines
CFLAGS_<file>.o
rules to either use
+=or:=, but I wish we were consistent, and consistent in our use of+=. For those rules, is there a difference between the use of+=and:=like there is for the more general case of appending toKBUILD_CFLAGS? If not, it's ok to match the existing style, but it's curious to me in this patch to see a mixed use of+=and:=.I think Kees mostly answered your question.
Let me add some comments.
'+=' is the most used in kernel Makefiles, but
':=' and '=' are also used.So, you are right, we are inconsistent.
This applies to not only CFLAGS_<file>.o, but also obj-y, etc.For example,
https://github.com/torvalds/linux/blob/v5.7/arch/arm64/kernel/Makefile#L15
'obj-y :=' works since it is the first assignment to obj-y in that file. 'obj-y +=' also works, of course.We can consistently use '+=' everywhere, but I do not send patches for churn.
You can use any assignment operator to CFLAGS_<file>.o if it is the first assignment in the
Makefile.
Using '+=' is robust for future code insertion/removal, though.Quoted 5 lines
If the right-hand side contains variable references, there is important difference in the behavior.
You may know two flavors in variables
(https://www.gnu.org/software/make/manual/make.html#Flavors)Cool, thanks for all the info. With that, I'm happy with this patch.
Reviewed-by Nick Desaulniers <[email protected]>Quoted 10 lines
CFLAGS_foo.o := $(call cc-option,-fno-stack-protector) The cc-option is expanded immediately when this line is parsed. (So, the compiler is invoked for 'make clean' too)
CFLAGS_foo.o += $(call cc-option,-fno-stack-protector) If this is the first assignment in the file, '+=' act as '=', so the evaluation of cc-option is delayed until $(CFLAGS_foo.o) is expanded. (So, the compiler is NOT invoked for 'make clean')
Quoted 8 lines
Ah, I think that may explain: I've been seeing the occasional warning from $(NM) when running
make cleanfor ARCH=arm, I'll bet that's where this is coming from then. Next time I reproduce it, I'll try to find maybe where we're using:=or=with$(NM).Maybe
arch/arm/boot/compressed/Makefile,KBSS_SZis evaluated formake clean? (If you start an arm build, but kill it before vmlinux is created, thenmake cleanI suspect thatKBSS_SZis evaluated?)
Quoted 5 lines
$ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make LLVM=1 -j71 $ rm vmlinux $ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make LLVM=1 -j71 clean llvm-nm: error: arch/arm/boot/compressed/../../../../vmlinux: No such file or directory.
yeah, I had noticed this noise, but I did not get around to digging into it.
Quoted 7 lines
I suspect I see this from doing an ARCH=arm build, then building a different ARCH and killing the build before vmlinux is produced or
make cleanfor a different ARCH, then run amake cleanfor ARCH=arm.Is the above (regarding lazy evaluation) not true for
LDFLAGS_vmlinux? I would have thought this would work:
No, this does not work.
LDFLAGS_vmlinux is assigned by '=', so it already has the lazy expansion flavor.
Unexporting LDFLAGS_vmlinux will fix it. (I may write a better patch, though)
(quoted diff) +0 -0
b/arch/arm/boot/compressed/Makefile index 00602a6fba04..fab54b1c39aa 100644
arch/arm/boot/compressed/Makefile +2 -0
@@ -131,6 +131,8 @@ LDFLAGS_vmlinux += -X # Next argument is a linker script LDFLAGS_vmlinux += -T +unexport LDFLAGS_vmlinux + # For __aeabi_uidivmod lib1funcs = $(obj)/lib1funcs.o
Signature · 2 lines
Best Regards Masahiro Yamada
Quoted 99 lines · Nick Desaulniers
Quoted 81 lines · Nick Desaulniers
Quoted 57 lines · Masahiro Yamada
Quoted 19 lines · Nick Desaulniers
arch/x86/kernel/cpu/Makefile KCOV_INSTRUMENT_perf_event.o := n · line 20
Quoted 12 lines · Masahiro Yamada
arch/x86/kernel/cpu/Makefile +1
-2@@ -17,8 +17,7 @@ KCOV_INSTRUMENT_perf_event.o := n KCSAN_SANITIZE_common.o := n # Make sure load_percpu_segment has no stackprotector -nostackp := $(call cc-option, -fno-stack-protector) -CFLAGS_common.o := $(nostackp) +CFLAGS_common.o := -fno-stack-protectorAny time I see
:=assignment to a CFLAGS variable, it's a red flag for overwriting existing CFLAGS, which is a common source of bugs. I recognize the kernel is current a mix and match for:Quoted 8 lines
CFLAGS_<file>.o
rules to either use
+=or:=, but I wish we were consistent, and consistent in our use of+=. For those rules, is there a difference between the use of+=and:=like there is for the more general case of appending toKBUILD_CFLAGS? If not, it's ok to match the existing style, but it's curious to me in this patch to see a mixed use of+=and:=.I think Kees mostly answered your question.
Let me add some comments.
'+=' is the most used in kernel Makefiles, but
':=' and '=' are also used.So, you are right, we are inconsistent.
This applies to not only CFLAGS_<file>.o, but also obj-y, etc.For example,
https://github.com/torvalds/linux/blob/v5.7/arch/arm64/kernel/Makefile#L15
'obj-y :=' works since it is the first assignment to obj-y in that file. 'obj-y +=' also works, of course.We can consistently use '+=' everywhere, but I do not send patches for churn.
You can use any assignment operator to CFLAGS_<file>.o if it is the first assignment in the
Makefile.
Using '+=' is robust for future code insertion/removal, though.Quoted 5 lines
If the right-hand side contains variable references, there is important difference in the behavior.
You may know two flavors in variables
(https://www.gnu.org/software/make/manual/make.html#Flavors)Cool, thanks for all the info. With that, I'm happy with this patch.
Reviewed-by Nick Desaulniers <[email protected]>Quoted 10 lines
CFLAGS_foo.o := $(call cc-option,-fno-stack-protector) The cc-option is expanded immediately when this line is parsed. (So, the compiler is invoked for 'make clean' too)
CFLAGS_foo.o += $(call cc-option,-fno-stack-protector) If this is the first assignment in the file, '+=' act as '=', so the evaluation of cc-option is delayed until $(CFLAGS_foo.o) is expanded. (So, the compiler is NOT invoked for 'make clean')
Quoted 8 lines
Ah, I think that may explain: I've been seeing the occasional warning from $(NM) when running
make cleanfor ARCH=arm, I'll bet that's where this is coming from then. Next time I reproduce it, I'll try to find maybe where we're using:=or=with$(NM).Maybe
arch/arm/boot/compressed/Makefile,KBSS_SZis evaluated formake clean? (If you start an arm build, but kill it before vmlinux is created, thenmake cleanI suspect thatKBSS_SZis evaluated?)$ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make LLVM=1 -j71 $ rm vmlinux $ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make LLVM=1 -j71 clean llvm-nm: error: arch/arm/boot/compressed/../../../../vmlinux: No such file or directory.
Quoted 8 lines
I suspect I see this from doing an ARCH=arm build, then building a different ARCH and killing the build before vmlinux is produced or
make cleanfor a different ARCH, then run amake cleanfor ARCH=arm.Is the above (regarding lazy evaluation) not true for
LDFLAGS_vmlinux? I would have thought this would work:
I described why this error message is displayed:
https://patchwork.kernel.org/patch/11637129/
Signature · 2 lines
Best Regards Masahiro Yamada
Quoted 9 lines · Masahiro Yamada
Some Makefiles already pass -fno-stack-protector unconditionally. For example,
arch/arm64/kernel/vdso/Makefile,arch/x86/xen/Makefile. No problem report so far about hard-coding this option. So, we can assume all supported compilers know -fno-stack-protector.GCC 4.8 and Clang support this option (https://godbolt.org/z/_HDGzN)
Get rid of cc-option from -fno-stack-protector.
Quoted 7 lines
Remove
CONFIG_CC_HAS_STACKPROTECTOR_NONE, which should always be 'y'.Note:
arch/mips/vdso/Makefileadds -fno-stack-protector twice, first unconditionally, and second conditionally. I removed the second one.Signed-off-by Masahiro Yamada <[email protected]>
Signature · 1 line
Kees Cook
Quoted 10 lines · Masahiro Yamada
Some Makefiles already pass -fno-stack-protector unconditionally. For example,
arch/arm64/kernel/vdso/Makefile,arch/x86/xen/Makefile. No problem report so far about hard-coding this option. So, we can assume all supported compilers know -fno-stack-protector.GCC 4.8 and Clang support this option (https://godbolt.org/z/_HDGzN)
Get rid of cc-option from -fno-stack-protector.
Quoted 7 lines
Remove
CONFIG_CC_HAS_STACKPROTECTOR_NONE, which should always be 'y'.Note:
arch/mips/vdso/Makefileadds -fno-stack-protector twice, first unconditionally, and second conditionally. I removed the second one.Signed-off-by Masahiro Yamada <[email protected]>
Quoted 388 lines
---
Documentation/kbuild/kconfig-language.rst | 4 ++-- Makefile | 2 +- arch/Kconfig | 3 --- arch/arm/boot/compressed/Makefile | 3 +-- arch/mips/vdso/Makefile | 3 +-- arch/powerpc/kernel/Makefile | 2 +- arch/powerpc/platforms/powermac/Makefile | 2 +- arch/sparc/vdso/Makefile | 4 ++-- arch/um/Makefile | 3 +-- arch/x86/Makefile | 2 +- arch/x86/boot/compressed/Makefile | 2 +- arch/x86/entry/vdso/Makefile | 4 ++-- arch/x86/kernel/cpu/Makefile | 3 +-- arch/x86/lib/Makefile | 2 +- arch/x86/mm/Makefile | 7 +++---- arch/x86/power/Makefile | 3 +-- arch/x86/purgatory/Makefile | 2 +- arch/x86/um/vdso/Makefile | 2 +- arch/x86/xen/Makefile | 5 ++--- drivers/firmware/efi/libstub/Makefile | 2 +- drivers/xen/Makefile | 3 +-- kernel/kcsan/Makefile | 3 +-- lib/Makefile | 4 ++-- mm/kasan/Makefile | 2 +- 24 files changed, 30 insertions(+), 42 deletions(-)Documentation/kbuild/kconfig-language.rst +2
-2@@ -540,8 +540,8 @@ followed by a test macro:: If you need to expose a compiler capability to makefiles and/or C source files, `CC_HAS_` is the recommended prefix for the config option:: - config CC_HAS_STACKPROTECTOR_NONE - def_bool $(cc-option,-fno-stack-protector) + config CC_HAS_ASM_GOTO + def_bool $(success,$(srctree)/scripts/gcc-goto.sh $(CC)) Build as module only ~~~~~~~~~~~~~~~~~~~~Makefile +1
-1@@ -762,7 +762,7 @@ ifneq ($(CONFIG_FRAME_WARN),0) KBUILD_CFLAGS += -Wframe-larger-than=$(CONFIG_FRAME_WARN) endif -stackp-flags-$(CONFIG_CC_HAS_STACKPROTECTOR_NONE) := -fno-stack-protector +stackp-flags-y := -fno-stack-protector stackp-flags-$(CONFIG_STACKPROTECTOR) := -fstack-protector stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strongarch/Kconfig +0
-3@@ -478,9 +478,6 @@ config HAVE_STACKPROTECTOR An arch should select this symbol if: - it has implemented a stack canary (e.g. __stack_chk_guard) -config CC_HAS_STACKPROTECTOR_NONE - def_bool $(cc-option,-fno-stack-protector) - config STACKPROTECTOR bool "Stack Protector buffer overflow detection" depends on HAVE_STACKPROTECTORarch/arm/boot/compressed/Makefile +1
-2@@ -84,9 +84,8 @@ endif # -fstack-protector-strong triggers protection checks in this code, # but it is being used too early to link to meaningful stack_chk logic. -nossp-flags-$(CONFIG_CC_HAS_STACKPROTECTOR_NONE) := -fno-stack-protector $(foreach o, $(libfdt_objs) atags_to_fdt.o, \ - $(eval CFLAGS_$(o) := -I $(srctree)/scripts/dtc/libfdt $(nossp-flags-y))) + $(eval CFLAGS_$(o) := -I $(srctree)/scripts/dtc/libfdt -fno-stack-protector)) # These were previously generated C files. When you are building the kernel # with O=, make sure to remove the stale files in the output tree. Otherwise,arch/mips/vdso/Makefile +1
-2@@ -35,8 +35,7 @@ cflags-vdso := $(ccflags-vdso) \ -O3 -g -fPIC -fno-strict-aliasing -fno-common -fno-builtin -G 0 \ -mrelax-pic-calls $(call cc-option, -mexplicit-relocs) \ -fno-stack-protector -fno-jump-tables -DDISABLE_BRANCH_PROFILING \ - $(call cc-option, -fno-asynchronous-unwind-tables) \ - $(call cc-option, -fno-stack-protector) + $(call cc-option, -fno-asynchronous-unwind-tables) aflags-vdso := $(ccflags-vdso) \ -D__ASSEMBLY__ -Wa,-gdwarf-2arch/powerpc/kernel/Makefile +1
-1@@ -16,7 +16,7 @@ CFLAGS_prom_init.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) CFLAGS_btext.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) CFLAGS_prom.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) -CFLAGS_prom_init.o += $(call cc-option, -fno-stack-protector) +CFLAGS_prom_init.o += -fno-stack-protector CFLAGS_prom_init.o += -DDISABLE_BRANCH_PROFILING CFLAGS_prom_init.o += -ffreestandingarch/powerpc/platforms/powermac/Makefile +1
-1@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 CFLAGS_bootx_init.o += -fPIC -CFLAGS_bootx_init.o += $(call cc-option, -fno-stack-protector) +CFLAGS_bootx_init.o += -fno-stack-protector KASAN_SANITIZE_bootx_init.o := narch/sparc/vdso/Makefile +2
-2@@ -54,7 +54,7 @@ $(obj)/vdso-image-%.c: $(obj)/vdso%.so.dbg $(obj)/vdso%.so $(obj)/vdso2c FORCE # optimize sibling calls. # CFL := $(PROFILING) -mcmodel=medlow -fPIC -O2 -fasynchronous-unwind-tables -m64 \ - $(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \ + $(filter -g%,$(KBUILD_CFLAGS)) -fno-stack-protector \ -fno-omit-frame-pointer -foptimize-sibling-calls \ -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO@@ -93,7 +93,7 @@ KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(SPARC_REG_CFLAGS),$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 += -m32 -msoft-float -fpic -KBUILD_CFLAGS_32 += $(call cc-option, -fno-stack-protector) +KBUILD_CFLAGS_32 += -fno-stack-protector KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls) KBUILD_CFLAGS_32 += -fno-omit-frame-pointer KBUILD_CFLAGS_32 += -DDISABLE_BRANCH_PROFILINGarch/um/Makefile +1
-2@@ -121,8 +121,7 @@ LINK-$(CONFIG_LD_SCRIPT_STATIC) += -static LINK-$(CONFIG_LD_SCRIPT_DYN) += -Wl,-rpath,/lib $(call cc-option, -no-pie) CFLAGS_NO_HARDENING := $(call cc-option, -fno-PIC,) $(call cc-option, -fno-pic,) \ - $(call cc-option, -fno-stack-protector,) \ - $(call cc-option, -fno-stack-protector-all,) + -fno-stack-protector $(call cc-option, -fno-stack-protector-all) # Options used by linker script export LDS_START := $(START)arch/x86/Makefile +1
-1@@ -37,7 +37,7 @@ REALMODE_CFLAGS := $(M16_CFLAGS) -g -Os -DDISABLE_BRANCH_PROFILING \ -mno-mmx -mno-sse REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -ffreestanding) -REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -fno-stack-protector) +REALMODE_CFLAGS += -fno-stack-protector REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -Wno-address-of-packed-member) REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), $(cc_stack_align4)) export REALMODE_CFLAGSarch/x86/boot/compressed/Makefile +1
-1@@ -36,7 +36,7 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small KBUILD_CFLAGS += $(cflags-y) KBUILD_CFLAGS += -mno-mmx -mno-sse KBUILD_CFLAGS += $(call cc-option,-ffreestanding) -KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector) +KBUILD_CFLAGS += -fno-stack-protector KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) KBUILD_CFLAGS += $(call cc-disable-warning, gnu) KBUILD_CFLAGS += -Wno-pointer-signarch/x86/entry/vdso/Makefile +2
-2@@ -82,7 +82,7 @@ $(obj)/vdso-image-%.c: $(obj)/vdso%.so.dbg $(obj)/vdso%.so $(obj)/vdso2c FORCE # optimize sibling calls. # CFL := $(PROFILING) -mcmodel=small -fPIC -O2 -fasynchronous-unwind-tables -m64 \ - $(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \ + $(filter -g%,$(KBUILD_CFLAGS)) -fno-stack-protector \ -fno-omit-frame-pointer -foptimize-sibling-calls \ -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO@@ -151,7 +151,7 @@ KBUILD_CFLAGS_32 := $(filter-out -mfentry,$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 += -m32 -msoft-float -mregparm=0 -fpic -KBUILD_CFLAGS_32 += $(call cc-option, -fno-stack-protector) +KBUILD_CFLAGS_32 += -fno-stack-protector KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls) KBUILD_CFLAGS_32 += -fno-omit-frame-pointer KBUILD_CFLAGS_32 += -DDISABLE_BRANCH_PROFILINGarch/x86/kernel/cpu/Makefile +1
-2@@ -17,8 +17,7 @@ KCOV_INSTRUMENT_perf_event.o := n KCSAN_SANITIZE_common.o := n # Make sure load_percpu_segment has no stackprotector -nostackp := $(call cc-option, -fno-stack-protector) -CFLAGS_common.o := $(nostackp) +CFLAGS_common.o := -fno-stack-protector obj-y := cacheinfo.o scattered.o topology.o obj-y += common.oarch/x86/lib/Makefile +1
-1@@ -24,7 +24,7 @@ ifdef CONFIG_FUNCTION_TRACER CFLAGS_REMOVE_cmdline.o = -pg endif -CFLAGS_cmdline.o := $(call cc-option, -fno-stack-protector) +CFLAGS_cmdline.o := -fno-stack-protector endif inat_tables_script = $(srctree)/arch/x86/tools/gen-insn-attr-x86.awkarch/x86/mm/Makefile +3
-4@@ -22,10 +22,9 @@ obj-y := init.o init_$(BITS).o fault.o ioremap.o extable.o mmap.o \ obj-y += pat/ # Make sure __phys_addr has no stackprotector -nostackp := $(call cc-option, -fno-stack-protector) -CFLAGS_physaddr.o := $(nostackp) -CFLAGS_setup_nx.o := $(nostackp) -CFLAGS_mem_encrypt_identity.o := $(nostackp) +CFLAGS_physaddr.o := -fno-stack-protector +CFLAGS_setup_nx.o := -fno-stack-protector +CFLAGS_mem_encrypt_identity.o := -fno-stack-protector CFLAGS_fault.o := -I $(srctree)/$(src)/../include/asm/tracearch/x86/power/Makefile +1
-2@@ -3,8 +3,7 @@ OBJECT_FILES_NON_STANDARD_hibernate_asm_$(BITS).o := y # __restore_processor_state() restores %gs after S3 resume and so should not # itself be stack-protected -nostackp := $(call cc-option, -fno-stack-protector) -CFLAGS_cpu.o := $(nostackp) +CFLAGS_cpu.o := -fno-stack-protector obj-$(CONFIG_PM_SLEEP) += cpu.o obj-$(CONFIG_HIBERNATION) += hibernate_$(BITS).o hibernate_asm_$(BITS).o hibernate.oarch/x86/purgatory/Makefile +1
-1@@ -34,7 +34,7 @@ KCOV_INSTRUMENT := n PURGATORY_CFLAGS_REMOVE := -mcmodel=kernel PURGATORY_CFLAGS := -mcmodel=large -ffreestanding -fno-zero-initialized-in-bss PURGATORY_CFLAGS += $(DISABLE_STACKLEAK_PLUGIN) -DDISABLE_BRANCH_PROFILING -PURGATORY_CFLAGS += $(call cc-option,-fno-stack-protector) +PURGATORY_CFLAGS += -fno-stack-protector # Default KBUILD_CFLAGS can have -pg option set when FTRACE is enabled. That # in turn leaves some undefined symbols like __fentry__ in purgatory and notarch/x86/um/vdso/Makefile +1
-1@@ -42,7 +42,7 @@ $(obj)/%.so: $(obj)/%.so.dbg FORCE # optimize sibling calls. # CFL := $(PROFILING) -mcmodel=small -fPIC -O2 -fasynchronous-unwind-tables -m64 \ - $(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \ + $(filter -g%,$(KBUILD_CFLAGS)) -fno-stack-protector \ -fno-omit-frame-pointer -foptimize-sibling-calls $(vobjs): KBUILD_CFLAGS += $(CFL)arch/x86/xen/Makefile +2
-3@@ -9,9 +9,8 @@ CFLAGS_REMOVE_irq.o = -pg endif # Make sure early boot has no stackprotector -nostackp := $(call cc-option, -fno-stack-protector) -CFLAGS_enlighten_pv.o := $(nostackp) -CFLAGS_mmu_pv.o := $(nostackp) +CFLAGS_enlighten_pv.o := -fno-stack-protector +CFLAGS_mmu_pv.o := -fno-stack-protector obj-y += enlighten.o obj-y += mmu.odrivers/firmware/efi/libstub/Makefile +1
-1@@ -29,7 +29,7 @@ KBUILD_CFLAGS := $(cflags-y) -Os -DDISABLE_BRANCH_PROFILING \ -include $(srctree)/drivers/firmware/efi/libstub/hidden.h \ -D__NO_FORTIFY \ $(call cc-option,-ffreestanding) \ - $(call cc-option,-fno-stack-protector) \ + -fno-stack-protector \ $(call cc-option,-fno-addrsig) \ -D__DISABLE_EXPORTSdrivers/xen/Makefile +1
-2@@ -5,8 +5,7 @@ obj-y += mem-reservation.o obj-y += events/ obj-y += xenbus/ -nostackp := $(call cc-option, -fno-stack-protector) -CFLAGS_features.o := $(nostackp) +CFLAGS_features.o := -fno-stack-protector dom0-$(CONFIG_ARM64) += arm-device.o dom0-$(CONFIG_PCI) += pci.okernel/kcsan/Makefile +1
-2@@ -7,8 +7,7 @@ CFLAGS_REMOVE_core.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_debugfs.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_report.o = $(CC_FLAGS_FTRACE) -CFLAGS_core.o := $(call cc-option,-fno-conserve-stack,) \ - $(call cc-option,-fno-stack-protector,) +CFLAGS_core.o := $(call cc-option,-fno-conserve-stack,) -fno-stack-protector obj-y := core.o debugfs.o report.o obj-$(CONFIG_KCSAN_SELFTEST) += test.olib/Makefile +2
-2@@ -22,7 +22,7 @@ KCOV_INSTRUMENT_fault-inject.o := n ifdef CONFIG_AMD_MEM_ENCRYPT KASAN_SANITIZE_string.o := n -CFLAGS_string.o := $(call cc-option, -fno-stack-protector) +CFLAGS_string.o := -fno-stack-protector endif # Used by KCSAN while enabled, avoid recursion.@@ -300,7 +300,7 @@ endif UBSAN_SANITIZE_ubsan.o := n KASAN_SANITIZE_ubsan.o := n KCSAN_SANITIZE_ubsan.o := n -CFLAGS_ubsan.o := $(call cc-option, -fno-stack-protector) $(DISABLE_STACKLEAK_PLUGIN) +CFLAGS_ubsan.o := -fno-stack-protector $(DISABLE_STACKLEAK_PLUGIN) obj-$(CONFIG_SBITMAP) += sbitmap.omm/kasan/Makefile +1
-2@@ -16,7 +16,7 @@ CFLAGS_REMOVE_tags_report.o = $(CC_FLAGS_FTRACE) # Function splitter causes unnecessary splits in __asan_load1/__asan_store1 # see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63533 CC_FLAGS_KASAN_RUNTIME := $(call cc-option, -fno-conserve-stack) -CC_FLAGS_KASAN_RUNTIME += $(call cc-option, -fno-stack-protector) +CC_FLAGS_KASAN_RUNTIME += -fno-stack-protector # Disable branch tracing to avoid recursion. CC_FLAGS_KASAN_RUNTIME += -DDISABLE_BRANCH_PROFILING --2.25.1
Marco Elver
maintainerQuoted 32 lines · Masahiro Yamada
Some Makefiles already pass -fno-stack-protector unconditionally. For example,
arch/arm64/kernel/vdso/Makefile,arch/x86/xen/Makefile. No problem report so far about hard-coding this option. So, we can assume all supported compilers know -fno-stack-protector.GCC 4.8 and Clang support this option (https://godbolt.org/z/_HDGzN)
Get rid of cc-option from -fno-stack-protector.
Remove
CONFIG_CC_HAS_STACKPROTECTOR_NONE, which should always be 'y'.Note:
arch/mips/vdso/Makefileadds -fno-stack-protector twice, first unconditionally, and second conditionally. I removed the second one.Signed-off-by Masahiro Yamada <[email protected]>---
Documentation/kbuild/kconfig-language.rst | 4 ++-- Makefile | 2 +- arch/Kconfig | 3 --- arch/arm/boot/compressed/Makefile | 3 +-- arch/mips/vdso/Makefile | 3 +-- arch/powerpc/kernel/Makefile | 2 +- arch/powerpc/platforms/powermac/Makefile | 2 +- arch/sparc/vdso/Makefile | 4 ++-- arch/um/Makefile | 3 +-- arch/x86/Makefile | 2 +- arch/x86/boot/compressed/Makefile | 2 +- arch/x86/entry/vdso/Makefile | 4 ++-- arch/x86/kernel/cpu/Makefile | 3 +-- arch/x86/lib/Makefile | 2 +-
Quoted 8 lines
arch/x86/mm/Makefile | 7 +++---- arch/x86/power/Makefile | 3 +-- arch/x86/purgatory/Makefile | 2 +- arch/x86/um/vdso/Makefile | 2 +- arch/x86/xen/Makefile | 5 ++--- drivers/firmware/efi/libstub/Makefile | 2 +- drivers/xen/Makefile | 3 +-- kernel/kcsan/Makefile | 3 +--
Is it possible that this patch drops the KCSAN portion? We have a patch that is part of a series intended for 5.9 that also removes the cc-option from -fno-stack-protector, but can't easily be dropped from the surrounding series.
Please see: https://lkml.kernel.org/r/20200624190236.GA6603@paulmck-ThinkPad-P72
Thanks,
-- Marco