git: 0c4d13c521aa - stable/13 - Add SPLIT_KERNEL_DEBUG knob

From: Ed Maste <emaste_at_FreeBSD.org>
Date: Mon, 18 Jul 2022 15:01:50 UTC
The branch stable/13 has been updated by emaste:

URL: https://cgit.FreeBSD.org/src/commit/?id=0c4d13c521aaa56725e31d5a052760b9effd2dd5

commit 0c4d13c521aaa56725e31d5a052760b9effd2dd5
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2022-06-07 14:20:39 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2022-07-18 15:01:23 +0000

    Add SPLIT_KERNEL_DEBUG knob
    
    Prior to 9b6edf364eb0 WITHOUT_KERNEL_SYMBOLS split kernel debug data
    into standalone debug files at build time, but did not install those
    files.  As of 9b6edf364eb0 it stopped splitting the debug data, leaving
    it in the kernel and modules (the default kernel configs include
    DEBUG=-g).
    
    Revert 9b6edf364eb0 and introduce a new build-time SPLIT_KERNEL_DEBUG
    knob, as some people rely on the pre-9b6edf364eb0 WITHOUT_KERNEL_SYMBOLS
    behaviour and that was imp's original intent.
    
    PR:             264433
    Reviewed by:    eugen, imp
    MFC after:      3 weeks
    Relnotes:       yes
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D35437
    
    (cherry picked from commit 92fc5822a8301d0c20d292e97d1661b25f5035bc)
    (cherry picked from commit e3709cfe6a2a1f7d345db2870be175c9cf2a8979)
    (cherry picked from commit a7bd57de86372d834cf9312fcc4c39070653e009)
---
 share/man/man5/src.conf.5                      | 15 +++++++++++++--
 sys/conf/kern.opts.mk                          |  5 +++++
 sys/conf/kmod.mk                               |  4 ++--
 tools/build/options/WITHOUT_KERNEL_SYMBOLS     |  3 ++-
 tools/build/options/WITHOUT_SPLIT_KERNEL_DEBUG |  3 +++
 5 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/share/man/man5/src.conf.5 b/share/man/man5/src.conf.5
index a879dc352830..272ad1cb9e71 100644
--- a/share/man/man5/src.conf.5
+++ b/share/man/man5/src.conf.5
@@ -1,6 +1,6 @@
 .\" DO NOT EDIT-- this file is @generated by tools/build/options/makeman.
 .\" $FreeBSD$
-.Dd June 13, 2022
+.Dd July 18, 2022
 .Dt SRC.CONF 5
 .Os
 .Sh NAME
@@ -817,7 +817,8 @@ and
 Enable the "retpoline" mitigation for CVE-2017-5715 in the kernel
 build.
 .It Va WITHOUT_KERNEL_SYMBOLS
-Do not install kernel debug symbol files.
+Do not install standalone kernel debug symbol files.
+This option has no effect at build time.
 .It Va WITHOUT_KVM
 Do not build the
 .Nm libkvm
@@ -1470,6 +1471,16 @@ When set, it enforces these options:
 Do not build kernel modules that include sourceless native code for host CPU.
 .It Va WITHOUT_SOURCELESS_UCODE
 Do not build kernel modules that include sourceless microcode.
+.It Va WITHOUT_SPLIT_KERNEL_DEBUG
+Do not build standalone kernel debug files.
+Debug data (if enabled by the kernel configuration file)
+will be included in the kernel and modules.
+When set, it enforces these options:
+.Pp
+.Bl -item -compact
+.It
+.Va WITHOUT_KERNEL_SYMBOLS
+.El
 .It Va WITHOUT_SSP
 Do not build world with propolice stack smashing protection.
 .Pp
diff --git a/sys/conf/kern.opts.mk b/sys/conf/kern.opts.mk
index 7361cdd70076..a6e0a48d3272 100644
--- a/sys/conf/kern.opts.mk
+++ b/sys/conf/kern.opts.mk
@@ -46,6 +46,7 @@ __DEFAULT_YES_OPTIONS = \
     SCTP_SUPPORT \
     SOURCELESS_HOST \
     SOURCELESS_UCODE \
+    SPLIT_KERNEL_DEBUG \
     TESTS \
     USB_GADGET_EXAMPLES \
     ZFS
@@ -173,6 +174,10 @@ MK_${var}_SUPPORT:= yes
 .endif
 .endfor
 
+.if ${MK_SPLIT_KERNEL_DEBUG} == "no"
+MK_KERNEL_SYMBOLS:=	no
+.endif
+
 # Some modules only compile successfully if option FDT is set, due to #ifdef FDT
 # wrapped around declarations.  Module makefiles can optionally compile such
 # things using .if !empty(OPT_FDT)
diff --git a/sys/conf/kmod.mk b/sys/conf/kmod.mk
index 5a7199091096..16174983bb32 100644
--- a/sys/conf/kmod.mk
+++ b/sys/conf/kmod.mk
@@ -219,7 +219,7 @@ OBJS+=	${SRCS:N*.h:R:S/$/.o/g}
 PROG=	${KMOD}.ko
 .endif
 
-.if !defined(DEBUG_FLAGS) || ${MK_KERNEL_SYMBOLS} == "no"
+.if !defined(DEBUG_FLAGS) || ${MK_SPLIT_KERNEL_DEBUG} == "no"
 FULLPROG=	${PROG}
 .else
 FULLPROG=	${PROG}.full
@@ -323,7 +323,7 @@ ${_ILINKS}:
 
 CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS}
 
-.if defined(DEBUG_FLAGS) && ${MK_KERNEL_SYMBOLS} != "no"
+.if defined(DEBUG_FLAGS) && ${MK_SPLIT_KERNEL_DEBUG} != "no"
 CLEANFILES+= ${FULLPROG} ${PROG}.debug
 .endif
 
diff --git a/tools/build/options/WITHOUT_KERNEL_SYMBOLS b/tools/build/options/WITHOUT_KERNEL_SYMBOLS
index 33fa2c4f1c97..c56359d9fa6b 100644
--- a/tools/build/options/WITHOUT_KERNEL_SYMBOLS
+++ b/tools/build/options/WITHOUT_KERNEL_SYMBOLS
@@ -1,2 +1,3 @@
 .\" $FreeBSD$
-Do not install kernel debug symbol files.
+Do not install standalone kernel debug symbol files.
+This option has no effect at build time.
diff --git a/tools/build/options/WITHOUT_SPLIT_KERNEL_DEBUG b/tools/build/options/WITHOUT_SPLIT_KERNEL_DEBUG
new file mode 100644
index 000000000000..a23bcd5ffdb6
--- /dev/null
+++ b/tools/build/options/WITHOUT_SPLIT_KERNEL_DEBUG
@@ -0,0 +1,3 @@
+Do not build standalone kernel debug files.
+Debug data (if enabled by the kernel configuration file)
+will be included in the kernel and modules.