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