git: 53fba3b984ac - main - build: Default to DWARF4 in the kernel

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Tue, 13 Feb 2024 22:53:42 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=53fba3b984aca0dc5d34b84d0e21f0d4d121b56f

commit 53fba3b984aca0dc5d34b84d0e21f0d4d121b56f
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2024-02-11 18:03:23 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-02-13 22:51:09 +0000

    build: Default to DWARF4 in the kernel
    
    gcc 12 defaults to emitting DWARF 5, but this is not yet supported by
    our libdwarf and thus by ctfconvert.
    
    Reviewed by:    emaste, imp
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D43837
---
 sys/conf/kern.mk | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/sys/conf/kern.mk b/sys/conf/kern.mk
index 08779b4da193..53781927dee8 100644
--- a/sys/conf/kern.mk
+++ b/sys/conf/kern.mk
@@ -256,6 +256,14 @@ CFLAGS+= -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clan
 .endif
 .endif
 
+#
+# Some newer toolchains default to DWARF 5, which isn't supported by some build
+# tools yet.
+#
+.if (${CFLAGS:M-g} != "" || ${CFLAGS:M-g[0-3]} != "") && ${CFLAGS:M-gdwarf*} == ""
+CFLAGS+=	-gdwarf-4
+.endif
+
 CFLAGS+= ${CWARNFLAGS:M*} ${CWARNFLAGS.${.IMPSRC:T}}
 CFLAGS+= ${CWARNFLAGS.${COMPILER_TYPE}}
 CFLAGS+= ${CFLAGS.${COMPILER_TYPE}} ${CFLAGS.${.IMPSRC:T}}