Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Kconfig.debug: make DEBUG_INFO selectable from a choice

Currently it's not possible to enable DEBUG_INFO for an all*config
build, since it is marked as "depends on !COMPILE_TEST".

This generally makes sense because a debug build of an all*config target
ends up taking much longer and the output is much larger. Having this
be "default off" makes sense.

However, there are cases where enabling DEBUG_INFO for such builds is
useful for doing treewide A/B comparisons of build options, etc.

Make DEBUG_INFO selectable from any of the DWARF version choice options,
with DEBUG_INFO_NONE being the default for COMPILE_TEST.

The mutually exclusive relationship between DWARF5 and BTF must be
inverted, but the result remains the same. Additionally moves
DEBUG_KERNEL and DEBUG_MISC up to the top of the menu because they were
enabling features _above_ it, making it weird to navigate menuconfig.

[keescook@chromium.org: make DEBUG_INFO always default=n]
Link: https://lkml.kernel.org/r/20220128214131.580131-1-keescook@chromium.org
Link: https://lore.kernel.org/lkml/YfRY6+CaQxX7O8vF@dev-arch.archlinux-ax161

Link: https://lkml.kernel.org/r/20220125075126.891825-1-keescook@chromium.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Suggested-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Tested-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Masahiro Yamada <masahiroy@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Kees Cook and committed by
Linus Torvalds
f9b3cd24 a7cd9a53

+74 -65
+74 -65
lib/Kconfig.debug
··· 208 208 209 209 endmenu # "printk and dmesg options" 210 210 211 + config DEBUG_KERNEL 212 + bool "Kernel debugging" 213 + help 214 + Say Y here if you are developing drivers or trying to debug and 215 + identify kernel problems. 216 + 217 + config DEBUG_MISC 218 + bool "Miscellaneous debug code" 219 + default DEBUG_KERNEL 220 + depends on DEBUG_KERNEL 221 + help 222 + Say Y here if you need to enable miscellaneous debug code that should 223 + be under a more specific debug option but isn't. 224 + 211 225 menu "Compile-time checks and compiler options" 212 226 213 227 config DEBUG_INFO 214 - bool "Compile the kernel with debug info" 215 - depends on DEBUG_KERNEL && !COMPILE_TEST 228 + bool 216 229 help 217 - If you say Y here the resulting kernel image will include 218 - debugging info resulting in a larger kernel image. 230 + A kernel debug info option other than "None" has been selected 231 + in the "Debug information" choice below, indicating that debug 232 + information will be generated for build targets. 233 + 234 + choice 235 + prompt "Debug information" 236 + depends on DEBUG_KERNEL 237 + help 238 + Selecting something other than "None" results in a kernel image 239 + that will include debugging info resulting in a larger kernel image. 219 240 This adds debug symbols to the kernel and modules (gcc -g), and 220 241 is needed if you intend to use kernel crashdump or binary object 221 242 tools like crash, kgdb, LKCD, gdb, etc on the kernel. 222 - Say Y here only if you plan to debug the kernel. 223 243 224 - If unsure, say N. 244 + Choose which version of DWARF debug info to emit. If unsure, 245 + select "Toolchain default". 246 + 247 + config DEBUG_INFO_NONE 248 + bool "Disable debug information" 249 + help 250 + Do not build the kernel with debugging information, which will 251 + result in a faster and smaller build. 252 + 253 + config DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT 254 + bool "Rely on the toolchain's implicit default DWARF version" 255 + select DEBUG_INFO 256 + help 257 + The implicit default version of DWARF debug info produced by a 258 + toolchain changes over time. 259 + 260 + This can break consumers of the debug info that haven't upgraded to 261 + support newer revisions, and prevent testing newer versions, but 262 + those should be less common scenarios. 263 + 264 + config DEBUG_INFO_DWARF4 265 + bool "Generate DWARF Version 4 debuginfo" 266 + select DEBUG_INFO 267 + help 268 + Generate DWARF v4 debug info. This requires gcc 4.5+ and gdb 7.0+. 269 + 270 + If you have consumers of DWARF debug info that are not ready for 271 + newer revisions of DWARF, you may wish to choose this or have your 272 + config select this. 273 + 274 + config DEBUG_INFO_DWARF5 275 + bool "Generate DWARF Version 5 debuginfo" 276 + select DEBUG_INFO 277 + depends on !CC_IS_CLANG || (CC_IS_CLANG && (AS_IS_LLVM || (AS_IS_GNU && AS_VERSION >= 23502))) 278 + help 279 + Generate DWARF v5 debug info. Requires binutils 2.35.2, gcc 5.0+ (gcc 280 + 5.0+ accepts the -gdwarf-5 flag but only had partial support for some 281 + draft features until 7.0), and gdb 8.0+. 282 + 283 + Changes to the structure of debug info in Version 5 allow for around 284 + 15-18% savings in resulting image and debug info section sizes as 285 + compared to DWARF Version 4. DWARF Version 5 standardizes previous 286 + extensions such as accelerators for symbol indexing and the format 287 + for fission (.dwo/.dwp) files. Users may not want to select this 288 + config if they rely on tooling that has not yet been updated to 289 + support DWARF Version 5. 290 + 291 + endchoice # "Debug information" 225 292 226 293 if DEBUG_INFO 227 294 ··· 334 267 to know about the .dwo files and include them. 335 268 Incompatible with older versions of ccache. 336 269 337 - choice 338 - prompt "DWARF version" 339 - help 340 - Which version of DWARF debug info to emit. 341 - 342 - config DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT 343 - bool "Rely on the toolchain's implicit default DWARF version" 344 - help 345 - The implicit default version of DWARF debug info produced by a 346 - toolchain changes over time. 347 - 348 - This can break consumers of the debug info that haven't upgraded to 349 - support newer revisions, and prevent testing newer versions, but 350 - those should be less common scenarios. 351 - 352 - If unsure, say Y. 353 - 354 - config DEBUG_INFO_DWARF4 355 - bool "Generate DWARF Version 4 debuginfo" 356 - help 357 - Generate DWARF v4 debug info. This requires gcc 4.5+ and gdb 7.0+. 358 - 359 - If you have consumers of DWARF debug info that are not ready for 360 - newer revisions of DWARF, you may wish to choose this or have your 361 - config select this. 362 - 363 - config DEBUG_INFO_DWARF5 364 - bool "Generate DWARF Version 5 debuginfo" 365 - depends on !CC_IS_CLANG || (CC_IS_CLANG && (AS_IS_LLVM || (AS_IS_GNU && AS_VERSION >= 23502))) 366 - depends on !DEBUG_INFO_BTF 367 - help 368 - Generate DWARF v5 debug info. Requires binutils 2.35.2, gcc 5.0+ (gcc 369 - 5.0+ accepts the -gdwarf-5 flag but only had partial support for some 370 - draft features until 7.0), and gdb 8.0+. 371 - 372 - Changes to the structure of debug info in Version 5 allow for around 373 - 15-18% savings in resulting image and debug info section sizes as 374 - compared to DWARF Version 4. DWARF Version 5 standardizes previous 375 - extensions such as accelerators for symbol indexing and the format 376 - for fission (.dwo/.dwp) files. Users may not want to select this 377 - config if they rely on tooling that has not yet been updated to 378 - support DWARF Version 5. 379 - 380 - endchoice # "DWARF version" 381 - 382 270 config DEBUG_INFO_BTF 383 271 bool "Generate BTF typeinfo" 384 272 depends on !DEBUG_INFO_SPLIT && !DEBUG_INFO_REDUCED 385 273 depends on !GCC_PLUGIN_RANDSTRUCT || COMPILE_TEST 386 274 depends on BPF_SYSCALL 275 + depends on !DEBUG_INFO_DWARF5 387 276 help 388 277 Generate deduplicated BTF type information from DWARF debug info. 389 278 Turning this on expects presence of pahole tool, which will convert ··· 607 584 source "lib/Kconfig.kcsan" 608 585 609 586 endmenu 610 - 611 - config DEBUG_KERNEL 612 - bool "Kernel debugging" 613 - help 614 - Say Y here if you are developing drivers or trying to debug and 615 - identify kernel problems. 616 - 617 - config DEBUG_MISC 618 - bool "Miscellaneous debug code" 619 - default DEBUG_KERNEL 620 - depends on DEBUG_KERNEL 621 - help 622 - Say Y here if you need to enable miscellaneous debug code that should 623 - be under a more specific debug option but isn't. 624 587 625 588 menu "Networking Debugging" 626 589