Always pass the linker emulation via -m when linking modules and kernels.

Previously the linker emulation was only passed when building binary
objects for firmware modules.  This change always passes the desired
output format for kernel modules and kernels rather than requiring the
toolchain's default output format to match the desired output format.
This in turn permits use of external toolchains whose default output
format does not match the desired output format.

Reviewed by:	imp, emaste
Sponsored by:	DARPA / AFRL
Differential Revision:	https://reviews.freebsd.org/D10085
This commit is contained in:
John Baldwin 2017-04-05 03:05:04 +00:00
parent 5da3b3772f
commit dc653882d4
4 changed files with 10 additions and 9 deletions

View File

@ -56,8 +56,8 @@ CFLAGS += -mllvm -arm-enable-ehabi
# hack because genassym.c includes sys/bus.h which includes these.
genassym.o: bus_if.h device_if.h
SYSTEM_LD_ = ${LD} -Bdynamic -T ldscript.$M.noheader ${_LDFLAGS} \
--no-warn-mismatch --warn-common --export-dynamic \
SYSTEM_LD_ = ${LD} -m ${LD_EMULATION} -Bdynamic -T ldscript.$M.noheader \
${_LDFLAGS} --no-warn-mismatch --warn-common --export-dynamic \
--dynamic-linker /red/herring \
-o ${FULLKERNEL}.noheader -X ${SYSTEM_OBJS} vers.o
SYSTEM_LD_TAIL +=;sed s/" + SIZEOF_HEADERS"// ldscript.$M\

View File

@ -254,8 +254,7 @@ CFLAGS+= -std=iso9899:1999
CFLAGS+= -std=${CSTD}
.endif # CSTD
# Set target-specific linker emulation name. Used by ld -b binary to convert
# binary files into ELF objects.
# Set target-specific linker emulation name.
LD_EMULATION_aarch64=aarch64elf
LD_EMULATION_amd64=elf_x86_64_fbsd
LD_EMULATION_arm=armelf_fbsd

View File

@ -184,8 +184,9 @@ MD_ROOT_SIZE_CONFIGURED!= grep MD_ROOT_SIZE opt_md.h || true ; echo
SYSTEM_OBJS+= embedfs_${MFS_IMAGE:T:R}.o
.endif
.endif
SYSTEM_LD= @${LD} -Bdynamic -T ${LDSCRIPT} ${_LDFLAGS} --no-warn-mismatch \
--warn-common --export-dynamic --dynamic-linker /red/herring \
SYSTEM_LD= @${LD} -m ${LD_EMULATION} -Bdynamic -T ${LDSCRIPT} ${_LDFLAGS} \
--no-warn-mismatch --warn-common --export-dynamic \
--dynamic-linker /red/herring \
-o ${.TARGET} -X ${SYSTEM_OBJS} vers.o
SYSTEM_LD_TAIL= @${OBJCOPY} --strip-symbol gcc2_compiled. ${.TARGET} ; \
${SIZE} ${.TARGET} ; chmod 755 ${.TARGET}

View File

@ -210,7 +210,8 @@ ${PROG}.debug: ${FULLPROG}
.if ${__KLD_SHARED} == yes
${FULLPROG}: ${KMOD}.kld
.if ${MACHINE_CPUARCH} != "aarch64"
${LD} -Bshareable ${_LDFLAGS} -o ${.TARGET} ${KMOD}.kld
${LD} -m ${LD_EMULATION} -Bshareable ${_LDFLAGS} -o ${.TARGET} \
${KMOD}.kld
.else
#XXXKIB Relocatable linking in aarch64 ld from binutils 2.25.1 does
# not work. The linker corrupts the references to the external
@ -218,7 +219,7 @@ ${FULLPROG}: ${KMOD}.kld
# and should therefore loose the GOT entry. The problem seems
# to be fixed in the binutils-gdb git HEAD as of 2015-10-04. Hack
# below allows to get partially functioning modules for now.
${LD} -Bshareable ${_LDFLAGS} -o ${.TARGET} ${OBJS}
${LD} -m ${LD_EMULATION} -Bshareable ${_LDFLAGS} -o ${.TARGET} ${OBJS}
.endif
.if !defined(DEBUG_FLAGS)
${OBJCOPY} --strip-debug ${.TARGET}
@ -235,7 +236,7 @@ ${KMOD}.kld: ${OBJS}
.else
${FULLPROG}: ${OBJS}
.endif
${LD} ${_LDFLAGS} -r -d -o ${.TARGET} ${OBJS}
${LD} -m ${LD_EMULATION} ${_LDFLAGS} -r -d -o ${.TARGET} ${OBJS}
.if ${MK_CTF} != "no"
${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
.endif