1# SPDX-License-Identifier: GPL-2.0
2# Objects to go into the VDSO.
3
4# Sanitizer runtimes are unavailable and cannot be linked here.
5 KCSAN_SANITIZE			:= n
6
7# Include the generic Makefile to check the built vdso.
8include $(srctree)/lib/vdso/Makefile
9
10obj-vdso-y := elf.o vgettimeofday.o sigreturn.o
11
12# Common compiler flags between ABIs.
13ccflags-vdso := \
14	$(filter -I%,$(KBUILD_CFLAGS)) \
15	$(filter -E%,$(KBUILD_CFLAGS)) \
16	$(filter -mmicromips,$(KBUILD_CFLAGS)) \
17	$(filter -march=%,$(KBUILD_CFLAGS)) \
18	$(filter -m%-float,$(KBUILD_CFLAGS)) \
19	$(filter -mno-loongson-%,$(KBUILD_CFLAGS)) \
20	$(CLANG_FLAGS) \
21	-D__VDSO__
22
23ifndef CONFIG_64BIT
24ccflags-vdso += -DBUILD_VDSO32
25endif
26
27#
28# The -fno-jump-tables flag only prevents the compiler from generating
29# jump tables but does not prevent the compiler from emitting absolute
30# offsets.
31cflags-vdso := $(ccflags-vdso) \
32	$(filter -W%,$(filter-out -Wa$(comma)%,$(KBUILD_CFLAGS))) \
33	-O3 -g -fPIC -fno-strict-aliasing -fno-common -fno-builtin -G 0 \
34	-mrelax-pic-calls $(call cc-option, -mexplicit-relocs) \
35	-fno-stack-protector -fno-jump-tables -DDISABLE_BRANCH_PROFILING \
36	$(call cc-option, -fno-asynchronous-unwind-tables)
37aflags-vdso := $(ccflags-vdso) \
38	-D__ASSEMBLY__ -Wa,-gdwarf-2
39
40ifneq ($(c-gettimeofday-y),)
41CFLAGS_vgettimeofday.o = -include $(c-gettimeofday-y)
42
43# config-n32-o32-env.c prepares the environment to build a 32bit vDSO
44# library on a 64bit kernel.
45# Note: Needs to be included before than the generic library.
46CFLAGS_vgettimeofday-o32.o = -include $(srctree)/$(src)/config-n32-o32-env.c -include $(c-gettimeofday-y)
47CFLAGS_vgettimeofday-n32.o = -include $(srctree)/$(src)/config-n32-o32-env.c -include $(c-gettimeofday-y)
48endif
49
50CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE)
51
52ifdef CONFIG_MIPS_DISABLE_VDSO
53  obj-vdso-y := $(filter-out vgettimeofday.o, $(obj-vdso-y))
54endif
55
56# VDSO linker flags.
57ldflags-y := -Bsymbolic --no-undefined -soname=linux-vdso.so.1 \
58	$(filter -E%,$(KBUILD_CFLAGS)) -shared \
59	-G 0 --eh-frame-hdr --hash-style=sysv --build-id=sha1 -T
60
61CFLAGS_REMOVE_vdso.o = $(CC_FLAGS_FTRACE)
62
63GCOV_PROFILE := n
64UBSAN_SANITIZE := n
65KCOV_INSTRUMENT := n
66
67# Check that we don't have PIC 'jalr t9' calls left
68quiet_cmd_vdso_mips_check = VDSOCHK $@
69      cmd_vdso_mips_check = if $(OBJDUMP) --disassemble $@ | grep -E -h "jalr.*t9" > /dev/null; \
70		       then (echo >&2 "$@: PIC 'jalr t9' calls are not supported"; \
71			     rm -f $@; /bin/false); fi
72
73#
74# Shared build commands.
75#
76
77quiet_cmd_vdsold_and_vdso_check = LD      $@
78      cmd_vdsold_and_vdso_check = $(cmd_ld); $(cmd_vdso_check); $(cmd_vdso_mips_check)
79
80quiet_cmd_vdsoas_o_S = AS      $@
81      cmd_vdsoas_o_S = $(CC) $(a_flags) -c -o $@ $<
82
83# Strip rule for the raw .so files
84$(obj)/%.so.raw: OBJCOPYFLAGS := -S
85$(obj)/%.so.raw: $(obj)/%.so.dbg.raw FORCE
86	$(call if_changed,objcopy)
87
88hostprogs := genvdso
89
90quiet_cmd_genvdso = GENVDSO $@
91define cmd_genvdso
92	$(foreach file,$(filter %.raw,$^),cp $(file) $(file:%.raw=%) &&) \
93	$(obj)/genvdso $(<:%.raw=%) $(<:%.dbg.raw=%) $@ $(VDSO_NAME)
94endef
95
96#
97# Build native VDSO.
98#
99
100native-abi := $(filter -mabi=%,$(KBUILD_CFLAGS))
101
102targets += $(obj-vdso-y)
103targets += vdso.lds
104targets += vdso.so.dbg.raw vdso.so.raw
105targets += vdso.so.dbg vdso.so
106targets += vdso-image.c
107
108obj-vdso := $(obj-vdso-y:%.o=$(obj)/%.o)
109
110$(obj-vdso): KBUILD_CFLAGS := $(cflags-vdso) $(native-abi)
111$(obj-vdso): KBUILD_AFLAGS := $(aflags-vdso) $(native-abi)
112
113$(obj)/vdso.lds: KBUILD_CPPFLAGS := $(ccflags-vdso) $(native-abi)
114
115$(obj)/vdso.so.dbg.raw: $(obj)/vdso.lds $(obj-vdso) FORCE
116	$(call if_changed,vdsold_and_vdso_check)
117
118$(obj)/vdso-image.c: $(obj)/vdso.so.dbg.raw $(obj)/vdso.so.raw \
119                     $(obj)/genvdso FORCE
120	$(call if_changed,genvdso)
121
122obj-y += vdso-image.o
123
124#
125# Build O32 VDSO.
126#
127
128# Define these outside the ifdef to ensure they are picked up by clean.
129targets += $(obj-vdso-y:%.o=%-o32.o)
130targets += vdso-o32.lds
131targets += vdso-o32.so.dbg.raw vdso-o32.so.raw
132targets += vdso-o32.so.dbg vdso-o32.so
133targets += vdso-o32-image.c
134
135ifdef CONFIG_MIPS32_O32
136
137obj-vdso-o32 := $(obj-vdso-y:%.o=$(obj)/%-o32.o)
138
139$(obj-vdso-o32): KBUILD_CFLAGS := $(cflags-vdso) -mabi=32
140$(obj-vdso-o32): KBUILD_AFLAGS := $(aflags-vdso) -mabi=32
141
142$(obj)/%-o32.o: $(src)/%.S FORCE
143	$(call if_changed_dep,vdsoas_o_S)
144
145$(obj)/%-o32.o: $(src)/%.c FORCE
146	$(call cmd,force_checksrc)
147	$(call if_changed_rule,cc_o_c)
148
149$(obj)/vdso-o32.lds: KBUILD_CPPFLAGS := $(ccflags-vdso) -mabi=32
150$(obj)/vdso-o32.lds: $(src)/vdso.lds.S FORCE
151	$(call if_changed_dep,cpp_lds_S)
152
153$(obj)/vdso-o32.so.dbg.raw: $(obj)/vdso-o32.lds $(obj-vdso-o32) FORCE
154	$(call if_changed,vdsold_and_vdso_check)
155
156$(obj)/vdso-o32-image.c: VDSO_NAME := o32
157$(obj)/vdso-o32-image.c: $(obj)/vdso-o32.so.dbg.raw $(obj)/vdso-o32.so.raw \
158                         $(obj)/genvdso FORCE
159	$(call if_changed,genvdso)
160
161obj-y += vdso-o32-image.o
162
163endif
164
165#
166# Build N32 VDSO.
167#
168
169targets += $(obj-vdso-y:%.o=%-n32.o)
170targets += vdso-n32.lds
171targets += vdso-n32.so.dbg.raw vdso-n32.so.raw
172targets += vdso-n32.so.dbg vdso-n32.so
173targets += vdso-n32-image.c
174
175ifdef CONFIG_MIPS32_N32
176
177obj-vdso-n32 := $(obj-vdso-y:%.o=$(obj)/%-n32.o)
178
179$(obj-vdso-n32): KBUILD_CFLAGS := $(cflags-vdso) -mabi=n32
180$(obj-vdso-n32): KBUILD_AFLAGS := $(aflags-vdso) -mabi=n32
181
182$(obj)/%-n32.o: $(src)/%.S FORCE
183	$(call if_changed_dep,vdsoas_o_S)
184
185$(obj)/%-n32.o: $(src)/%.c FORCE
186	$(call cmd,force_checksrc)
187	$(call if_changed_rule,cc_o_c)
188
189$(obj)/vdso-n32.lds: KBUILD_CPPFLAGS := $(ccflags-vdso) -mabi=n32
190$(obj)/vdso-n32.lds: $(src)/vdso.lds.S FORCE
191	$(call if_changed_dep,cpp_lds_S)
192
193$(obj)/vdso-n32.so.dbg.raw: $(obj)/vdso-n32.lds $(obj-vdso-n32) FORCE
194	$(call if_changed,vdsold_and_vdso_check)
195
196$(obj)/vdso-n32-image.c: VDSO_NAME := n32
197$(obj)/vdso-n32-image.c: $(obj)/vdso-n32.so.dbg.raw $(obj)/vdso-n32.so.raw \
198                         $(obj)/genvdso FORCE
199	$(call if_changed,genvdso)
200
201obj-y += vdso-n32-image.o
202
203endif
204
205# FIXME: Need install rule for debug.
206# Needs to deal with dependency for generation of dbg by cmd_genvdso...
207