xref: /openbmc/linux/arch/mips/vdso/Makefile (revision 89e33ea7)
1# SPDX-License-Identifier: GPL-2.0
2# Objects to go into the VDSO.
3obj-vdso-y := elf.o gettimeofday.o sigreturn.o
4
5# Common compiler flags between ABIs.
6ccflags-vdso := \
7	$(filter -I%,$(KBUILD_CFLAGS)) \
8	$(filter -E%,$(KBUILD_CFLAGS)) \
9	$(filter -mmicromips,$(KBUILD_CFLAGS)) \
10	$(filter -march=%,$(KBUILD_CFLAGS)) \
11	$(filter -m%-float,$(KBUILD_CFLAGS)) \
12	-D__VDSO__
13
14ifdef CONFIG_CC_IS_CLANG
15ccflags-vdso += $(filter --target=%,$(KBUILD_CFLAGS))
16endif
17
18cflags-vdso := $(ccflags-vdso) \
19	$(filter -W%,$(filter-out -Wa$(comma)%,$(KBUILD_CFLAGS))) \
20	-O2 -g -fPIC -fno-strict-aliasing -fno-common -fno-builtin -G 0 \
21	-DDISABLE_BRANCH_PROFILING \
22	$(call cc-option, -fno-asynchronous-unwind-tables) \
23	$(call cc-option, -fno-stack-protector)
24aflags-vdso := $(ccflags-vdso) \
25	-D__ASSEMBLY__ -Wa,-gdwarf-2
26
27#
28# For the pre-R6 code in arch/mips/vdso/vdso.h for locating
29# the base address of VDSO, the linker will emit a R_MIPS_PC32
30# relocation in binutils > 2.25 but it will fail with older versions
31# because that relocation is not supported for that symbol. As a result
32# of which we are forced to disable the VDSO symbols when building
33# with < 2.25 binutils on pre-R6 kernels. For more references on why we
34# can't use other methods to get the base address of VDSO please refer to
35# the comments on that file.
36#
37ifndef CONFIG_CPU_MIPSR6
38  ifeq ($(call ld-ifversion, -lt, 225000000, y),y)
39    $(warning MIPS VDSO requires binutils >= 2.25)
40    obj-vdso-y := $(filter-out gettimeofday.o, $(obj-vdso-y))
41    ccflags-vdso += -DDISABLE_MIPS_VDSO
42  endif
43endif
44
45# VDSO linker flags.
46VDSO_LDFLAGS := \
47	-Wl,-Bsymbolic -Wl,--no-undefined -Wl,-soname=linux-vdso.so.1 \
48	$(addprefix -Wl$(comma),$(filter -E%,$(KBUILD_CFLAGS))) \
49	-nostdlib -shared \
50	$(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
51	$(call cc-ldoption, -Wl$(comma)--build-id)
52
53GCOV_PROFILE := n
54UBSAN_SANITIZE := n
55
56#
57# Shared build commands.
58#
59
60quiet_cmd_vdsold = VDSO    $@
61      cmd_vdsold = $(CC) $(c_flags) $(VDSO_LDFLAGS) \
62                   -Wl,-T $(filter %.lds,$^) $(filter %.o,$^) -o $@
63
64quiet_cmd_vdsoas_o_S = AS       $@
65      cmd_vdsoas_o_S = $(CC) $(a_flags) -c -o $@ $<
66
67# Strip rule for the raw .so files
68$(obj)/%.so.raw: OBJCOPYFLAGS := -S
69$(obj)/%.so.raw: $(obj)/%.so.dbg.raw FORCE
70	$(call if_changed,objcopy)
71
72hostprogs-y := genvdso
73
74quiet_cmd_genvdso = GENVDSO $@
75define cmd_genvdso
76	$(foreach file,$(filter %.raw,$^),cp $(file) $(file:%.raw=%) &&) \
77	$(obj)/genvdso $(<:%.raw=%) $(<:%.dbg.raw=%) $@ $(VDSO_NAME)
78endef
79
80#
81# Build native VDSO.
82#
83
84native-abi := $(filter -mabi=%,$(KBUILD_CFLAGS))
85
86targets += $(obj-vdso-y)
87targets += vdso.lds
88targets += vdso.so.dbg.raw vdso.so.raw
89targets += vdso.so.dbg vdso.so
90targets += vdso-image.c
91
92obj-vdso := $(obj-vdso-y:%.o=$(obj)/%.o)
93
94$(obj-vdso): KBUILD_CFLAGS := $(cflags-vdso) $(native-abi)
95$(obj-vdso): KBUILD_AFLAGS := $(aflags-vdso) $(native-abi)
96
97$(obj)/vdso.lds: KBUILD_CPPFLAGS := $(ccflags-vdso) $(native-abi)
98
99$(obj)/vdso.so.dbg.raw: $(obj)/vdso.lds $(obj-vdso) FORCE
100	$(call if_changed,vdsold)
101
102$(obj)/vdso-image.c: $(obj)/vdso.so.dbg.raw $(obj)/vdso.so.raw \
103                     $(obj)/genvdso FORCE
104	$(call if_changed,genvdso)
105
106obj-y += vdso-image.o
107
108#
109# Build O32 VDSO.
110#
111
112# Define these outside the ifdef to ensure they are picked up by clean.
113targets += $(obj-vdso-y:%.o=%-o32.o)
114targets += vdso-o32.lds
115targets += vdso-o32.so.dbg.raw vdso-o32.so.raw
116targets += vdso-o32.so.dbg vdso-o32.so
117targets += vdso-o32-image.c
118
119ifdef CONFIG_MIPS32_O32
120
121obj-vdso-o32 := $(obj-vdso-y:%.o=$(obj)/%-o32.o)
122
123$(obj-vdso-o32): KBUILD_CFLAGS := $(cflags-vdso) -mabi=32
124$(obj-vdso-o32): KBUILD_AFLAGS := $(aflags-vdso) -mabi=32
125
126$(obj)/%-o32.o: $(src)/%.S FORCE
127	$(call if_changed_dep,vdsoas_o_S)
128
129$(obj)/%-o32.o: $(src)/%.c FORCE
130	$(call cmd,force_checksrc)
131	$(call if_changed_rule,cc_o_c)
132
133$(obj)/vdso-o32.lds: KBUILD_CPPFLAGS := $(ccflags-vdso) -mabi=32
134$(obj)/vdso-o32.lds: $(src)/vdso.lds.S FORCE
135	$(call if_changed_dep,cpp_lds_S)
136
137$(obj)/vdso-o32.so.dbg.raw: $(obj)/vdso-o32.lds $(obj-vdso-o32) FORCE
138	$(call if_changed,vdsold)
139
140$(obj)/vdso-o32-image.c: VDSO_NAME := o32
141$(obj)/vdso-o32-image.c: $(obj)/vdso-o32.so.dbg.raw $(obj)/vdso-o32.so.raw \
142                         $(obj)/genvdso FORCE
143	$(call if_changed,genvdso)
144
145obj-y += vdso-o32-image.o
146
147endif
148
149#
150# Build N32 VDSO.
151#
152
153targets += $(obj-vdso-y:%.o=%-n32.o)
154targets += vdso-n32.lds
155targets += vdso-n32.so.dbg.raw vdso-n32.so.raw
156targets += vdso-n32.so.dbg vdso-n32.so
157targets += vdso-n32-image.c
158
159ifdef CONFIG_MIPS32_N32
160
161obj-vdso-n32 := $(obj-vdso-y:%.o=$(obj)/%-n32.o)
162
163$(obj-vdso-n32): KBUILD_CFLAGS := $(cflags-vdso) -mabi=n32
164$(obj-vdso-n32): KBUILD_AFLAGS := $(aflags-vdso) -mabi=n32
165
166$(obj)/%-n32.o: $(src)/%.S FORCE
167	$(call if_changed_dep,vdsoas_o_S)
168
169$(obj)/%-n32.o: $(src)/%.c FORCE
170	$(call cmd,force_checksrc)
171	$(call if_changed_rule,cc_o_c)
172
173$(obj)/vdso-n32.lds: KBUILD_CPPFLAGS := $(ccflags-vdso) -mabi=n32
174$(obj)/vdso-n32.lds: $(src)/vdso.lds.S FORCE
175	$(call if_changed_dep,cpp_lds_S)
176
177$(obj)/vdso-n32.so.dbg.raw: $(obj)/vdso-n32.lds $(obj-vdso-n32) FORCE
178	$(call if_changed,vdsold)
179
180$(obj)/vdso-n32-image.c: VDSO_NAME := n32
181$(obj)/vdso-n32-image.c: $(obj)/vdso-n32.so.dbg.raw $(obj)/vdso-n32.so.raw \
182                         $(obj)/genvdso FORCE
183	$(call if_changed,genvdso)
184
185obj-y += vdso-n32-image.o
186
187endif
188
189# FIXME: Need install rule for debug.
190# Needs to deal with dependency for generation of dbg by cmd_genvdso...
191