1fd1feadeSChristophe Leroy# SPDX-License-Identifier: GPL-2.0 2fd1feadeSChristophe Leroy 3fd1feadeSChristophe Leroy# List of files in the vdso, has to be asm only for now 4fd1feadeSChristophe Leroy 5aff69273SFangrui Song# Include the generic Makefile to check the built vdso. 6127b0e05SThomas Weißschuhinclude $(srctree)/lib/vdso/Makefile.include 7fd1feadeSChristophe Leroy 8fd1feadeSChristophe Leroyobj-vdso32 = sigtramp32-32.o gettimeofday-32.o datapage-32.o cacheflush-32.o note-32.o getcpu-32.o 9fd1feadeSChristophe Leroyobj-vdso64 = sigtramp64-64.o gettimeofday-64.o datapage-64.o cacheflush-64.o note-64.o getcpu-64.o 10fd1feadeSChristophe Leroy 1153cee505SChristophe Leroyobj-vdso32 += getrandom-32.o vgetrandom-chacha-32.o 128072b39cSChristophe Leroyobj-vdso64 += getrandom-64.o vgetrandom-chacha-64.o 1353cee505SChristophe Leroy 14fd1feadeSChristophe Leroyifneq ($(c-gettimeofday-y),) 15fd1feadeSChristophe Leroy CFLAGS_vgettimeofday-32.o += -include $(c-gettimeofday-y) 16fd1feadeSChristophe Leroy# Go prior to 1.16.x assumes r30 is not clobbered by any VDSO code. That used to be true 17fd1feadeSChristophe Leroy# by accident when the VDSO was hand-written asm code, but may not be now that the VDSO is 18fd1feadeSChristophe Leroy# compiler generated. To avoid breaking Go tell GCC not to use r30. Impact on code 19fd1feadeSChristophe Leroy# generation is minimal, it will just use r29 instead. 20a6b67eb0SChristophe Leroy CFLAGS_vgettimeofday-64.o += -include $(c-gettimeofday-y) $(call cc-option, -ffixed-r30) 21fd1feadeSChristophe Leroyendif 22fd1feadeSChristophe Leroy 2353cee505SChristophe Leroyifneq ($(c-getrandom-y),) 2453cee505SChristophe Leroy CFLAGS_vgetrandom-32.o += -include $(c-getrandom-y) 254b058c9fSJason A. Donenfeld CFLAGS_vgetrandom-64.o += -include $(c-getrandom-y) 2653cee505SChristophe Leroyendif 2753cee505SChristophe Leroy 28fd1feadeSChristophe Leroy# Build rules 29fd1feadeSChristophe Leroy 30fd1feadeSChristophe Leroyifdef CROSS32_COMPILE 31fd1feadeSChristophe Leroy VDSOCC := $(CROSS32_COMPILE)gcc 32fd1feadeSChristophe Leroyelse 33fd1feadeSChristophe Leroy VDSOCC := $(CC) 34fd1feadeSChristophe Leroyendif 35fd1feadeSChristophe Leroy 3653cee505SChristophe Leroytargets := $(obj-vdso32) vdso32.so.dbg vgettimeofday-32.o vgetrandom-32.o 37b163596aSChristophe Leroytargets += crtsavres-32.o 38fd1feadeSChristophe Leroyobj-vdso32 := $(addprefix $(obj)/, $(obj-vdso32)) 398072b39cSChristophe Leroytargets += $(obj-vdso64) vdso64.so.dbg vgettimeofday-64.o vgetrandom-64.o 40fd1feadeSChristophe Leroyobj-vdso64 := $(addprefix $(obj)/, $(obj-vdso64)) 41fd1feadeSChristophe Leroy 4253cee505SChristophe Leroyccflags-y := -fno-common -fno-builtin -DBUILD_VDSO 43a6b67eb0SChristophe Leroyccflags-y += $(DISABLE_LATENT_ENTROPY_PLUGIN) 44a6b67eb0SChristophe Leroyccflags-y += $(call cc-option, -fno-stack-protector) 45a6b67eb0SChristophe Leroyccflags-y += -DDISABLE_BRANCH_PROFILING 46a6b67eb0SChristophe Leroyccflags-y += -ffreestanding -fasynchronous-unwind-tables 47a6b67eb0SChristophe Leroyccflags-remove-y := $(CC_FLAGS_FTRACE) 48a7e5eb53SNathan Chancellorldflags-y := -Wl,--hash-style=both -nostdlib -shared -z noexecstack $(CLANG_FLAGS) 49f0a42fbaSNathan Chancellorldflags-$(CONFIG_LD_IS_LLD) += $(call cc-option,--ld-path=$(LD),-fuse-ld=lld) 508ad57addSNicholas Pigginldflags-$(CONFIG_LD_ORPHAN_WARN) += -Wl,--orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL) 518ad57addSNicholas Piggin 52f0a42fbaSNathan Chancellor# Filter flags that clang will warn are unused for linking 53a5371018SArnd Bergmannldflags-y += $(filter-out $(CC_AUTO_VAR_INIT_ZERO_ENABLER) $(CC_FLAGS_FTRACE) -Wa$(comma)%, $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS)) 54fd1feadeSChristophe Leroy 55f0a42fbaSNathan ChancellorCC32FLAGS := -m32 56*b93755f4SChristophe LeroyCC32FLAGSREMOVE := -mcmodel=medium -mabi=elfv1 -mabi=elfv2 -mcall-aixdesc -mpcrel 57d677ce52SNathan Chancellorifdef CONFIG_CC_IS_CLANG 58a6b67eb0SChristophe Leroy# This flag is supported by clang for 64-bit but not 32-bit so it will cause 59a6b67eb0SChristophe Leroy# an unused command line flag warning for this file. 60a6b67eb0SChristophe LeroyCC32FLAGSREMOVE += -fno-stack-clash-protection 61d677ce52SNathan Chancellor# -mstack-protector-guard values from the 64-bit build are not valid for the 62d677ce52SNathan Chancellor# 32-bit one. clang validates the values passed to these arguments during 63d677ce52SNathan Chancellor# parsing, even when -fno-stack-protector is passed afterwards. 64d677ce52SNathan ChancellorCC32FLAGSREMOVE += -mstack-protector-guard% 65a6b67eb0SChristophe Leroyendif 66f0a42fbaSNathan ChancellorLD32FLAGS := -Wl,-soname=linux-vdso32.so.1 67024734d1SNathan ChancellorAS32FLAGS := -D__VDSO32__ 68fd1feadeSChristophe Leroy 69f0a42fbaSNathan ChancellorLD64FLAGS := -Wl,-soname=linux-vdso64.so.1 70024734d1SNathan ChancellorAS64FLAGS := -D__VDSO64__ 71fd1feadeSChristophe Leroy 72fd1feadeSChristophe Leroytargets += vdso32.lds 73fd1feadeSChristophe LeroyCPPFLAGS_vdso32.lds += -P -C -Upowerpc 74fd1feadeSChristophe Leroytargets += vdso64.lds 7542449052SMichael EllermanCPPFLAGS_vdso64.lds += -P -C 76fd1feadeSChristophe Leroy 77fd1feadeSChristophe Leroy# link rule for the .so file, .lds has to be first 7853cee505SChristophe Leroy$(obj)/vdso32.so.dbg: $(obj)/vdso32.lds $(obj-vdso32) $(obj)/vgettimeofday-32.o $(obj)/vgetrandom-32.o $(obj)/crtsavres-32.o FORCE 79fd1feadeSChristophe Leroy $(call if_changed,vdso32ld_and_check) 808072b39cSChristophe Leroy$(obj)/vdso64.so.dbg: $(obj)/vdso64.lds $(obj-vdso64) $(obj)/vgettimeofday-64.o $(obj)/vgetrandom-64.o FORCE 81fd1feadeSChristophe Leroy $(call if_changed,vdso64ld_and_check) 82fd1feadeSChristophe Leroy 83fd1feadeSChristophe Leroy# assembly rules for the .S files 84fd1feadeSChristophe Leroy$(obj-vdso32): %-32.o: %.S FORCE 85fd1feadeSChristophe Leroy $(call if_changed_dep,vdso32as) 86b163596aSChristophe Leroy$(obj)/crtsavres-32.o: %-32.o: $(srctree)/arch/powerpc/lib/crtsavres.S FORCE 87b163596aSChristophe Leroy $(call if_changed_dep,vdso32as) 88fd1feadeSChristophe Leroy$(obj)/vgettimeofday-32.o: %-32.o: %.c FORCE 89fd1feadeSChristophe Leroy $(call if_changed_dep,vdso32cc) 9053cee505SChristophe Leroy$(obj)/vgetrandom-32.o: %-32.o: %.c FORCE 9153cee505SChristophe Leroy $(call if_changed_dep,vdso32cc) 92fd1feadeSChristophe Leroy$(obj-vdso64): %-64.o: %.S FORCE 93fd1feadeSChristophe Leroy $(call if_changed_dep,vdso64as) 94fd1feadeSChristophe Leroy$(obj)/vgettimeofday-64.o: %-64.o: %.c FORCE 95fd1feadeSChristophe Leroy $(call if_changed_dep,cc_o_c) 968072b39cSChristophe Leroy$(obj)/vgetrandom-64.o: %-64.o: %.c FORCE 978072b39cSChristophe Leroy $(call if_changed_dep,cc_o_c) 98fd1feadeSChristophe Leroy 99fd1feadeSChristophe Leroy# Generate VDSO offsets using helper script 100b1992c37SMasahiro Yamadagen-vdso32sym := $(src)/gen_vdso32_offsets.sh 101fd1feadeSChristophe Leroyquiet_cmd_vdso32sym = VDSO32SYM $@ 102fd1feadeSChristophe Leroy cmd_vdso32sym = $(NM) $< | $(gen-vdso32sym) | LC_ALL=C sort > $@ 103b1992c37SMasahiro Yamadagen-vdso64sym := $(src)/gen_vdso64_offsets.sh 104fd1feadeSChristophe Leroyquiet_cmd_vdso64sym = VDSO64SYM $@ 105fd1feadeSChristophe Leroy cmd_vdso64sym = $(NM) $< | $(gen-vdso64sym) | LC_ALL=C sort > $@ 106fd1feadeSChristophe Leroy 107fd1feadeSChristophe Leroyinclude/generated/vdso32-offsets.h: $(obj)/vdso32.so.dbg FORCE 108fd1feadeSChristophe Leroy $(call if_changed,vdso32sym) 109fd1feadeSChristophe Leroyinclude/generated/vdso64-offsets.h: $(obj)/vdso64.so.dbg FORCE 110fd1feadeSChristophe Leroy $(call if_changed,vdso64sym) 111fd1feadeSChristophe Leroy 112fd1feadeSChristophe Leroy# actual build commands 113fd1feadeSChristophe Leroyquiet_cmd_vdso32ld_and_check = VDSO32L $@ 114f0a42fbaSNathan Chancellor cmd_vdso32ld_and_check = $(VDSOCC) $(ldflags-y) $(CC32FLAGS) $(LD32FLAGS) -o $@ -Wl,-T$(filter %.lds,$^) $(filter %.o,$^); $(cmd_vdso_check) 115fd1feadeSChristophe Leroyquiet_cmd_vdso32as = VDSO32A $@ 116fd1feadeSChristophe Leroy cmd_vdso32as = $(VDSOCC) $(a_flags) $(CC32FLAGS) $(AS32FLAGS) -c -o $@ $< 117fd1feadeSChristophe Leroyquiet_cmd_vdso32cc = VDSO32C $@ 118a6b67eb0SChristophe Leroy cmd_vdso32cc = $(VDSOCC) $(filter-out $(CC32FLAGSREMOVE), $(c_flags)) $(CC32FLAGS) -c -o $@ $< 119fd1feadeSChristophe Leroy 120fd1feadeSChristophe Leroyquiet_cmd_vdso64ld_and_check = VDSO64L $@ 121f0a42fbaSNathan Chancellor cmd_vdso64ld_and_check = $(VDSOCC) $(ldflags-y) $(LD64FLAGS) -o $@ -Wl,-T$(filter %.lds,$^) $(filter %.o,$^); $(cmd_vdso_check) 122fd1feadeSChristophe Leroyquiet_cmd_vdso64as = VDSO64A $@ 123f0a42fbaSNathan Chancellor cmd_vdso64as = $(VDSOCC) $(a_flags) $(AS64FLAGS) -c -o $@ $< 124