xref: /linux/arch/riscv/kernel/vdso/Makefile (revision 119b1e61a769aa98e68599f44721661a4d8c55f3)
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
20# Files to link into the vdso
21obj-vdso = $(patsubst %, %.o, $(vdso-syms)) note.o
22
23ifdef CONFIG_VDSO_GETRANDOM
24obj-vdso += vgetrandom-chacha.o
25endif
26
27ccflags-y := -fno-stack-protector
28ccflags-y += -DDISABLE_BRANCH_PROFILING
29ccflags-y += -fno-builtin
30
31ifneq ($(c-gettimeofday-y),)
32  CFLAGS_vgettimeofday.o += -fPIC -include $(c-gettimeofday-y)
33endif
34
35ifneq ($(c-getrandom-y),)
36  CFLAGS_getrandom.o += -fPIC -include $(c-getrandom-y)
37endif
38
39CFLAGS_hwprobe.o += -fPIC
40
41# Build rules
42targets := $(obj-vdso) vdso.so vdso.so.dbg vdso.lds
43obj-vdso := $(addprefix $(obj)/, $(obj-vdso))
44
45obj-y += vdso.o
46CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
47ifneq ($(filter vgettimeofday, $(vdso-syms)),)
48CPPFLAGS_vdso.lds += -DHAS_VGETTIMEOFDAY
49endif
50
51# Disable -pg to prevent insert call site
52CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS)
53CFLAGS_REMOVE_getrandom.o = $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS)
54CFLAGS_REMOVE_hwprobe.o = $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS)
55
56# Force dependency
57$(obj)/vdso.o: $(obj)/vdso.so
58
59# link rule for the .so file, .lds has to be first
60$(obj)/vdso.so.dbg: $(obj)/vdso.lds $(obj-vdso) FORCE
61	$(call if_changed,vdsold_and_check)
62LDFLAGS_vdso.so.dbg = -shared -soname=linux-vdso.so.1 \
63	--build-id=sha1 --eh-frame-hdr
64
65# strip rule for the .so file
66$(obj)/%.so: OBJCOPYFLAGS := -S
67$(obj)/%.so: $(obj)/%.so.dbg FORCE
68	$(call if_changed,objcopy)
69
70# Generate VDSO offsets using helper script
71gen-vdsosym := $(src)/gen_vdso_offsets.sh
72quiet_cmd_vdsosym = VDSOSYM $@
73	cmd_vdsosym = $(NM) $< | $(gen-vdsosym) | LC_ALL=C sort > $@
74
75include/generated/vdso-offsets.h: $(obj)/vdso.so.dbg FORCE
76	$(call if_changed,vdsosym)
77
78# actual build commands
79# The DSO images are built using a special linker script
80# Make sure only to export the intended __vdso_xxx symbol offsets.
81quiet_cmd_vdsold_and_check = VDSOLD  $@
82      cmd_vdsold_and_check = $(LD) $(ld_flags) -T $(filter-out FORCE,$^) -o $@.tmp && \
83                   $(OBJCOPY) $(patsubst %, -G __vdso_%, $(vdso-syms)) $@.tmp $@ && \
84                   rm $@.tmp && \
85                   $(cmd_vdso_check)
86