diff --git a/share/mk/bsd.sys.mk b/share/mk/bsd.sys.mk index 3aa6c7e938e4..2cf95f570c6c 100644 --- a/share/mk/bsd.sys.mk +++ b/share/mk/bsd.sys.mk @@ -284,6 +284,19 @@ CFLAGS+= ERROR-tried-to-rebuild-during-make-install .endif .endif +# Please keep this if in sync with kern.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" +LDFLAGS+= -fuse-ld=${LD:[1]} +.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. +.warning LD (${LD}) is not the default linker for ${CC} but -fuse-ld= is not supported +.endif +.endif + # Tell bmake not to mistake standard targets for things to be searched for # or expect to ever be up-to-date. PHONY_NOTMAIN = analyze afterdepend afterinstall all beforedepend beforeinstall \ diff --git a/sys/conf/kern.mk b/sys/conf/kern.mk index 71abc84247ec..bf278e1716aa 100644 --- a/sys/conf/kern.mk +++ b/sys/conf/kern.mk @@ -270,6 +270,22 @@ CFLAGS+= -std=iso9899:1999 CFLAGS+= -std=${CSTD} .endif # 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. +CCLDFLAGS+= -fuse-ld=${LD:[1]} +.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. +.warning LD (${LD}) is not the default linker for ${CC} but -fuse-ld= is not supported +.endif +.endif + # Set target-specific linker emulation name. LD_EMULATION_aarch64=aarch64elf LD_EMULATION_amd64=elf_x86_64_fbsd diff --git a/sys/conf/kern.post.mk b/sys/conf/kern.post.mk index 5f9d55c07a2f..c9dce0e9f2f2 100644 --- a/sys/conf/kern.post.mk +++ b/sys/conf/kern.post.mk @@ -228,7 +228,7 @@ kernel-clean: # in the a.out ld. For now, this works. hack.pico: Makefile :> hack.c - ${CC} -shared ${CFLAGS} -nostdlib hack.c -o hack.pico + ${CC} ${CCLDFLAGS} -shared ${CFLAGS} -nostdlib hack.c -o hack.pico rm -f hack.c offset.inc: $S/kern/genoffset.sh genoffset.o diff --git a/sys/modules/cloudabi32/Makefile b/sys/modules/cloudabi32/Makefile index bf9a04b9b1b6..8d6063a99209 100644 --- a/sys/modules/cloudabi32/Makefile +++ b/sys/modules/cloudabi32/Makefile @@ -33,7 +33,7 @@ BINARY_ARCHITECTURE=i386 .endif cloudabi32_vdso.o: ${VDSO_SRCS} - ${CC} -x assembler-with-cpp -m32 -shared -nostdinc -nostdlib \ + ${CC} ${CCLDFLAGS} -x assembler-with-cpp -m32 -shared -nostdinc -nostdlib \ -Wl,-T${SYSDIR}/compat/cloudabi/cloudabi_vdso.lds \ ${VDSO_SRCS} -o ${.TARGET} diff --git a/sys/modules/cloudabi64/Makefile b/sys/modules/cloudabi64/Makefile index 4e23f0b1dbb4..9d0caf902ad4 100644 --- a/sys/modules/cloudabi64/Makefile +++ b/sys/modules/cloudabi64/Makefile @@ -25,7 +25,7 @@ BINARY_ARCHITECTURE=i386 .endif cloudabi64_vdso.o: ${VDSO_SRCS} - ${CC} -x assembler-with-cpp -shared -nostdinc -nostdlib \ + ${CC} ${CCLDFLAGS} -x assembler-with-cpp -shared -nostdinc -nostdlib \ -Wl,-T${SYSDIR}/compat/cloudabi/cloudabi_vdso.lds \ ${VDSO_SRCS} -o ${.TARGET} diff --git a/sys/modules/linux/Makefile b/sys/modules/linux/Makefile index c91dfbdaf380..e5b70933acd4 100644 --- a/sys/modules/linux/Makefile +++ b/sys/modules/linux/Makefile @@ -54,7 +54,7 @@ linux${SFX}_assym.h: linux${SFX}_genassym.o sh ${SYSDIR}/kern/genassym.sh linux${SFX}_genassym.o > ${.TARGET} linux${SFX}_locore.o: linux${SFX}_assym.h assym.inc - ${CC} -x assembler-with-cpp -DLOCORE -m32 -shared -s \ + ${CC} ${CCLDFLAGS} -x assembler-with-cpp -DLOCORE -m32 -shared -s \ -pipe -I. -I${SYSDIR} ${WERROR} -Wall -fno-common -nostdinc -nostdlib \ -fno-omit-frame-pointer -fPIC \ -Wl,-T${SRCTOP}/sys/${MACHINE_CPUARCH}/linux${SFX}/${VDSO}.lds.s \ diff --git a/sys/modules/linux64/Makefile b/sys/modules/linux64/Makefile index 33dccc907709..162cfea625c9 100644 --- a/sys/modules/linux64/Makefile +++ b/sys/modules/linux64/Makefile @@ -30,7 +30,7 @@ linux_assym.h: linux_genassym.o sh ${SYSDIR}/kern/genassym.sh linux_genassym.o > ${.TARGET} linux_locore.o: linux_locore.asm linux_assym.h - ${CC} -x assembler-with-cpp -DLOCORE -shared -mcmodel=small \ + ${CC} ${CCLDFLAGS} -x assembler-with-cpp -DLOCORE -shared -mcmodel=small \ -pipe -I. -I${SYSDIR} ${WERROR} -Wall -fno-common -fPIC -nostdinc \ -Wl,-T${SRCTOP}/sys/${MACHINE}/linux/${VDSO}.lds.s \ -Wl,-soname=${VDSO}.so.1,-warn-common -nostdlib \