1# SPDX-License-Identifier: GPL-2.0
2#
3# Building a vDSO image for AArch64.
4#
5# Author: Will Deacon <will.deacon@arm.com>
6# Heavily based on the vDSO Makefiles for other archs.
7#
8
9# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
10# the inclusion of generic Makefile.
11ARCH_REL_TYPE_ABS := R_AARCH64_JUMP_SLOT|R_AARCH64_GLOB_DAT|R_AARCH64_ABS64
12include $(srctree)/lib/vdso/Makefile
13
14obj-vdso := vgettimeofday.o note.o sigreturn.o
15
16# Build rules
17targets := $(obj-vdso) vdso.so vdso.so.dbg
18obj-vdso := $(addprefix $(obj)/, $(obj-vdso))
19
20btildflags-$(CONFIG_ARM64_BTI_KERNEL) += -z force-bti
21
22# -Bsymbolic has been added for consistency with arm, the compat vDSO and
23# potential future proofing if we end up with internal calls to the exported
24# routines, as x86 does (see 6f121e548f83 ("x86, vdso: Reimplement vdso.so
25# preparation in build-time C")).
26ldflags-y := -shared -soname=linux-vdso.so.1 --hash-style=sysv	\
27	     -Bsymbolic --build-id=sha1 -n $(btildflags-y)
28
29ifdef CONFIG_LD_ORPHAN_WARN
30  ldflags-y += --orphan-handling=warn
31endif
32
33ldflags-y += -T
34
35ccflags-y := -fno-common -fno-builtin -fno-stack-protector -ffixed-x18
36ccflags-y += -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO
37
38# -Wmissing-prototypes and -Wmissing-declarations are removed from
39# the CFLAGS of vgettimeofday.c to make possible to build the
40# kernel with CONFIG_WERROR enabled.
41CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE) -Os $(CC_FLAGS_SCS) \
42				$(RANDSTRUCT_CFLAGS) $(GCC_PLUGINS_CFLAGS) \
43				$(CC_FLAGS_LTO) $(CC_FLAGS_CFI) \
44				-Wmissing-prototypes -Wmissing-declarations
45KASAN_SANITIZE			:= n
46KCSAN_SANITIZE			:= n
47UBSAN_SANITIZE			:= n
48OBJECT_FILES_NON_STANDARD	:= y
49KCOV_INSTRUMENT			:= n
50
51CFLAGS_vgettimeofday.o = -O2 -mcmodel=tiny -fasynchronous-unwind-tables
52
53ifneq ($(c-gettimeofday-y),)
54  CFLAGS_vgettimeofday.o += -include $(c-gettimeofday-y)
55endif
56
57# Disable gcov profiling for VDSO code
58GCOV_PROFILE := n
59
60targets += vdso.lds
61CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
62
63# Link rule for the .so file, .lds has to be first
64$(obj)/vdso.so.dbg: $(obj)/vdso.lds $(obj-vdso) FORCE
65	$(call if_changed,vdsold_and_vdso_check)
66
67# Strip rule for the .so file
68$(obj)/%.so: OBJCOPYFLAGS := -S
69$(obj)/%.so: $(obj)/%.so.dbg FORCE
70	$(call if_changed,objcopy)
71
72# Generate VDSO offsets using helper script
73gen-vdsosym := $(srctree)/$(src)/gen_vdso_offsets.sh
74quiet_cmd_vdsosym = VDSOSYM $@
75      cmd_vdsosym = $(NM) $< | $(gen-vdsosym) | LC_ALL=C sort > $@
76
77include/generated/vdso-offsets.h: $(obj)/vdso.so.dbg FORCE
78	$(call if_changed,vdsosym)
79
80# Actual build commands
81quiet_cmd_vdsold_and_vdso_check = LD      $@
82      cmd_vdsold_and_vdso_check = $(cmd_ld); $(cmd_vdso_check)
83
84# Install commands for the unstripped file
85quiet_cmd_vdso_install = INSTALL $@
86      cmd_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/vdso/$@
87
88vdso.so: $(obj)/vdso.so.dbg
89	@mkdir -p $(MODLIB)/vdso
90	$(call cmd,vdso_install)
91
92vdso_install: vdso.so
93