xref: /linux/arch/riscv/kernel/vdso/Makefile (revision eb13a1ff271b0d180687eebb30611b0b276d5193)
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 += $(CONFIG_CC_OPT_INLINE_MEMSET)
40ccflags-y += $(KBUILD_BASE_ISA)$(CFI_MARCH)
41ccflags-y += $(CFI_FULL)
42asflags-y += $(KBUILD_BASE_ISA)$(CFI_MARCH)
43asflags-y += $(CFI_FULL)
44
45ccflags-remove-y += $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS) $(CC_FLAGS_LTO)
46
47ifneq ($(c-gettimeofday-y),)
48  CFLAGS_vgettimeofday.o += -fPIC -include $(c-gettimeofday-y)
49endif
50
51ifneq ($(c-getrandom-y),)
52  CFLAGS_getrandom.o += -fPIC -include $(c-getrandom-y)
53endif
54
55CFLAGS_hwprobe.o += -fPIC
56
57# Build rules
58vdso_offsets := vdso$(if $(VDSO_CFI_BUILD),$(CFI_SUFFIX),)-offsets.h
59vdso_o := vdso$(if $(VDSO_CFI_BUILD),$(CFI_SUFFIX),).o
60vdso_so := vdso$(if $(VDSO_CFI_BUILD),$(CFI_SUFFIX),).so
61vdso_so_dbg := vdso$(if $(VDSO_CFI_BUILD),$(CFI_SUFFIX),).so.dbg
62vdso_lds := vdso.lds
63
64targets := $(obj-vdso) $(vdso_so) $(vdso_so_dbg) $(vdso_lds)
65
66obj-vdso := $(addprefix $(obj)/, $(obj-vdso))
67
68obj-y += vdso$(if $(VDSO_CFI_BUILD),$(CFI_SUFFIX),).o
69CPPFLAGS_$(vdso_lds) += -P -C -U$(ARCH)
70ifneq ($(filter vgettimeofday, $(vdso-syms)),)
71CPPFLAGS_$(vdso_lds) += -DHAS_VGETTIMEOFDAY
72endif
73
74# Force dependency
75$(obj)/$(vdso_o): $(obj)/$(vdso_so)
76
77# link rule for the .so file, .lds has to be first
78$(obj)/$(vdso_so_dbg): $(obj)/$(vdso_lds) $(obj-vdso) FORCE
79	$(call if_changed,vdsold_and_check)
80LDFLAGS_$(vdso_so_dbg) = -shared -soname=linux-vdso.so.1 \
81	--build-id=sha1 --eh-frame-hdr
82
83# strip rule for the .so file
84$(obj)/%.so: OBJCOPYFLAGS := -S
85$(obj)/%.so: $(obj)/%.so.dbg FORCE
86	$(call if_changed,objcopy)
87
88# Generate VDSO offsets using helper script
89gen-vdsosym := $(src)/gen_vdso_offsets.sh
90quiet_cmd_vdsosym = VDSOSYM $@
91	cmd_vdsosym = $(NM) $< | $(gen-vdsosym) $(OFFSET_SUFFIX) | LC_ALL=C sort > $@
92
93include/generated/$(vdso_offsets): $(obj)/$(vdso_so_dbg) FORCE
94	$(call if_changed,vdsosym)
95
96# actual build commands
97# The DSO images are built using a special linker script
98# Make sure only to export the intended __vdso_xxx symbol offsets.
99quiet_cmd_vdsold_and_check = VDSOLD  $@
100      cmd_vdsold_and_check = $(LD) $(CFI_FULL) $(ld_flags) -T $(filter-out FORCE,$^) -o $@.tmp && \
101                   $(OBJCOPY) $(patsubst %, -G __vdso_%, $(vdso-syms)) $@.tmp $@ && \
102                   rm $@.tmp && \
103                   $(cmd_vdso_check)
104