xref: /linux/arch/riscv/kernel/vdso/Makefile (revision 20d38f7c45a44e4b762b586a7bcacbc93ddb3153)
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
15
16# Files to link into the vdso
17obj-vdso = $(patsubst %, %.o, $(vdso-syms)) note.o
18
19ifneq ($(c-gettimeofday-y),)
20  CFLAGS_vgettimeofday.o += -fPIC -include $(c-gettimeofday-y)
21endif
22
23# Build rules
24targets := $(obj-vdso) vdso.so vdso.so.dbg vdso.lds vdso-dummy.o
25obj-vdso := $(addprefix $(obj)/, $(obj-vdso))
26
27obj-y += vdso.o vdso-syms.o
28CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
29
30# Disable -pg to prevent insert call site
31CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE) -Os
32
33# Disable gcov profiling for VDSO code
34GCOV_PROFILE := n
35KCOV_INSTRUMENT := n
36
37# Force dependency
38$(obj)/vdso.o: $(obj)/vdso.so
39
40# link rule for the .so file, .lds has to be first
41SYSCFLAGS_vdso.so.dbg = $(c_flags)
42$(obj)/vdso.so.dbg: $(src)/vdso.lds $(obj-vdso) FORCE
43	$(call if_changed,vdsold)
44
45# We also create a special relocatable object that should mirror the symbol
46# table and layout of the linked DSO. With ld --just-symbols we can then
47# refer to these symbols in the kernel code rather than hand-coded addresses.
48
49SYSCFLAGS_vdso.so.dbg = -shared -s -Wl,-soname=linux-vdso.so.1 \
50	-Wl,--build-id -Wl,--hash-style=both
51$(obj)/vdso-dummy.o: $(src)/vdso.lds $(obj)/rt_sigreturn.o FORCE
52	$(call if_changed,vdsold)
53
54LDFLAGS_vdso-syms.o := -r --just-symbols
55$(obj)/vdso-syms.o: $(obj)/vdso-dummy.o FORCE
56	$(call if_changed,ld)
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# actual build commands
64# The DSO images are built using a special linker script
65# Add -lgcc so rv32 gets static muldi3 and lshrdi3 definitions.
66# Make sure only to export the intended __vdso_xxx symbol offsets.
67quiet_cmd_vdsold = VDSOLD  $@
68      cmd_vdsold = $(CC) $(KBUILD_CFLAGS) $(call cc-option, -no-pie) -nostdlib -nostartfiles $(SYSCFLAGS_$(@F)) \
69                           -Wl,-T,$(filter-out FORCE,$^) -o $@.tmp && \
70                   $(CROSS_COMPILE)objcopy \
71                           $(patsubst %, -G __vdso_%, $(vdso-syms)) $@.tmp $@ && \
72                   rm $@.tmp
73
74# install commands for the unstripped file
75quiet_cmd_vdso_install = INSTALL $@
76      cmd_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/vdso/$@
77
78vdso.so: $(obj)/vdso.so.dbg
79	@mkdir -p $(MODLIB)/vdso
80	$(call cmd,vdso_install)
81
82vdso_install: vdso.so
83