Search code examples
linux-kernelkerneldebug-information

How do you include debug info for assembly files in the Linux kernel?


For debug info, I have these config options enabled:

/Volumes/git/linux (master)*$ grep CONFIG_DEBUG build/.config | grep -v ^#
CONFIG_DEBUG_ALIGN_RODATA=y
CONFIG_DEBUG_KERNEL=y
CONFIG_DEBUG_INFO=y
CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y
CONFIG_DEBUG_LL_INCLUDE="mach/debug-macro.S"

However the vmlinux file only includes debug info for .c and .h files and not .S files.

Is there a standard way to get debug info for the assembly files included in vmlinux?

update 8/2/2022:

I found that in scripts/Makefile.debug if you use LLVM/clang then debug info is excluded from assembly files for some reason.

ifndef CONFIG_AS_IS_LLVM
KBUILD_AFLAGS   += -Wa,-gdwarf-2
endif

and removing the ifndef line fixed the missing debug info for me.

Why is ifndef CONFIG_AS_IS_LLVM there?


Solution

  • if building with llvm clang, remove ifndef CONFIG_AS_IS_LLVM and endif from around the KBUILD_AFLAGS

    diff --git a/scripts/Makefile.debug b/scripts/Makefile.debug
    index 9f39b0130551f..1a26df0538b5b 100644
    --- a/scripts/Makefile.debug
    +++ b/scripts/Makefile.debug
    @@ -6,9 +6,7 @@ else
     DEBUG_CFLAGS   += -g
     endif
     
    -ifndef CONFIG_AS_IS_LLVM
     KBUILD_AFLAGS  += -Wa,-gdwarf-2
    -endif
     
     ifndef CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
     dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4