xref: /openbmc/linux/arch/mips/vdso/Makefile (revision 72cf3b3d)
1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
2ebb5e78cSAlex Smith# Objects to go into the VDSO.
324640f23SVincenzo Frascino
424640f23SVincenzo Frascino# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
524640f23SVincenzo Frascino# the inclusion of generic Makefile.
624640f23SVincenzo FrascinoARCH_REL_TYPE_ABS := R_MIPS_JUMP_SLOT|R_MIPS_GLOB_DAT
724640f23SVincenzo Frascinoinclude $(srctree)/lib/vdso/Makefile
824640f23SVincenzo Frascino
924640f23SVincenzo Frascinoobj-vdso-y := elf.o vgettimeofday.o sigreturn.o
10ebb5e78cSAlex Smith
11ebb5e78cSAlex Smith# Common compiler flags between ABIs.
12ebb5e78cSAlex Smithccflags-vdso := \
13ebb5e78cSAlex Smith	$(filter -I%,$(KBUILD_CFLAGS)) \
14ebb5e78cSAlex Smith	$(filter -E%,$(KBUILD_CFLAGS)) \
15bb93078eSJames Hogan	$(filter -mmicromips,$(KBUILD_CFLAGS)) \
16351fddddSPaul Burton	$(filter -march=%,$(KBUILD_CFLAGS)) \
170648e50eSPaul Burton	$(filter -m%-float,$(KBUILD_CFLAGS)) \
182f2b4fd6SPaul Burton	$(filter -mno-loongson-%,$(KBUILD_CFLAGS)) \
19351fddddSPaul Burton	-D__VDSO__
20ee67855eSPaul Burton
2199570c3dSThomas Gleixnerifndef CONFIG_64BIT
2299570c3dSThomas Gleixnerccflags-vdso += -DBUILD_VDSO32
2399570c3dSThomas Gleixnerendif
2499570c3dSThomas Gleixner
25076f421dSMasahiro Yamadaifdef CONFIG_CC_IS_CLANG
26ee67855eSPaul Burtonccflags-vdso += $(filter --target=%,$(KBUILD_CFLAGS))
27ee67855eSPaul Burtonendif
28ee67855eSPaul Burton
2924640f23SVincenzo Frascino#
3024640f23SVincenzo Frascino# The -fno-jump-tables flag only prevents the compiler from generating
3124640f23SVincenzo Frascino# jump tables but does not prevent the compiler from emitting absolute
3224640f23SVincenzo Frascino# offsets.
33ebb5e78cSAlex Smithcflags-vdso := $(ccflags-vdso) \
34ebb5e78cSAlex Smith	$(filter -W%,$(filter-out -Wa$(comma)%,$(KBUILD_CFLAGS))) \
3524640f23SVincenzo Frascino	-O3 -g -fPIC -fno-strict-aliasing -fno-common -fno-builtin -G 0 \
3672cf3b3dSNathan Chancellor	-mrelax-pic-calls $(call cc-option, -mexplicit-relocs) \
3724640f23SVincenzo Frascino	-fno-stack-protector -fno-jump-tables -DDISABLE_BRANCH_PROFILING \
38cfd75c2dSRobert Schiele	$(call cc-option, -fno-asynchronous-unwind-tables) \
39ebb5e78cSAlex Smith	$(call cc-option, -fno-stack-protector)
40ebb5e78cSAlex Smithaflags-vdso := $(ccflags-vdso) \
41ebb5e78cSAlex Smith	-D__ASSEMBLY__ -Wa,-gdwarf-2
42ebb5e78cSAlex Smith
4324640f23SVincenzo Frascinoifneq ($(c-gettimeofday-y),)
4424640f23SVincenzo FrascinoCFLAGS_vgettimeofday.o = -include $(c-gettimeofday-y)
4524640f23SVincenzo Frascino
4624640f23SVincenzo Frascino# config-n32-o32-env.c prepares the environment to build a 32bit vDSO
4724640f23SVincenzo Frascino# library on a 64bit kernel.
4824640f23SVincenzo Frascino# Note: Needs to be included before than the generic library.
49b4c0f7faSVincenzo FrascinoCFLAGS_vgettimeofday-o32.o = -include $(srctree)/$(src)/config-n32-o32-env.c -include $(c-gettimeofday-y)
50b4c0f7faSVincenzo FrascinoCFLAGS_vgettimeofday-n32.o = -include $(srctree)/$(src)/config-n32-o32-env.c -include $(c-gettimeofday-y)
5124640f23SVincenzo Frascinoendif
5224640f23SVincenzo Frascino
5324640f23SVincenzo FrascinoCFLAGS_REMOVE_vgettimeofday.o = -pg
5424640f23SVincenzo Frascino
5507015d7aSPaul BurtonDISABLE_VDSO := n
5607015d7aSPaul Burton
57ebb5e78cSAlex Smith#
58ebb5e78cSAlex Smith# For the pre-R6 code in arch/mips/vdso/vdso.h for locating
59ebb5e78cSAlex Smith# the base address of VDSO, the linker will emit a R_MIPS_PC32
60ebb5e78cSAlex Smith# relocation in binutils > 2.25 but it will fail with older versions
61ebb5e78cSAlex Smith# because that relocation is not supported for that symbol. As a result
62ebb5e78cSAlex Smith# of which we are forced to disable the VDSO symbols when building
63ebb5e78cSAlex Smith# with < 2.25 binutils on pre-R6 kernels. For more references on why we
64ebb5e78cSAlex Smith# can't use other methods to get the base address of VDSO please refer to
65ebb5e78cSAlex Smith# the comments on that file.
66ebb5e78cSAlex Smith#
67ebb5e78cSAlex Smithifndef CONFIG_CPU_MIPSR6
68d5ece1cbSJames Hogan  ifeq ($(call ld-ifversion, -lt, 225000000, y),y)
692a037f31SQais Yousef    $(warning MIPS VDSO requires binutils >= 2.25)
7007015d7aSPaul Burton    DISABLE_VDSO := y
7107015d7aSPaul Burton  endif
7207015d7aSPaul Burtonendif
7307015d7aSPaul Burton
7407015d7aSPaul Burton#
7507015d7aSPaul Burton# GCC (at least up to version 9.2) appears to emit function calls that make use
7607015d7aSPaul Burton# of the GOT when targeting microMIPS, which we can't use in the VDSO due to
7707015d7aSPaul Burton# the lack of relocations. As such, we disable the VDSO for microMIPS builds.
7807015d7aSPaul Burton#
7907015d7aSPaul Burtonifdef CONFIG_CPU_MICROMIPS
8007015d7aSPaul Burton  DISABLE_VDSO := y
8107015d7aSPaul Burtonendif
8207015d7aSPaul Burton
8307015d7aSPaul Burtonifeq ($(DISABLE_VDSO),y)
848919975bSPaul Burton  obj-vdso-y := $(filter-out vgettimeofday.o, $(obj-vdso-y))
85ebb5e78cSAlex Smith  ccflags-vdso += -DDISABLE_MIPS_VDSO
86ebb5e78cSAlex Smithendif
87ebb5e78cSAlex Smith
88ebb5e78cSAlex Smith# VDSO linker flags.
89ebb5e78cSAlex SmithVDSO_LDFLAGS := \
90ebb5e78cSAlex Smith	-Wl,-Bsymbolic -Wl,--no-undefined -Wl,-soname=linux-vdso.so.1 \
912f002567SPaul Burton	$(addprefix -Wl$(comma),$(filter -E%,$(KBUILD_CFLAGS))) \
921e022137SNick Desaulniers	-nostdlib -shared -Wl,--hash-style=sysv -Wl,--build-id
93ebb5e78cSAlex Smith
9424640f23SVincenzo FrascinoCFLAGS_REMOVE_vdso.o = -pg
9524640f23SVincenzo Frascino
96ebb5e78cSAlex SmithGCOV_PROFILE := n
971e35918aSHassan NaveedUBSAN_SANITIZE := n
98dcf78ee6SAlexey KhoroshilovKCOV_INSTRUMENT := n
99ebb5e78cSAlex Smith
100976c23afSVictor Kamensky# Check that we don't have PIC 'jalr t9' calls left
101976c23afSVictor Kamenskyquiet_cmd_vdso_mips_check = VDSOCHK $@
102976c23afSVictor Kamensky      cmd_vdso_mips_check = if $(OBJDUMP) --disassemble $@ | egrep -h "jalr.*t9" > /dev/null; \
103976c23afSVictor Kamensky		       then (echo >&2 "$@: PIC 'jalr t9' calls are not supported"; \
104976c23afSVictor Kamensky			     rm -f $@; /bin/false); fi
105976c23afSVictor Kamensky
106ebb5e78cSAlex Smith#
107ebb5e78cSAlex Smith# Shared build commands.
108ebb5e78cSAlex Smith#
109ebb5e78cSAlex Smith
110cdab7e2cSVincenzo Frascinoquiet_cmd_vdsold_and_vdso_check = LD      $@
111976c23afSVictor Kamensky      cmd_vdsold_and_vdso_check = $(cmd_vdsold); $(cmd_vdso_check); $(cmd_vdso_mips_check)
112cdab7e2cSVincenzo Frascino
113ebb5e78cSAlex Smithquiet_cmd_vdsold = VDSO    $@
114ebb5e78cSAlex Smith      cmd_vdsold = $(CC) $(c_flags) $(VDSO_LDFLAGS) \
115ebb5e78cSAlex Smith                   -Wl,-T $(filter %.lds,$^) $(filter %.o,$^) -o $@
116ebb5e78cSAlex Smith
117b668970eSArnd Bergmannquiet_cmd_vdsoas_o_S = AS      $@
118b668970eSArnd Bergmann      cmd_vdsoas_o_S = $(CC) $(a_flags) -c -o $@ $<
119b668970eSArnd Bergmann
1202afb9745SJames Hogan# Strip rule for the raw .so files
1212afb9745SJames Hogan$(obj)/%.so.raw: OBJCOPYFLAGS := -S
1222afb9745SJames Hogan$(obj)/%.so.raw: $(obj)/%.so.dbg.raw FORCE
1232afb9745SJames Hogan	$(call if_changed,objcopy)
1242afb9745SJames Hogan
1255f2fb52fSMasahiro Yamadahostprogs := genvdso
126ebb5e78cSAlex Smith
127ebb5e78cSAlex Smithquiet_cmd_genvdso = GENVDSO $@
128ebb5e78cSAlex Smithdefine cmd_genvdso
1292afb9745SJames Hogan	$(foreach file,$(filter %.raw,$^),cp $(file) $(file:%.raw=%) &&) \
1302afb9745SJames Hogan	$(obj)/genvdso $(<:%.raw=%) $(<:%.dbg.raw=%) $@ $(VDSO_NAME)
131ebb5e78cSAlex Smithendef
132ebb5e78cSAlex Smith
133ebb5e78cSAlex Smith#
134ebb5e78cSAlex Smith# Build native VDSO.
135ebb5e78cSAlex Smith#
136ebb5e78cSAlex Smith
137ebb5e78cSAlex Smithnative-abi := $(filter -mabi=%,$(KBUILD_CFLAGS))
138ebb5e78cSAlex Smith
139ebb5e78cSAlex Smithtargets += $(obj-vdso-y)
1402afb9745SJames Hogantargets += vdso.lds
1412afb9745SJames Hogantargets += vdso.so.dbg.raw vdso.so.raw
1422afb9745SJames Hogantargets += vdso.so.dbg vdso.so
1432afb9745SJames Hogantargets += vdso-image.c
144ebb5e78cSAlex Smith
145ebb5e78cSAlex Smithobj-vdso := $(obj-vdso-y:%.o=$(obj)/%.o)
146ebb5e78cSAlex Smith
147ebb5e78cSAlex Smith$(obj-vdso): KBUILD_CFLAGS := $(cflags-vdso) $(native-abi)
148ebb5e78cSAlex Smith$(obj-vdso): KBUILD_AFLAGS := $(aflags-vdso) $(native-abi)
149ebb5e78cSAlex Smith
150034827c7SJames Hogan$(obj)/vdso.lds: KBUILD_CPPFLAGS := $(ccflags-vdso) $(native-abi)
151ebb5e78cSAlex Smith
1522afb9745SJames Hogan$(obj)/vdso.so.dbg.raw: $(obj)/vdso.lds $(obj-vdso) FORCE
153cdab7e2cSVincenzo Frascino	$(call if_changed,vdsold_and_vdso_check)
154ebb5e78cSAlex Smith
1552afb9745SJames Hogan$(obj)/vdso-image.c: $(obj)/vdso.so.dbg.raw $(obj)/vdso.so.raw \
1562afb9745SJames Hogan                     $(obj)/genvdso FORCE
157ebb5e78cSAlex Smith	$(call if_changed,genvdso)
158ebb5e78cSAlex Smith
159ebb5e78cSAlex Smithobj-y += vdso-image.o
160ebb5e78cSAlex Smith
161ebb5e78cSAlex Smith#
162ebb5e78cSAlex Smith# Build O32 VDSO.
163ebb5e78cSAlex Smith#
164ebb5e78cSAlex Smith
165ebb5e78cSAlex Smith# Define these outside the ifdef to ensure they are picked up by clean.
166ebb5e78cSAlex Smithtargets += $(obj-vdso-y:%.o=%-o32.o)
1672afb9745SJames Hogantargets += vdso-o32.lds
1682afb9745SJames Hogantargets += vdso-o32.so.dbg.raw vdso-o32.so.raw
1692afb9745SJames Hogantargets += vdso-o32.so.dbg vdso-o32.so
1702afb9745SJames Hogantargets += vdso-o32-image.c
171ebb5e78cSAlex Smith
172ebb5e78cSAlex Smithifdef CONFIG_MIPS32_O32
173ebb5e78cSAlex Smith
174ebb5e78cSAlex Smithobj-vdso-o32 := $(obj-vdso-y:%.o=$(obj)/%-o32.o)
175ebb5e78cSAlex Smith
176ebb5e78cSAlex Smith$(obj-vdso-o32): KBUILD_CFLAGS := $(cflags-vdso) -mabi=32
177ebb5e78cSAlex Smith$(obj-vdso-o32): KBUILD_AFLAGS := $(aflags-vdso) -mabi=32
178ebb5e78cSAlex Smith
179ebb5e78cSAlex Smith$(obj)/%-o32.o: $(src)/%.S FORCE
180b668970eSArnd Bergmann	$(call if_changed_dep,vdsoas_o_S)
181ebb5e78cSAlex Smith
182ebb5e78cSAlex Smith$(obj)/%-o32.o: $(src)/%.c FORCE
183ebb5e78cSAlex Smith	$(call cmd,force_checksrc)
184ebb5e78cSAlex Smith	$(call if_changed_rule,cc_o_c)
185ebb5e78cSAlex Smith
18667fc5dc8SPaul Burton$(obj)/vdso-o32.lds: KBUILD_CPPFLAGS := $(ccflags-vdso) -mabi=32
187ebb5e78cSAlex Smith$(obj)/vdso-o32.lds: $(src)/vdso.lds.S FORCE
188ebb5e78cSAlex Smith	$(call if_changed_dep,cpp_lds_S)
189ebb5e78cSAlex Smith
1902afb9745SJames Hogan$(obj)/vdso-o32.so.dbg.raw: $(obj)/vdso-o32.lds $(obj-vdso-o32) FORCE
191cdab7e2cSVincenzo Frascino	$(call if_changed,vdsold_and_vdso_check)
192ebb5e78cSAlex Smith
193ebb5e78cSAlex Smith$(obj)/vdso-o32-image.c: VDSO_NAME := o32
1942afb9745SJames Hogan$(obj)/vdso-o32-image.c: $(obj)/vdso-o32.so.dbg.raw $(obj)/vdso-o32.so.raw \
1952afb9745SJames Hogan                         $(obj)/genvdso FORCE
196ebb5e78cSAlex Smith	$(call if_changed,genvdso)
197ebb5e78cSAlex Smith
198ebb5e78cSAlex Smithobj-y += vdso-o32-image.o
199ebb5e78cSAlex Smith
200ebb5e78cSAlex Smithendif
201ebb5e78cSAlex Smith
202ebb5e78cSAlex Smith#
203ebb5e78cSAlex Smith# Build N32 VDSO.
204ebb5e78cSAlex Smith#
205ebb5e78cSAlex Smith
206ebb5e78cSAlex Smithtargets += $(obj-vdso-y:%.o=%-n32.o)
2072afb9745SJames Hogantargets += vdso-n32.lds
2082afb9745SJames Hogantargets += vdso-n32.so.dbg.raw vdso-n32.so.raw
2092afb9745SJames Hogantargets += vdso-n32.so.dbg vdso-n32.so
2102afb9745SJames Hogantargets += vdso-n32-image.c
211ebb5e78cSAlex Smith
212ebb5e78cSAlex Smithifdef CONFIG_MIPS32_N32
213ebb5e78cSAlex Smith
214ebb5e78cSAlex Smithobj-vdso-n32 := $(obj-vdso-y:%.o=$(obj)/%-n32.o)
215ebb5e78cSAlex Smith
216ebb5e78cSAlex Smith$(obj-vdso-n32): KBUILD_CFLAGS := $(cflags-vdso) -mabi=n32
217ebb5e78cSAlex Smith$(obj-vdso-n32): KBUILD_AFLAGS := $(aflags-vdso) -mabi=n32
218ebb5e78cSAlex Smith
219ebb5e78cSAlex Smith$(obj)/%-n32.o: $(src)/%.S FORCE
220b668970eSArnd Bergmann	$(call if_changed_dep,vdsoas_o_S)
221ebb5e78cSAlex Smith
222ebb5e78cSAlex Smith$(obj)/%-n32.o: $(src)/%.c FORCE
223ebb5e78cSAlex Smith	$(call cmd,force_checksrc)
224ebb5e78cSAlex Smith	$(call if_changed_rule,cc_o_c)
225ebb5e78cSAlex Smith
22667fc5dc8SPaul Burton$(obj)/vdso-n32.lds: KBUILD_CPPFLAGS := $(ccflags-vdso) -mabi=n32
227ebb5e78cSAlex Smith$(obj)/vdso-n32.lds: $(src)/vdso.lds.S FORCE
228ebb5e78cSAlex Smith	$(call if_changed_dep,cpp_lds_S)
229ebb5e78cSAlex Smith
2302afb9745SJames Hogan$(obj)/vdso-n32.so.dbg.raw: $(obj)/vdso-n32.lds $(obj-vdso-n32) FORCE
231cdab7e2cSVincenzo Frascino	$(call if_changed,vdsold_and_vdso_check)
232ebb5e78cSAlex Smith
233ebb5e78cSAlex Smith$(obj)/vdso-n32-image.c: VDSO_NAME := n32
2342afb9745SJames Hogan$(obj)/vdso-n32-image.c: $(obj)/vdso-n32.so.dbg.raw $(obj)/vdso-n32.so.raw \
2352afb9745SJames Hogan                         $(obj)/genvdso FORCE
236ebb5e78cSAlex Smith	$(call if_changed,genvdso)
237ebb5e78cSAlex Smith
238ebb5e78cSAlex Smithobj-y += vdso-n32-image.o
239ebb5e78cSAlex Smith
240ebb5e78cSAlex Smithendif
241ebb5e78cSAlex Smith
242ebb5e78cSAlex Smith# FIXME: Need install rule for debug.
243ebb5e78cSAlex Smith# Needs to deal with dependency for generation of dbg by cmd_genvdso...
244