Index: sys/conf/kmod.mk =================================================================== --- sys/conf/kmod.mk +++ sys/conf/kmod.mk @@ -14,6 +14,9 @@ # to export all symbols. If not defined, no symbols are # exported. # +# KLD_SHARED A boolean indicating whether the module is to be built as +# a shared object. +# # KMOD The name of the kernel module to build. # # KMODDIR Base path for kernel modules (see kld(4)). [/boot/kernel] @@ -97,8 +100,11 @@ .SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S .m -# amd64 and mips use direct linking for kmod, all others use shared binaries -.if ${MACHINE_CPUARCH} != amd64 && ${MACHINE_CPUARCH} != mips +# amd64 and mips use direct linking for kmods, all others use shared objects by +# default. +.if defined(KLD_SHARED) +__KLD_SHARED=${KLD_SHARED:tl} +.elif ${MACHINE_CPUARCH} != "amd64" && ${MACHINE_CPUARCH} != "mips" __KLD_SHARED=yes .else __KLD_SHARED=no @@ -151,8 +157,9 @@ CFLAGS+= -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer .endif -.if ${MACHINE_CPUARCH} == "aarch64" || ${MACHINE_CPUARCH} == "riscv" -CFLAGS+= -fPIC +.if ${__KLD_SHARED} == "yes" && (${MACHINE_CPUARCH} == "aarch64" || \ + ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "riscv") +CFLAGS+= -fPIC -fno-plt .endif # Temporary workaround for PR 196407, which contains the fascinating details. Index: sys/modules/hpt27xx/Makefile =================================================================== --- sys/modules/hpt27xx/Makefile +++ sys/modules/hpt27xx/Makefile @@ -8,6 +8,11 @@ SRCS+= os_bsd.h hpt27xx_os_bsd.c hpt27xx_osm_bsd.c hpt27xx_config.c OBJS+= hpt27xx_lib.o +# The amd64 blob is not PIC. +.if ${MACHINE_CPUARCH} == "amd64" +KLD_SHARED=no +.endif + hpt27xx_lib.o: uudecode -p < ${HPT27XX}/$(MACHINE_ARCH)-elf.hpt27xx_lib.o.uu > ${.TARGET} Index: sys/modules/hptmv/Makefile =================================================================== --- sys/modules/hptmv/Makefile +++ sys/modules/hptmv/Makefile @@ -13,6 +13,11 @@ SRCS+= mv.c entry.c ioctl.c hptproc.c gui_lib.c OBJS+= hptmvraid.o +.if $(MACHINE_CPUARCH) == "amd64" +# The amd64 blob is not PIC. +KLD_SHARED=no +.endif + hptmvraid.o: uudecode -p < ${HPTMV}/${MACHINE_CPUARCH}-elf.raid.o.uu > ${.TARGET} Index: sys/modules/hptnr/Makefile =================================================================== --- sys/modules/hptnr/Makefile +++ sys/modules/hptnr/Makefile @@ -8,6 +8,11 @@ SRCS+= os_bsd.h hptnr_os_bsd.c hptnr_osm_bsd.c hptnr_config.c OBJS+= hptnr_lib.o +# The amd64 blob is not PIC. +.if ${MACHINE_CPUARCH} == "amd64" +KLD_SHARED=no +.endif + hptnr_lib.o: uudecode -p < ${HPTNR}/${MACHINE_ARCH}-elf.hptnr_lib.o.uu > ${.TARGET} Index: sys/modules/hptrr/Makefile =================================================================== --- sys/modules/hptrr/Makefile +++ sys/modules/hptrr/Makefile @@ -8,6 +8,11 @@ SRCS+= hptrr_os_bsd.c hptrr_osm_bsd.c hptrr_config.c OBJS = hptrr_lib.o +# The amd64 blob is not PIC. +.if ${MACHINE_CPUARCH} == "amd64" +KLD_SHARED=no +.endif + hptrr_lib.o: uudecode -p < ${HPTRR}/$(MACHINE_CPUARCH)-elf.hptrr_lib.o.uu > hptrr_lib.o