mirror of
https://github.com/torvalds/linux.git
synced 2026-10-17 06:20:02 +02:00
After a recent change in LLVM [1], builds with the random vDSO implementation, such as PowerPC and RISC-V, fail when checking the vDSO: arch/powerpc/kernel/vdso/vdso32.so.dbg: dynamic relocations are not supported arch/riscv/kernel/vdso/vdso.so.dbg: dynamic relocations are not supported memset() is now generated when zeroing params->reserved for some builds because LLVM has an optimization (now run in more instances) that can recognize at compile time when it is assigning a static value to a contiguous area of memory and turn that into a call to memset(). Both clang and GCC assume memset() is always available [2]. Clang has an internal fiddly hook, -max-store-memset, which we can set to a high number, to disable generating out of line memset calls [3]. Similarly, GCC has -finline-stringops=memset to do the same [4], should this issue ever hit future version of GCC. While these options wouldn't make sense for normal kernel code, it is fine for the extremely limited and intentionally compact vDSO code. Link:90cebef141[1] Link: https://gcc.gnu.org/onlinedocs/gcc-16.2.0/gcc/Standards.html#index-ffreestanding [2] Link:b28eeb28be[3] Link: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-finline-stringops [4] Closes: https://github.com/ClangBuiltLinux/linux/issues/2183 Cc: stable@vger.kernel.org # v6.12+ Signed-off-by: Nathan Chancellor <nathan@kernel.org> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
104 lines
3.0 KiB
Makefile
104 lines
3.0 KiB
Makefile
# SPDX-License-Identifier: GPL-2.0-only
|
|
# Copied from arch/tile/kernel/vdso/Makefile
|
|
|
|
# Include the generic Makefile to check the built vdso.
|
|
include $(srctree)/lib/vdso/Makefile.include
|
|
# Symbols present in the vdso
|
|
vdso-syms = rt_sigreturn
|
|
ifdef CONFIG_64BIT
|
|
vdso-syms += vgettimeofday
|
|
endif
|
|
vdso-syms += getcpu
|
|
vdso-syms += flush_icache
|
|
vdso-syms += hwprobe
|
|
vdso-syms += sys_hwprobe
|
|
|
|
ifdef CONFIG_VDSO_GETRANDOM
|
|
vdso-syms += getrandom
|
|
endif
|
|
|
|
ifdef VDSO_CFI_BUILD
|
|
CFI_MARCH = _zicfilp_zicfiss
|
|
CFI_FULL = -fcf-protection=full
|
|
CFI_SUFFIX = -cfi
|
|
OFFSET_SUFFIX = _cfi
|
|
ccflags-y += -DVDSO_CFI=1
|
|
asflags-y += -DVDSO_CFI=1
|
|
endif
|
|
|
|
# Files to link into the vdso
|
|
obj-vdso = $(patsubst %, %.o, $(vdso-syms)) note.o
|
|
|
|
ifdef CONFIG_VDSO_GETRANDOM
|
|
obj-vdso += vgetrandom-chacha.o
|
|
endif
|
|
|
|
ccflags-y := -fno-stack-protector
|
|
ccflags-y += -DDISABLE_BRANCH_PROFILING
|
|
ccflags-y += -fno-builtin
|
|
ccflags-y += $(CONFIG_CC_OPT_INLINE_MEMSET)
|
|
ccflags-y += $(KBUILD_BASE_ISA)$(CFI_MARCH)
|
|
ccflags-y += $(CFI_FULL)
|
|
asflags-y += $(KBUILD_BASE_ISA)$(CFI_MARCH)
|
|
asflags-y += $(CFI_FULL)
|
|
|
|
ccflags-remove-y += $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS) $(CC_FLAGS_LTO)
|
|
|
|
ifneq ($(c-gettimeofday-y),)
|
|
CFLAGS_vgettimeofday.o += -fPIC -include $(c-gettimeofday-y)
|
|
endif
|
|
|
|
ifneq ($(c-getrandom-y),)
|
|
CFLAGS_getrandom.o += -fPIC -include $(c-getrandom-y)
|
|
endif
|
|
|
|
CFLAGS_hwprobe.o += -fPIC
|
|
|
|
# Build rules
|
|
vdso_offsets := vdso$(if $(VDSO_CFI_BUILD),$(CFI_SUFFIX),)-offsets.h
|
|
vdso_o := vdso$(if $(VDSO_CFI_BUILD),$(CFI_SUFFIX),).o
|
|
vdso_so := vdso$(if $(VDSO_CFI_BUILD),$(CFI_SUFFIX),).so
|
|
vdso_so_dbg := vdso$(if $(VDSO_CFI_BUILD),$(CFI_SUFFIX),).so.dbg
|
|
vdso_lds := vdso.lds
|
|
|
|
targets := $(obj-vdso) $(vdso_so) $(vdso_so_dbg) $(vdso_lds)
|
|
|
|
obj-vdso := $(addprefix $(obj)/, $(obj-vdso))
|
|
|
|
obj-y += vdso$(if $(VDSO_CFI_BUILD),$(CFI_SUFFIX),).o
|
|
CPPFLAGS_$(vdso_lds) += -P -C -U$(ARCH)
|
|
ifneq ($(filter vgettimeofday, $(vdso-syms)),)
|
|
CPPFLAGS_$(vdso_lds) += -DHAS_VGETTIMEOFDAY
|
|
endif
|
|
|
|
# Force dependency
|
|
$(obj)/$(vdso_o): $(obj)/$(vdso_so)
|
|
|
|
# link rule for the .so file, .lds has to be first
|
|
$(obj)/$(vdso_so_dbg): $(obj)/$(vdso_lds) $(obj-vdso) FORCE
|
|
$(call if_changed,vdsold_and_check)
|
|
LDFLAGS_$(vdso_so_dbg) = -shared -soname=linux-vdso.so.1 \
|
|
--build-id=sha1 --eh-frame-hdr
|
|
|
|
# strip rule for the .so file
|
|
$(obj)/%.so: OBJCOPYFLAGS := -S
|
|
$(obj)/%.so: $(obj)/%.so.dbg FORCE
|
|
$(call if_changed,objcopy)
|
|
|
|
# Generate VDSO offsets using helper script
|
|
gen-vdsosym := $(src)/gen_vdso_offsets.sh
|
|
quiet_cmd_vdsosym = VDSOSYM $@
|
|
cmd_vdsosym = $(NM) $< | $(gen-vdsosym) $(OFFSET_SUFFIX) | LC_ALL=C sort > $@
|
|
|
|
include/generated/$(vdso_offsets): $(obj)/$(vdso_so_dbg) FORCE
|
|
$(call if_changed,vdsosym)
|
|
|
|
# actual build commands
|
|
# The DSO images are built using a special linker script
|
|
# Make sure only to export the intended __vdso_xxx symbol offsets.
|
|
quiet_cmd_vdsold_and_check = VDSOLD $@
|
|
cmd_vdsold_and_check = $(LD) $(CFI_FULL) $(ld_flags) -T $(filter-out FORCE,$^) -o $@.tmp && \
|
|
$(OBJCOPY) $(patsubst %, -G __vdso_%, $(vdso-syms)) $@.tmp $@ && \
|
|
rm $@.tmp && \
|
|
$(cmd_vdso_check)
|