xref: /linux/arch/x86/um/vdso/Makefile (revision b3d9a136815ca9284ade2a897a3b7d2b0084c33c)
1# SPDX-License-Identifier: GPL-2.0
2#
3# Building vDSO images for x86.
4#
5
6# Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
7KCOV_INSTRUMENT                := n
8
9VDSO64-y		:= y
10
11vdso-install-$(VDSO64-y)	+= vdso.so
12
13
14# files to link into the vdso
15vobjs-y := vdso-note.o um_vdso.o
16
17# files to link into kernel
18obj-$(VDSO64-y)			+= vdso.o vma.o
19
20vobjs := $(foreach F,$(vobjs-y),$(obj)/$F)
21
22$(obj)/vdso.o: $(obj)/vdso.so
23
24targets += vdso.so vdso.so.dbg vdso.lds $(vobjs-y)
25
26export CPPFLAGS_vdso.lds += -P -C
27
28VDSO_LDFLAGS_vdso.lds = -m64 -Wl,-soname=linux-vdso.so.1 \
29       -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096
30
31$(obj)/vdso.o: $(src)/vdso.S $(obj)/vdso.so
32
33$(obj)/vdso.so.dbg: $(src)/vdso.lds $(vobjs) FORCE
34	$(call if_changed,vdso)
35
36$(obj)/%.so: OBJCOPYFLAGS := -S
37$(obj)/%.so: $(obj)/%.so.dbg FORCE
38	$(call if_changed,objcopy)
39
40#
41# Don't omit frame pointers for ease of userspace debugging, but do
42# optimize sibling calls.
43#
44CFL := $(PROFILING) -mcmodel=small -fPIC -O2 -fasynchronous-unwind-tables -m64 \
45       $(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \
46       -fno-omit-frame-pointer -foptimize-sibling-calls
47
48$(vobjs): KBUILD_CFLAGS += $(CFL)
49
50#
51# vDSO code runs in userspace and -pg doesn't help with profiling anyway.
52#
53CFLAGS_REMOVE_vdso-note.o = -pg -fprofile-arcs -ftest-coverage
54CFLAGS_REMOVE_um_vdso.o = -pg -fprofile-arcs -ftest-coverage
55
56targets += vdso-syms.lds
57extra-$(VDSO64-y)			+= vdso-syms.lds
58
59#
60# Match symbols in the DSO that look like VDSO*; produce a file of constants.
61#
62sed-vdsosym := -e 's/^00*/0/' \
63	-e 's/^\([0-9a-fA-F]*\) . \(VDSO[a-zA-Z0-9_]*\)$$/\2 = 0x\1;/p'
64quiet_cmd_vdsosym = VDSOSYM $@
65define cmd_vdsosym
66	$(NM) $< | LC_ALL=C sed -n $(sed-vdsosym) | LC_ALL=C sort > $@
67endef
68
69$(obj)/%-syms.lds: $(obj)/%.so.dbg FORCE
70	$(call if_changed,vdsosym)
71
72#
73# The DSO images are built using a special linker script.
74#
75quiet_cmd_vdso = VDSO    $@
76      cmd_vdso = $(CC) -nostdlib -o $@ \
77		       $(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \
78		       -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
79		 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
80
81VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
82GCOV_PROFILE := n
83
84#
85# Install the unstripped copy of vdso*.so listed in $(vdso-install-y).
86#
87quiet_cmd_vdso_install = INSTALL $@
88      cmd_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/vdso/$@
89$(vdso-install-y): %.so: $(obj)/%.so.dbg FORCE
90	@mkdir -p $(MODLIB)/vdso
91	$(call cmd,vdso_install)
92
93PHONY += vdso_install $(vdso-install-y)
94vdso_install: $(vdso-install-y)
95