18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci# Objects to go into the VDSO.
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
58c2ecf20Sopenharmony_ci# the inclusion of generic Makefile.
68c2ecf20Sopenharmony_ciARCH_REL_TYPE_ABS := R_MIPS_JUMP_SLOT|R_MIPS_GLOB_DAT
78c2ecf20Sopenharmony_ciinclude $(srctree)/lib/vdso/Makefile
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ciobj-vdso-y := elf.o vgettimeofday.o sigreturn.o
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci# Common compiler flags between ABIs.
128c2ecf20Sopenharmony_ciccflags-vdso := \
138c2ecf20Sopenharmony_ci	$(filter -I%,$(KBUILD_CFLAGS)) \
148c2ecf20Sopenharmony_ci	$(filter -E%,$(KBUILD_CFLAGS)) \
158c2ecf20Sopenharmony_ci	$(filter -mmicromips,$(KBUILD_CFLAGS)) \
168c2ecf20Sopenharmony_ci	$(filter -march=%,$(KBUILD_CFLAGS)) \
178c2ecf20Sopenharmony_ci	$(filter -m%-float,$(KBUILD_CFLAGS)) \
188c2ecf20Sopenharmony_ci	$(filter -mno-loongson-%,$(KBUILD_CFLAGS)) \
198c2ecf20Sopenharmony_ci	$(CLANG_FLAGS) \
208c2ecf20Sopenharmony_ci	-D__VDSO__
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ciifndef CONFIG_64BIT
238c2ecf20Sopenharmony_ciccflags-vdso += -DBUILD_VDSO32
248c2ecf20Sopenharmony_ciendif
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#
278c2ecf20Sopenharmony_ci# The -fno-jump-tables flag only prevents the compiler from generating
288c2ecf20Sopenharmony_ci# jump tables but does not prevent the compiler from emitting absolute
298c2ecf20Sopenharmony_ci# offsets.
308c2ecf20Sopenharmony_cicflags-vdso := $(ccflags-vdso) \
318c2ecf20Sopenharmony_ci	$(filter -W%,$(filter-out -Wa$(comma)%,$(KBUILD_CFLAGS))) \
328c2ecf20Sopenharmony_ci	-O3 -g -fPIC -fno-strict-aliasing -fno-common -fno-builtin -G 0 \
338c2ecf20Sopenharmony_ci	-mrelax-pic-calls $(call cc-option, -mexplicit-relocs) \
348c2ecf20Sopenharmony_ci	-fno-stack-protector -fno-jump-tables -DDISABLE_BRANCH_PROFILING \
358c2ecf20Sopenharmony_ci	$(call cc-option, -fno-asynchronous-unwind-tables)
368c2ecf20Sopenharmony_ciaflags-vdso := $(ccflags-vdso) \
378c2ecf20Sopenharmony_ci	-D__ASSEMBLY__ -Wa,-gdwarf-2
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ciifneq ($(c-gettimeofday-y),)
408c2ecf20Sopenharmony_ciCFLAGS_vgettimeofday.o = -include $(c-gettimeofday-y)
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci# config-n32-o32-env.c prepares the environment to build a 32bit vDSO
438c2ecf20Sopenharmony_ci# library on a 64bit kernel.
448c2ecf20Sopenharmony_ci# Note: Needs to be included before than the generic library.
458c2ecf20Sopenharmony_ciCFLAGS_vgettimeofday-o32.o = -include $(srctree)/$(src)/config-n32-o32-env.c -include $(c-gettimeofday-y)
468c2ecf20Sopenharmony_ciCFLAGS_vgettimeofday-n32.o = -include $(srctree)/$(src)/config-n32-o32-env.c -include $(c-gettimeofday-y)
478c2ecf20Sopenharmony_ciendif
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ciCFLAGS_REMOVE_vgettimeofday.o = -pg
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ciifdef CONFIG_MIPS_DISABLE_VDSO
528c2ecf20Sopenharmony_ci  ifndef CONFIG_MIPS_LD_CAN_LINK_VDSO
538c2ecf20Sopenharmony_ci    $(warning MIPS VDSO requires binutils >= 2.25)
548c2ecf20Sopenharmony_ci  endif
558c2ecf20Sopenharmony_ci  obj-vdso-y := $(filter-out vgettimeofday.o, $(obj-vdso-y))
568c2ecf20Sopenharmony_ciendif
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci# VDSO linker flags.
598c2ecf20Sopenharmony_cildflags-y := -Bsymbolic --no-undefined -soname=linux-vdso.so.1 \
608c2ecf20Sopenharmony_ci	$(filter -E%,$(KBUILD_CFLAGS)) -nostdlib -shared \
618c2ecf20Sopenharmony_ci	-G 0 --eh-frame-hdr --hash-style=sysv --build-id=sha1 -T
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ciCFLAGS_REMOVE_vdso.o = -pg
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ciGCOV_PROFILE := n
668c2ecf20Sopenharmony_ciUBSAN_SANITIZE := n
678c2ecf20Sopenharmony_ciKCOV_INSTRUMENT := n
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci# Check that we don't have PIC 'jalr t9' calls left
708c2ecf20Sopenharmony_ciquiet_cmd_vdso_mips_check = VDSOCHK $@
718c2ecf20Sopenharmony_ci      cmd_vdso_mips_check = if $(OBJDUMP) --disassemble $@ | egrep -h "jalr.*t9" > /dev/null; \
728c2ecf20Sopenharmony_ci		       then (echo >&2 "$@: PIC 'jalr t9' calls are not supported"; \
738c2ecf20Sopenharmony_ci			     rm -f $@; /bin/false); fi
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci#
768c2ecf20Sopenharmony_ci# Shared build commands.
778c2ecf20Sopenharmony_ci#
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ciquiet_cmd_vdsold_and_vdso_check = LD      $@
808c2ecf20Sopenharmony_ci      cmd_vdsold_and_vdso_check = $(cmd_ld); $(cmd_vdso_check); $(cmd_vdso_mips_check)
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ciquiet_cmd_vdsoas_o_S = AS      $@
838c2ecf20Sopenharmony_ci      cmd_vdsoas_o_S = $(CC) $(a_flags) -c -o $@ $<
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci# Strip rule for the raw .so files
868c2ecf20Sopenharmony_ci$(obj)/%.so.raw: OBJCOPYFLAGS := -S
878c2ecf20Sopenharmony_ci$(obj)/%.so.raw: $(obj)/%.so.dbg.raw FORCE
888c2ecf20Sopenharmony_ci	$(call if_changed,objcopy)
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_cihostprogs := genvdso
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ciquiet_cmd_genvdso = GENVDSO $@
938c2ecf20Sopenharmony_cidefine cmd_genvdso
948c2ecf20Sopenharmony_ci	$(foreach file,$(filter %.raw,$^),cp $(file) $(file:%.raw=%) &&) \
958c2ecf20Sopenharmony_ci	$(obj)/genvdso $(<:%.raw=%) $(<:%.dbg.raw=%) $@ $(VDSO_NAME)
968c2ecf20Sopenharmony_ciendef
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci#
998c2ecf20Sopenharmony_ci# Build native VDSO.
1008c2ecf20Sopenharmony_ci#
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_cinative-abi := $(filter -mabi=%,$(KBUILD_CFLAGS))
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_citargets += $(obj-vdso-y)
1058c2ecf20Sopenharmony_citargets += vdso.lds
1068c2ecf20Sopenharmony_citargets += vdso.so.dbg.raw vdso.so.raw
1078c2ecf20Sopenharmony_citargets += vdso.so.dbg vdso.so
1088c2ecf20Sopenharmony_citargets += vdso-image.c
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ciobj-vdso := $(obj-vdso-y:%.o=$(obj)/%.o)
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci$(obj-vdso): KBUILD_CFLAGS := $(cflags-vdso) $(native-abi)
1138c2ecf20Sopenharmony_ci$(obj-vdso): KBUILD_AFLAGS := $(aflags-vdso) $(native-abi)
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci$(obj)/vdso.lds: KBUILD_CPPFLAGS := $(ccflags-vdso) $(native-abi)
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci$(obj)/vdso.so.dbg.raw: $(obj)/vdso.lds $(obj-vdso) FORCE
1188c2ecf20Sopenharmony_ci	$(call if_changed,vdsold_and_vdso_check)
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci$(obj)/vdso-image.c: $(obj)/vdso.so.dbg.raw $(obj)/vdso.so.raw \
1218c2ecf20Sopenharmony_ci                     $(obj)/genvdso FORCE
1228c2ecf20Sopenharmony_ci	$(call if_changed,genvdso)
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ciobj-y += vdso-image.o
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci#
1278c2ecf20Sopenharmony_ci# Build O32 VDSO.
1288c2ecf20Sopenharmony_ci#
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci# Define these outside the ifdef to ensure they are picked up by clean.
1318c2ecf20Sopenharmony_citargets += $(obj-vdso-y:%.o=%-o32.o)
1328c2ecf20Sopenharmony_citargets += vdso-o32.lds
1338c2ecf20Sopenharmony_citargets += vdso-o32.so.dbg.raw vdso-o32.so.raw
1348c2ecf20Sopenharmony_citargets += vdso-o32.so.dbg vdso-o32.so
1358c2ecf20Sopenharmony_citargets += vdso-o32-image.c
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ciifdef CONFIG_MIPS32_O32
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ciobj-vdso-o32 := $(obj-vdso-y:%.o=$(obj)/%-o32.o)
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci$(obj-vdso-o32): KBUILD_CFLAGS := $(cflags-vdso) -mabi=32
1428c2ecf20Sopenharmony_ci$(obj-vdso-o32): KBUILD_AFLAGS := $(aflags-vdso) -mabi=32
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci$(obj)/%-o32.o: $(src)/%.S FORCE
1458c2ecf20Sopenharmony_ci	$(call if_changed_dep,vdsoas_o_S)
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci$(obj)/%-o32.o: $(src)/%.c FORCE
1488c2ecf20Sopenharmony_ci	$(call cmd,force_checksrc)
1498c2ecf20Sopenharmony_ci	$(call if_changed_rule,cc_o_c)
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci$(obj)/vdso-o32.lds: KBUILD_CPPFLAGS := $(ccflags-vdso) -mabi=32
1528c2ecf20Sopenharmony_ci$(obj)/vdso-o32.lds: $(src)/vdso.lds.S FORCE
1538c2ecf20Sopenharmony_ci	$(call if_changed_dep,cpp_lds_S)
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci$(obj)/vdso-o32.so.dbg.raw: $(obj)/vdso-o32.lds $(obj-vdso-o32) FORCE
1568c2ecf20Sopenharmony_ci	$(call if_changed,vdsold_and_vdso_check)
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci$(obj)/vdso-o32-image.c: VDSO_NAME := o32
1598c2ecf20Sopenharmony_ci$(obj)/vdso-o32-image.c: $(obj)/vdso-o32.so.dbg.raw $(obj)/vdso-o32.so.raw \
1608c2ecf20Sopenharmony_ci                         $(obj)/genvdso FORCE
1618c2ecf20Sopenharmony_ci	$(call if_changed,genvdso)
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ciobj-y += vdso-o32-image.o
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ciendif
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci#
1688c2ecf20Sopenharmony_ci# Build N32 VDSO.
1698c2ecf20Sopenharmony_ci#
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_citargets += $(obj-vdso-y:%.o=%-n32.o)
1728c2ecf20Sopenharmony_citargets += vdso-n32.lds
1738c2ecf20Sopenharmony_citargets += vdso-n32.so.dbg.raw vdso-n32.so.raw
1748c2ecf20Sopenharmony_citargets += vdso-n32.so.dbg vdso-n32.so
1758c2ecf20Sopenharmony_citargets += vdso-n32-image.c
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ciifdef CONFIG_MIPS32_N32
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ciobj-vdso-n32 := $(obj-vdso-y:%.o=$(obj)/%-n32.o)
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci$(obj-vdso-n32): KBUILD_CFLAGS := $(cflags-vdso) -mabi=n32
1828c2ecf20Sopenharmony_ci$(obj-vdso-n32): KBUILD_AFLAGS := $(aflags-vdso) -mabi=n32
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci$(obj)/%-n32.o: $(src)/%.S FORCE
1858c2ecf20Sopenharmony_ci	$(call if_changed_dep,vdsoas_o_S)
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ci$(obj)/%-n32.o: $(src)/%.c FORCE
1888c2ecf20Sopenharmony_ci	$(call cmd,force_checksrc)
1898c2ecf20Sopenharmony_ci	$(call if_changed_rule,cc_o_c)
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci$(obj)/vdso-n32.lds: KBUILD_CPPFLAGS := $(ccflags-vdso) -mabi=n32
1928c2ecf20Sopenharmony_ci$(obj)/vdso-n32.lds: $(src)/vdso.lds.S FORCE
1938c2ecf20Sopenharmony_ci	$(call if_changed_dep,cpp_lds_S)
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci$(obj)/vdso-n32.so.dbg.raw: $(obj)/vdso-n32.lds $(obj-vdso-n32) FORCE
1968c2ecf20Sopenharmony_ci	$(call if_changed,vdsold_and_vdso_check)
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ci$(obj)/vdso-n32-image.c: VDSO_NAME := n32
1998c2ecf20Sopenharmony_ci$(obj)/vdso-n32-image.c: $(obj)/vdso-n32.so.dbg.raw $(obj)/vdso-n32.so.raw \
2008c2ecf20Sopenharmony_ci                         $(obj)/genvdso FORCE
2018c2ecf20Sopenharmony_ci	$(call if_changed,genvdso)
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ciobj-y += vdso-n32-image.o
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ciendif
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci# FIXME: Need install rule for debug.
2088c2ecf20Sopenharmony_ci# Needs to deal with dependency for generation of dbg by cmd_genvdso...
209