diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index bcbe60d6c80c..37aa19f0f7b0 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -264,6 +264,7 @@ config DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT config DEBUG_INFO_DWARF4 bool "Generate DWARF Version 4 debuginfo" select DEBUG_INFO + depends on !CC_IS_CLANG || (CC_IS_CLANG && (AS_IS_LLVM || (AS_IS_GNU && AS_VERSION >= 23500))) help Generate DWARF v4 debug info. This requires gcc 4.5+ and gdb 7.0+. diff --git a/scripts/Makefile.debug b/scripts/Makefile.debug index 9f39b0130551..c5ecb882a638 100644 --- a/scripts/Makefile.debug +++ b/scripts/Makefile.debug @@ -3,17 +3,20 @@ DEBUG_CFLAGS := ifdef CONFIG_DEBUG_INFO_SPLIT DEBUG_CFLAGS += -gsplit-dwarf else -DEBUG_CFLAGS += -g +debug-flags-y += -g endif -ifndef CONFIG_AS_IS_LLVM -KBUILD_AFLAGS += -Wa,-gdwarf-2 -endif +debug-flags-$(CONFIG_DEBUG_INFO_DWARF4) += -gdwarf-4 +debug-flags-$(CONFIG_DEBUG_INFO_DWARF5) += -gdwarf-5 + +DEBUG_CFLAGS += $(debug-flags-y) -ifndef CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT -dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4 -dwarf-version-$(CONFIG_DEBUG_INFO_DWARF5) := 5 -DEBUG_CFLAGS += -gdwarf-$(dwarf-version-y) +ifeq ($(CONFIG_CC_IS_CLANG)$(CONFIG_AS_IS_GNU),yy) +# Clang does not pass -g or -gdwarf-* option down to GAS. +# Add -Wa, prefix to explicitly specify the flags. +KBUILD_AFLAGS += $(addprefix -Wa$(comma), $(debug-flags-y)) +else +KBUILD_AFLAGS += $(debug-flags-y) endif ifdef CONFIG_DEBUG_INFO_REDUCED