xref: /linux/arch/riscv/kernel/vdso/Makefile (revision 119b1e61a769aa98e68599f44721661a4d8c55f3)
1ec8f24b7SThomas Gleixner# SPDX-License-Identifier: GPL-2.0-only
2e2c0cdfbSPalmer Dabbelt# Copied from arch/tile/kernel/vdso/Makefile
3e2c0cdfbSPalmer Dabbelt
4aff69273SFangrui Song# Include the generic Makefile to check the built vdso.
5127b0e05SThomas Weißschuhinclude $(srctree)/lib/vdso/Makefile.include
6e2c0cdfbSPalmer Dabbelt# Symbols present in the vdso
7e2c0cdfbSPalmer Dabbeltvdso-syms  = rt_sigreturn
8d4c08b97SArnd Bergmannifdef CONFIG_64BIT
9ad5d1122SVincent Chenvdso-syms += vgettimeofday
10d4c08b97SArnd Bergmannendif
1128dfbe6eSAndrew Watermanvdso-syms += getcpu
12921ebd8fSAndrew Watermanvdso-syms += flush_icache
13aa5af0aaSEvan Greenvdso-syms += hwprobe
14aa5af0aaSEvan Greenvdso-syms += sys_hwprobe
15e2c0cdfbSPalmer Dabbelt
16*ee0d0305SXi Ruoyaoifdef CONFIG_VDSO_GETRANDOM
17*ee0d0305SXi Ruoyaovdso-syms += getrandom
18*ee0d0305SXi Ruoyaoendif
19*ee0d0305SXi Ruoyao
20e2c0cdfbSPalmer Dabbelt# Files to link into the vdso
210a9f2a61SAndreas Schwabobj-vdso = $(patsubst %, %.o, $(vdso-syms)) note.o
22e2c0cdfbSPalmer Dabbelt
23*ee0d0305SXi Ruoyaoifdef CONFIG_VDSO_GETRANDOM
24*ee0d0305SXi Ruoyaoobj-vdso += vgetrandom-chacha.o
25*ee0d0305SXi Ruoyaoendif
26*ee0d0305SXi Ruoyao
2740284a07STobias Klauserccflags-y := -fno-stack-protector
2874f6bb55SJisheng Zhangccflags-y += -DDISABLE_BRANCH_PROFILING
29bf40167dSAlexandre Ghiticcflags-y += -fno-builtin
3040284a07STobias Klauser
31ad5d1122SVincent Chenifneq ($(c-gettimeofday-y),)
32a0fc3b32SVincent Chen  CFLAGS_vgettimeofday.o += -fPIC -include $(c-gettimeofday-y)
33ad5d1122SVincent Chenendif
34ad5d1122SVincent Chen
35*ee0d0305SXi Ruoyaoifneq ($(c-getrandom-y),)
36*ee0d0305SXi Ruoyao  CFLAGS_getrandom.o += -fPIC -include $(c-getrandom-y)
37*ee0d0305SXi Ruoyaoendif
38*ee0d0305SXi Ruoyao
39aa5af0aaSEvan GreenCFLAGS_hwprobe.o += -fPIC
40aa5af0aaSEvan Green
41e2c0cdfbSPalmer Dabbelt# Build rules
42fde9c59aSSaleem Abdulrasooltargets := $(obj-vdso) vdso.so vdso.so.dbg vdso.lds
43e2c0cdfbSPalmer Dabbeltobj-vdso := $(addprefix $(obj)/, $(obj-vdso))
44e2c0cdfbSPalmer Dabbelt
45fde9c59aSSaleem Abdulrasoolobj-y += vdso.o
46e2c0cdfbSPalmer DabbeltCPPFLAGS_vdso.lds += -P -C -U$(ARCH)
47fcae44fdSNathan Chancellorifneq ($(filter vgettimeofday, $(vdso-syms)),)
48fcae44fdSNathan ChancellorCPPFLAGS_vdso.lds += -DHAS_VGETTIMEOFDAY
49fcae44fdSNathan Chancellorendif
50e2c0cdfbSPalmer Dabbelt
51e05d57dcSGuo Ren# Disable -pg to prevent insert call site
52d1584d79SSami TolvanenCFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS)
53*ee0d0305SXi RuoyaoCFLAGS_REMOVE_getrandom.o = $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS)
54ad14f7caSVladimir IsaevCFLAGS_REMOVE_hwprobe.o = $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS)
55e05d57dcSGuo Ren
56e2c0cdfbSPalmer Dabbelt# Force dependency
57e2c0cdfbSPalmer Dabbelt$(obj)/vdso.o: $(obj)/vdso.so
58e2c0cdfbSPalmer Dabbelt
59e2c0cdfbSPalmer Dabbelt# link rule for the .so file, .lds has to be first
60772d7891SJisheng Zhang$(obj)/vdso.so.dbg: $(obj)/vdso.lds $(obj-vdso) FORCE
61c6898d66SAlexandre Ghiti	$(call if_changed,vdsold_and_check)
627587a360SChangbin DuLDFLAGS_vdso.so.dbg = -shared -soname=linux-vdso.so.1 \
632940954cSXi Ruoyao	--build-id=sha1 --eh-frame-hdr
64e2c0cdfbSPalmer Dabbelt
65e2c0cdfbSPalmer Dabbelt# strip rule for the .so file
66e2c0cdfbSPalmer Dabbelt$(obj)/%.so: OBJCOPYFLAGS := -S
67e2c0cdfbSPalmer Dabbelt$(obj)/%.so: $(obj)/%.so.dbg FORCE
68e2c0cdfbSPalmer Dabbelt	$(call if_changed,objcopy)
69e2c0cdfbSPalmer Dabbelt
70fde9c59aSSaleem Abdulrasool# Generate VDSO offsets using helper script
71b1992c37SMasahiro Yamadagen-vdsosym := $(src)/gen_vdso_offsets.sh
72fde9c59aSSaleem Abdulrasoolquiet_cmd_vdsosym = VDSOSYM $@
73fde9c59aSSaleem Abdulrasool	cmd_vdsosym = $(NM) $< | $(gen-vdsosym) | LC_ALL=C sort > $@
74fde9c59aSSaleem Abdulrasool
75fde9c59aSSaleem Abdulrasoolinclude/generated/vdso-offsets.h: $(obj)/vdso.so.dbg FORCE
76fde9c59aSSaleem Abdulrasool	$(call if_changed,vdsosym)
77fde9c59aSSaleem Abdulrasool
78e2c0cdfbSPalmer Dabbelt# actual build commands
79e2c0cdfbSPalmer Dabbelt# The DSO images are built using a special linker script
80e2c0cdfbSPalmer Dabbelt# Make sure only to export the intended __vdso_xxx symbol offsets.
81c6898d66SAlexandre Ghitiquiet_cmd_vdsold_and_check = VDSOLD  $@
82c6898d66SAlexandre Ghiti      cmd_vdsold_and_check = $(LD) $(ld_flags) -T $(filter-out FORCE,$^) -o $@.tmp && \
837f3d3490SNathan Chancellor                   $(OBJCOPY) $(patsubst %, -G __vdso_%, $(vdso-syms)) $@.tmp $@ && \
84c6898d66SAlexandre Ghiti                   rm $@.tmp && \
85c6898d66SAlexandre Ghiti                   $(cmd_vdso_check)
86