git: 0817c8dc2a48 - main - Avoid adding -d to kernel module link command lines for lld >= 14

From: Dimitry Andric <dim_at_FreeBSD.org>
Date: Sat, 14 May 2022 20:07:26 UTC
The branch main has been updated by dim:

URL: https://cgit.FreeBSD.org/src/commit/?id=0817c8dc2a48efedac38d1b9b5c4747a15dbe840

commit 0817c8dc2a48efedac38d1b9b5c4747a15dbe840
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2022-05-14 20:07:01 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2022-05-14 20:07:12 +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
---
 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 e01a982d4793..2ab8fb576472 100644
--- a/sys/conf/kmod.mk
+++ b/sys/conf/kmod.mk
@@ -145,7 +145,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
@@ -247,7 +251,7 @@ ${KMOD}.kld: ${OBJS} ${BLOB_OBJS}
 .else
 ${FULLPROG}: ${OBJS} ${BLOB_OBJS}
 .endif
-	${LD} -m ${LD_EMULATION} ${_LDFLAGS} ${LDSCRIPT_FLAGS} -r -d \
+	${LD} -m ${LD_EMULATION} ${_LDFLAGS} ${LDSCRIPT_FLAGS} -r \
 	    -o ${.TARGET} ${OBJS} ${BLOB_OBJS}
 .if ${MK_CTF} != "no"
 	${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS} ${BLOB_OBJS}