From 172a624f0c9fbc47d74fd5178d46f771f82dc6a0 Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Thu, 4 Mar 2021 18:27:37 +0000 Subject: [PATCH] Silence annoying and incorrect non-default linker warning with GCC The CROSS_TOOLCHAIN GCC .mk files include -B${CROSS_BINUTILS_PREFIX}, so GCC will select the right linker and we don't need to warn. While here also apply 17b8b8fb5fc4acc832dabfe7ef11e3e1d399ad0f to kern.mk. Test Plan: no more warning printed with CROSS_TOOLCHAIN=mips-gcc6 Reviewed By: jhb Differential Revision: https://reviews.freebsd.org/D29015 --- share/mk/bsd.sys.mk | 4 ++++ sys/conf/kern.mk | 16 ++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/share/mk/bsd.sys.mk b/share/mk/bsd.sys.mk index 497283fc95da..fad487cf5630 100644 --- a/share/mk/bsd.sys.mk +++ b/share/mk/bsd.sys.mk @@ -306,9 +306,13 @@ LDFLAGS+= -fuse-ld=${LD:[1]:S/^ld.//1W} .else # GCC does not support an absolute path for -fuse-ld so we just print this # warning instead and let the user add the required symlinks. +# However, we can avoid this warning if -B is set appropriately (e.g. for +# CROSS_TOOLCHAIN=...-gcc). +.if !(${LD:[1]:T} == "ld" && ${CC:tw:M-B${LD:[1]:H}/}) .warning LD (${LD}) is not the default linker for ${CC} but -fuse-ld= is not supported .endif .endif +.endif # Tell bmake not to mistake standard targets for things to be searched for # or expect to ever be up-to-date. diff --git a/sys/conf/kern.mk b/sys/conf/kern.mk index 8f0163a3d0a0..8cc79e6645ad 100644 --- a/sys/conf/kern.mk +++ b/sys/conf/kern.mk @@ -280,19 +280,23 @@ CFLAGS+= -std=${CSTD} # Please keep this if in sync with bsd.sys.mk .if ${LD} != "ld" && (${CC:[1]:H} != ${LD:[1]:H} || ${LD:[1]:T} != "ld") # Add -fuse-ld=${LD} if $LD is in a different directory or not called "ld". -# Note: Clang 12+ will prefer --ld-path= over -fuse-ld=. .if ${COMPILER_TYPE} == "clang" -# Note: unlike bsd.sys.mk we can't use LDFLAGS here since that is used for the -# flags required when linking the kernel. We don't need those flags when -# building the vdsos. However, we do need -fuse-ld, so use ${CCLDFLAGS} instead. -# Note: Clang does not like relative paths in -fuse-ld so we map ld.lld -> lld. -CCLDFLAGS+= -fuse-ld=${LD:[1]:S/^ld.//1W} +# Note: Clang does not like relative paths for ld so we map ld.lld -> lld. +.if ${COMPILER_VERSION} >= 120000 +LDFLAGS+= --ld-path=${LD:[1]:S/^ld.//1W} +.else +LDFLAGS+= -fuse-ld=${LD:[1]:S/^ld.//1W} +.endif .else # GCC does not support an absolute path for -fuse-ld so we just print this # warning instead and let the user add the required symlinks. +# However, we can avoid this warning if -B is set appropriately (e.g. for +# CROSS_TOOLCHAIN=...-gcc). +.if !(${LD:[1]:T} == "ld" && ${CC:tw:M-B${LD:[1]:H}/}) .warning LD (${LD}) is not the default linker for ${CC} but -fuse-ld= is not supported .endif .endif +.endif # Set target-specific linker emulation name. LD_EMULATION_aarch64=aarch64elf