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