Index: share/mk/bsd.sys.mk =================================================================== --- share/mk/bsd.sys.mk +++ share/mk/bsd.sys.mk @@ -284,6 +284,19 @@ .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 \ Index: sys/conf/kern.mk =================================================================== --- sys/conf/kern.mk +++ sys/conf/kern.mk @@ -270,6 +270,22 @@ 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 Index: sys/conf/kern.post.mk =================================================================== --- sys/conf/kern.post.mk +++ sys/conf/kern.post.mk @@ -228,7 +228,7 @@ # 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 Index: sys/modules/cloudabi32/Makefile =================================================================== --- sys/modules/cloudabi32/Makefile +++ sys/modules/cloudabi32/Makefile @@ -33,7 +33,7 @@ .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} Index: sys/modules/cloudabi64/Makefile =================================================================== --- sys/modules/cloudabi64/Makefile +++ sys/modules/cloudabi64/Makefile @@ -25,7 +25,7 @@ .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} Index: sys/modules/linux/Makefile =================================================================== --- sys/modules/linux/Makefile +++ sys/modules/linux/Makefile @@ -54,7 +54,7 @@ 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 \ Index: sys/modules/linux64/Makefile =================================================================== --- sys/modules/linux64/Makefile +++ sys/modules/linux64/Makefile @@ -30,7 +30,7 @@ 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 \