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