1# SPDX-License-Identifier: GPL-2.0-only 2# Copied from arch/tile/kernel/vdso/Makefile 3 4# Include the generic Makefile to check the built vdso. 5include $(srctree)/lib/vdso/Makefile.include 6# Symbols present in the vdso 7vdso-syms = rt_sigreturn 8ifdef CONFIG_64BIT 9vdso-syms += vgettimeofday 10endif 11vdso-syms += getcpu 12vdso-syms += flush_icache 13vdso-syms += hwprobe 14vdso-syms += sys_hwprobe 15 16ifdef CONFIG_VDSO_GETRANDOM 17vdso-syms += getrandom 18endif 19 20ifdef VDSO_CFI_BUILD 21CFI_MARCH = _zicfilp_zicfiss 22CFI_FULL = -fcf-protection=full 23CFI_SUFFIX = -cfi 24OFFSET_SUFFIX = _cfi 25ccflags-y += -DVDSO_CFI=1 26asflags-y += -DVDSO_CFI=1 27endif 28 29# Files to link into the vdso 30obj-vdso = $(patsubst %, %.o, $(vdso-syms)) note.o 31 32ifdef CONFIG_VDSO_GETRANDOM 33obj-vdso += vgetrandom-chacha.o 34endif 35 36ccflags-y := -fno-stack-protector 37ccflags-y += -DDISABLE_BRANCH_PROFILING 38ccflags-y += -fno-builtin 39ccflags-y += $(KBUILD_BASE_ISA)$(CFI_MARCH) 40ccflags-y += $(CFI_FULL) 41asflags-y += $(KBUILD_BASE_ISA)$(CFI_MARCH) 42asflags-y += $(CFI_FULL) 43 44ccflags-remove-y += $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS) $(CC_FLAGS_LTO) 45 46ifneq ($(c-gettimeofday-y),) 47 CFLAGS_vgettimeofday.o += -fPIC -include $(c-gettimeofday-y) 48endif 49 50ifneq ($(c-getrandom-y),) 51 CFLAGS_getrandom.o += -fPIC -include $(c-getrandom-y) 52endif 53 54CFLAGS_hwprobe.o += -fPIC 55 56# Build rules 57vdso_offsets := vdso$(if $(VDSO_CFI_BUILD),$(CFI_SUFFIX),)-offsets.h 58vdso_o := vdso$(if $(VDSO_CFI_BUILD),$(CFI_SUFFIX),).o 59vdso_so := vdso$(if $(VDSO_CFI_BUILD),$(CFI_SUFFIX),).so 60vdso_so_dbg := vdso$(if $(VDSO_CFI_BUILD),$(CFI_SUFFIX),).so.dbg 61vdso_lds := vdso.lds 62 63targets := $(obj-vdso) $(vdso_so) $(vdso_so_dbg) $(vdso_lds) 64 65obj-vdso := $(addprefix $(obj)/, $(obj-vdso)) 66 67obj-y += vdso$(if $(VDSO_CFI_BUILD),$(CFI_SUFFIX),).o 68CPPFLAGS_$(vdso_lds) += -P -C -U$(ARCH) 69ifneq ($(filter vgettimeofday, $(vdso-syms)),) 70CPPFLAGS_$(vdso_lds) += -DHAS_VGETTIMEOFDAY 71endif 72 73# Force dependency 74$(obj)/$(vdso_o): $(obj)/$(vdso_so) 75 76# link rule for the .so file, .lds has to be first 77$(obj)/$(vdso_so_dbg): $(obj)/$(vdso_lds) $(obj-vdso) FORCE 78 $(call if_changed,vdsold_and_check) 79LDFLAGS_$(vdso_so_dbg) = -shared -soname=linux-vdso.so.1 \ 80 --build-id=sha1 --eh-frame-hdr 81 82# strip rule for the .so file 83$(obj)/%.so: OBJCOPYFLAGS := -S 84$(obj)/%.so: $(obj)/%.so.dbg FORCE 85 $(call if_changed,objcopy) 86 87# Generate VDSO offsets using helper script 88gen-vdsosym := $(src)/gen_vdso_offsets.sh 89quiet_cmd_vdsosym = VDSOSYM $@ 90 cmd_vdsosym = $(NM) $< | $(gen-vdsosym) $(OFFSET_SUFFIX) | LC_ALL=C sort > $@ 91 92include/generated/$(vdso_offsets): $(obj)/$(vdso_so_dbg) FORCE 93 $(call if_changed,vdsosym) 94 95# actual build commands 96# The DSO images are built using a special linker script 97# Make sure only to export the intended __vdso_xxx symbol offsets. 98quiet_cmd_vdsold_and_check = VDSOLD $@ 99 cmd_vdsold_and_check = $(LD) $(CFI_FULL) $(ld_flags) -T $(filter-out FORCE,$^) -o $@.tmp && \ 100 $(OBJCOPY) $(patsubst %, -G __vdso_%, $(vdso-syms)) $@.tmp $@ && \ 101 rm $@.tmp && \ 102 $(cmd_vdso_check) 103