1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0 29031fefdSWill Deacon# 39031fefdSWill Deacon# Building a vDSO image for AArch64. 49031fefdSWill Deacon# 59031fefdSWill Deacon# Author: Will Deacon <will.deacon@arm.com> 69031fefdSWill Deacon# Heavily based on the vDSO Makefiles for other archs. 79031fefdSWill Deacon# 89031fefdSWill Deacon 9aff69273SFangrui Song# Include the generic Makefile to check the built vdso. 10*127b0e05SThomas Weißschuhinclude $(srctree)/lib/vdso/Makefile.include 1128b1a824SVincenzo Frascino 12712676eaSAdhemerval Zanellaobj-vdso := vgettimeofday.o note.o sigreturn.o vgetrandom.o vgetrandom-chacha.o 139031fefdSWill Deacon 149031fefdSWill Deacon# Build rules 159031fefdSWill Deacontargets := $(obj-vdso) vdso.so vdso.so.dbg 169031fefdSWill Deaconobj-vdso := $(addprefix $(obj)/, $(obj-vdso)) 179031fefdSWill Deacon 185e02a188SMark Brownbtildflags-$(CONFIG_ARM64_BTI_KERNEL) += -z force-bti 195e02a188SMark Brown 2086b87837SVincenzo Frascino# -Bsymbolic has been added for consistency with arm, the compat vDSO and 2186b87837SVincenzo Frascino# potential future proofing if we end up with internal calls to the exported 2286b87837SVincenzo Frascino# routines, as x86 does (see 6f121e548f83 ("x86, vdso: Reimplement vdso.so 2386b87837SVincenzo Frascino# preparation in build-time C")). 2448f64305SFangrui Songldflags-y := -shared -soname=linux-vdso.so.1 \ 25e0ab20b2SJoey Gouly -Bsymbolic --build-id=sha1 -n $(btildflags-y) 26e0ab20b2SJoey Gouly 27e0ab20b2SJoey Goulyifdef CONFIG_LD_ORPHAN_WARN 28e1789d7cSXin Li ldflags-y += --orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL) 29e0ab20b2SJoey Goulyendif 30e0ab20b2SJoey Gouly 31e0ab20b2SJoey Goulyldflags-y += -T 329031fefdSWill Deacon 3398cd3c3fSPeter Collingbourneccflags-y := -fno-common -fno-builtin -fno-stack-protector -ffixed-x18 34e35123d8SWill Deaconccflags-y += -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO 3528b1a824SVincenzo Frascino 3658cd4a08SVincenzo Frascino# -Wmissing-prototypes and -Wmissing-declarations are removed from 37712676eaSAdhemerval Zanella# the CFLAGS to make possible to build the kernel with CONFIG_WERROR enabled. 38712676eaSAdhemerval ZanellaCC_FLAGS_REMOVE_VDSO := $(CC_FLAGS_FTRACE) -Os $(CC_FLAGS_SCS) \ 39613f4b3eSKees Cook $(RANDSTRUCT_CFLAGS) $(GCC_PLUGINS_CFLAGS) \ 40f143ff39SSami Tolvanen $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) \ 41f143ff39SSami Tolvanen -Wmissing-prototypes -Wmissing-declarations 4228b1a824SVincenzo Frascino 43712676eaSAdhemerval ZanellaCC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables 44712676eaSAdhemerval Zanella 45712676eaSAdhemerval ZanellaCFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_REMOVE_VDSO) 46712676eaSAdhemerval ZanellaCFLAGS_REMOVE_vgetrandom.o = $(CC_FLAGS_REMOVE_VDSO) 47712676eaSAdhemerval Zanella 48712676eaSAdhemerval ZanellaCFLAGS_vgettimeofday.o = $(CC_FLAGS_ADD_VDSO) 49712676eaSAdhemerval ZanellaCFLAGS_vgetrandom.o = $(CC_FLAGS_ADD_VDSO) 50a88754b2SVincenzo Frascino 51a88754b2SVincenzo Frascinoifneq ($(c-gettimeofday-y),) 52a88754b2SVincenzo Frascino CFLAGS_vgettimeofday.o += -include $(c-gettimeofday-y) 5328b1a824SVincenzo Frascinoendif 5428b1a824SVincenzo Frascino 55712676eaSAdhemerval Zanellaifneq ($(c-getrandom-y),) 56712676eaSAdhemerval Zanella CFLAGS_vgetrandom.o += -include $(c-getrandom-y) 57712676eaSAdhemerval Zanellaendif 58712676eaSAdhemerval Zanella 59887af6d7SMasahiro Yamadatargets += vdso.lds 609031fefdSWill DeaconCPPFLAGS_vdso.lds += -P -C -U$(ARCH) 619031fefdSWill Deacon 629031fefdSWill Deacon# Link rule for the .so file, .lds has to be first 63697e96edSMasahiro Yamada$(obj)/vdso.so.dbg: $(obj)/vdso.lds $(obj-vdso) FORCE 642e2f3c9bSNaohiro Aota $(call if_changed,vdsold_and_vdso_check) 659031fefdSWill Deacon 669031fefdSWill Deacon# Strip rule for the .so file 679031fefdSWill Deacon$(obj)/%.so: OBJCOPYFLAGS := -S 689031fefdSWill Deacon$(obj)/%.so: $(obj)/%.so.dbg FORCE 699031fefdSWill Deacon $(call if_changed,objcopy) 709031fefdSWill Deacon 719031fefdSWill Deacon# Generate VDSO offsets using helper script 72b1992c37SMasahiro Yamadagen-vdsosym := $(src)/gen_vdso_offsets.sh 739031fefdSWill Deaconquiet_cmd_vdsosym = VDSOSYM $@ 74697e96edSMasahiro Yamada cmd_vdsosym = $(NM) $< | $(gen-vdsosym) | LC_ALL=C sort > $@ 759031fefdSWill Deacon 76a66649daSKevin Brodskyinclude/generated/vdso-offsets.h: $(obj)/vdso.so.dbg FORCE 779031fefdSWill Deacon $(call if_changed,vdsosym) 789031fefdSWill Deacon 799031fefdSWill Deacon# Actual build commands 802e2f3c9bSNaohiro Aotaquiet_cmd_vdsold_and_vdso_check = LD $@ 812e2f3c9bSNaohiro Aota cmd_vdsold_and_vdso_check = $(cmd_ld); $(cmd_vdso_check) 82