1DEBUG_CFLAGS	:=
2DEBUG_RUSTFLAGS	:=
3
4debug-flags-y	:= -g
5
6ifdef CONFIG_DEBUG_INFO_SPLIT
7DEBUG_CFLAGS	+= -gsplit-dwarf
8endif
9
10debug-flags-$(CONFIG_DEBUG_INFO_DWARF4)	+= -gdwarf-4
11debug-flags-$(CONFIG_DEBUG_INFO_DWARF5)	+= -gdwarf-5
12ifeq ($(CONFIG_CC_IS_CLANG)$(CONFIG_AS_IS_GNU),yy)
13# Clang does not pass -g or -gdwarf-* option down to GAS.
14# Add -Wa, prefix to explicitly specify the flags.
15KBUILD_AFLAGS	+= $(addprefix -Wa$(comma), $(debug-flags-y))
16endif
17DEBUG_CFLAGS	+= $(debug-flags-y)
18KBUILD_AFLAGS	+= $(debug-flags-y)
19
20ifdef CONFIG_DEBUG_INFO_DWARF4
21DEBUG_RUSTFLAGS	+= -Zdwarf-version=4
22else ifdef CONFIG_DEBUG_INFO_DWARF5
23DEBUG_RUSTFLAGS	+= -Zdwarf-version=5
24endif
25
26ifdef CONFIG_DEBUG_INFO_REDUCED
27DEBUG_CFLAGS	+= -fno-var-tracking
28DEBUG_RUSTFLAGS	+= -Cdebuginfo=1
29ifdef CONFIG_CC_IS_GCC
30DEBUG_CFLAGS	+= -femit-struct-debug-baseonly
31endif
32else
33DEBUG_RUSTFLAGS	+= -Cdebuginfo=2
34endif
35
36ifdef CONFIG_DEBUG_INFO_COMPRESSED_ZLIB
37DEBUG_CFLAGS	+= -gz=zlib
38DEBUG_RUSTFLAGS	+= -Zdebuginfo-compression=zlib
39KBUILD_AFLAGS	+= -gz=zlib
40KBUILD_LDFLAGS	+= --compress-debug-sections=zlib
41else ifdef CONFIG_DEBUG_INFO_COMPRESSED_ZSTD
42DEBUG_CFLAGS	+= -gz=zstd
43DEBUG_RUSTFLAGS	+= -Zdebuginfo-compression=zstd
44KBUILD_AFLAGS	+= -gz=zstd
45KBUILD_LDFLAGS	+= --compress-debug-sections=zstd
46endif
47
48KBUILD_CFLAGS	+= $(DEBUG_CFLAGS)
49export DEBUG_CFLAGS
50
51KBUILD_RUSTFLAGS += $(DEBUG_RUSTFLAGS)
52export DEBUG_RUSTFLAGS
53