xref: /linux-6.15/arch/riscv/kernel/vdso/Makefile (revision aa5af0aa)
1# SPDX-License-Identifier: GPL-2.0-only
2# Copied from arch/tile/kernel/vdso/Makefile
3
4# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
5# the inclusion of generic Makefile.
6ARCH_REL_TYPE_ABS := R_RISCV_32|R_RISCV_64|R_RISCV_JUMP_SLOT
7include $(srctree)/lib/vdso/Makefile
8# Symbols present in the vdso
9vdso-syms  = rt_sigreturn
10ifdef CONFIG_64BIT
11vdso-syms += vgettimeofday
12endif
13vdso-syms += getcpu
14vdso-syms += flush_icache
15vdso-syms += hwprobe
16vdso-syms += sys_hwprobe
17
18# Files to link into the vdso
19obj-vdso = $(patsubst %, %.o, $(vdso-syms)) note.o
20
21ccflags-y := -fno-stack-protector
22ccflags-y += -DDISABLE_BRANCH_PROFILING
23
24ifneq ($(c-gettimeofday-y),)
25  CFLAGS_vgettimeofday.o += -fPIC -include $(c-gettimeofday-y)
26endif
27
28CFLAGS_hwprobe.o += -fPIC
29
30# Build rules
31targets := $(obj-vdso) vdso.so vdso.so.dbg vdso.lds
32obj-vdso := $(addprefix $(obj)/, $(obj-vdso))
33
34obj-y += vdso.o
35CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
36ifneq ($(filter vgettimeofday, $(vdso-syms)),)
37CPPFLAGS_vdso.lds += -DHAS_VGETTIMEOFDAY
38endif
39
40# Disable -pg to prevent insert call site
41CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE)
42
43# Disable profiling and instrumentation for VDSO code
44GCOV_PROFILE := n
45KCOV_INSTRUMENT := n
46KASAN_SANITIZE := n
47UBSAN_SANITIZE := n
48
49# Force dependency
50$(obj)/vdso.o: $(obj)/vdso.so
51
52# link rule for the .so file, .lds has to be first
53$(obj)/vdso.so.dbg: $(obj)/vdso.lds $(obj-vdso) FORCE
54	$(call if_changed,vdsold)
55LDFLAGS_vdso.so.dbg = -shared -S -soname=linux-vdso.so.1 \
56	--build-id=sha1 --hash-style=both --eh-frame-hdr
57
58# strip rule for the .so file
59$(obj)/%.so: OBJCOPYFLAGS := -S
60$(obj)/%.so: $(obj)/%.so.dbg FORCE
61	$(call if_changed,objcopy)
62
63# Generate VDSO offsets using helper script
64gen-vdsosym := $(srctree)/$(src)/gen_vdso_offsets.sh
65quiet_cmd_vdsosym = VDSOSYM $@
66	cmd_vdsosym = $(NM) $< | $(gen-vdsosym) | LC_ALL=C sort > $@
67
68include/generated/vdso-offsets.h: $(obj)/vdso.so.dbg FORCE
69	$(call if_changed,vdsosym)
70
71# actual build commands
72# The DSO images are built using a special linker script
73# Make sure only to export the intended __vdso_xxx symbol offsets.
74quiet_cmd_vdsold = VDSOLD  $@
75      cmd_vdsold = $(LD) $(ld_flags) -T $(filter-out FORCE,$^) -o $@.tmp && \
76                   $(OBJCOPY) $(patsubst %, -G __vdso_%, $(vdso-syms)) $@.tmp $@ && \
77                   rm $@.tmp
78
79# install commands for the unstripped file
80quiet_cmd_vdso_install = INSTALL $@
81      cmd_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/vdso/$@
82
83vdso.so: $(obj)/vdso.so.dbg
84	@mkdir -p $(MODLIB)/vdso
85	$(call cmd,vdso_install)
86
87vdso_install: vdso.so
88