git: 177466dac805 - stable/13 - Avoid adding -d to kernel module link command lines for lld >= 14

From: Dimitry Andric <dim_at_FreeBSD.org>
Date: Mon, 30 May 2022 18:30:31 UTC
The branch stable/13 has been updated by dim:

URL: https://cgit.FreeBSD.org/src/commit/?id=177466dac805df0271511a0d7cd3152a467820c6

commit 177466dac805df0271511a0d7cd3152a467820c6
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2022-05-14 20:07:01 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2022-05-30 18:28:14 +0000

    Avoid adding -d to kernel module link command lines for lld >= 14
    
    Since 0b3178a45cd0 we have added '-d' to the link command line for
    kernel modules, so if any unexpected common symbols turn up (even though
    we use -fno-common in CFLAGS), storage will be allocated in in the
    module itself.
    
    However, with lld this option did not have any effect since ~2017, and
    as of lld 14 it warns: "-d, -dc, -dp, and --[no-]define-common will be
    removed. See https://github.com/llvm/llvm-project/issues/53660"
    
    Add a linker type and version check, to avoid adding the option for lld
    14 and later.
    
    Reported by:    bz
    MFC after:      2 weeks
    
    (cherry picked from commit 0817c8dc2a48efedac38d1b9b5c4747a15dbe840)
---
 sys/conf/kmod.mk | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/sys/conf/kmod.mk b/sys/conf/kmod.mk
index 736ce26d406c..629b7554f005 100644
--- a/sys/conf/kmod.mk
+++ b/sys/conf/kmod.mk
@@ -139,7 +139,11 @@ CFLAGS.gcc+= --param large-function-growth=1000
 # share/mk/src.sys.mk, but the following is important for out-of-tree modules
 # (e.g. ports).
 CFLAGS+=	-fno-common
-LDFLAGS+=	-d -warn-common
+.if ${LINKER_TYPE} != "lld" || ${LINKER_VERSION} < 140000
+# lld >= 14 warns that -d is deprecated, and will be removed.
+LDFLAGS+=	-d
+.endif
+LDFLAGS+=	-warn-common
 
 .if defined(LINKER_FEATURES) && ${LINKER_FEATURES:Mbuild-id}
 LDFLAGS+=	--build-id=sha1
@@ -245,7 +249,7 @@ ${KMOD}.kld: ${OBJS}
 .else
 ${FULLPROG}: ${OBJS}
 .endif
-	${LD} -m ${LD_EMULATION} ${_LDFLAGS} ${LDSCRIPT_FLAGS} -r -d \
+	${LD} -m ${LD_EMULATION} ${_LDFLAGS} ${LDSCRIPT_FLAGS} -r \
 	    -o ${.TARGET} ${OBJS}
 .if ${MK_CTF} != "no"
 	${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}