diff --git a/Makefile b/Makefile index ae10eb148570..9882d727b186 100644 --- a/Makefile +++ b/Makefile @@ -364,10 +364,7 @@ ZEPHYRINCLUDE := \ KBUILD_CPPFLAGS := -DKERNEL -DEFAULTFLAGS ?= -Os - KBUILD_CFLAGS := -c -g -std=c99 \ - $(DEFAULTFLAGS) \ $(CONFIG_COMPILER_OPT) \ -fno-reorder-functions \ -fno-asynchronous-unwind-tables \ @@ -634,6 +631,12 @@ endif endif KBUILD_CFLAGS += $(stackp-flag) +ifeq ($(CONFIG_DEBUG),y) +KBUILD_CFLAGS += -O0 +else +KBUILD_CFLAGS += -Os +endif + export x86_FLAGS arm_FLAGS arc_FLAGS LDFLAG_LINKERCMD OUTPUT_FORMAT OUTPUT_ARCH ARCHFLAGS = $($(SRCARCH)_FLAGS) diff --git a/misc/Kconfig b/misc/Kconfig index 7a36d58840fe..33b5d57d6f44 100644 --- a/misc/Kconfig +++ b/misc/Kconfig @@ -58,6 +58,14 @@ config KERNEL_BIN_NAME default "microkernel" if MICROKERNEL default "nanokernel" if NANOKERNEL +config DEBUG + bool "Build kernel with debugging" + default n + help + Build a kernel suitable for debugging. Right now, this option + only disables optimization, more debugging variants can be selected + from here to allow more debugging. + config COMPILER_OPT string prompt "Custom compiler options" diff --git a/scripts/Makefile.x86.preparch b/scripts/Makefile.x86.preparch index b33d2003fe1d..99dd13546dd2 100644 --- a/scripts/Makefile.x86.preparch +++ b/scripts/Makefile.x86.preparch @@ -1,9 +1,13 @@ + + PERF_OPT_FLAG-y = -DPERF_OPT ALIGN_STACK_FLAG- = -mpreferred-stack-boundary=2 SECTION_GC_FLAG = $(call cc-option,-ffunction-sections,) $(call cc-option,-fdata-sections,) LTO_FLAG-y = $(call cc-option,-flto,) -PERF_OPT=$(if $(filter -Os,$(DEFAULTFLAGS)),,y) + +PERF_OPT=$(if $(filter -Os,$(KBUILD_CFLAGS)),,y) PERF_OPT_FLAG = $(PERF_OPT_FLAG-$(PERF_OPT)) + ALIGN_STACK_FLAG = $(ALIGN_STACK_FLAG-$(PERF_OPT)) LTO_FLAG = $(LTO_FLAG-$(CONFIG_LTO)) ifneq ($(CONFIG_PLATFORM_QUARK),y)