xref: /openbmc/linux/arch/arm64/kernel/vdso32/Makefile (revision a701d28e)
1# SPDX-License-Identifier: GPL-2.0
2#
3# Makefile for vdso32
4#
5
6# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
7# the inclusion of generic Makefile.
8ARCH_REL_TYPE_ABS := R_ARM_JUMP_SLOT|R_ARM_GLOB_DAT|R_ARM_ABS32
9include $(srctree)/lib/vdso/Makefile
10
11# Same as cc-*option, but using CC_COMPAT instead of CC
12ifeq ($(CONFIG_CC_IS_CLANG), y)
13COMPAT_GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE_COMPAT)elfedit))
14COMPAT_GCC_TOOLCHAIN := $(realpath $(COMPAT_GCC_TOOLCHAIN_DIR)/..)
15
16CC_COMPAT_CLANG_FLAGS := --target=$(notdir $(CROSS_COMPILE_COMPAT:%-=%))
17CC_COMPAT_CLANG_FLAGS += --prefix=$(COMPAT_GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE_COMPAT))
18CC_COMPAT_CLANG_FLAGS += -no-integrated-as -Qunused-arguments
19ifneq ($(COMPAT_GCC_TOOLCHAIN),)
20CC_COMPAT_CLANG_FLAGS += --gcc-toolchain=$(COMPAT_GCC_TOOLCHAIN)
21endif
22
23CC_COMPAT ?= $(CC)
24CC_COMPAT += $(CC_COMPAT_CLANG_FLAGS)
25
26ifneq ($(LLVM),)
27LD_COMPAT ?= $(LD)
28else
29LD_COMPAT ?= $(CROSS_COMPILE_COMPAT)ld
30endif
31else
32CC_COMPAT ?= $(CROSS_COMPILE_COMPAT)gcc
33LD_COMPAT ?= $(CROSS_COMPILE_COMPAT)ld
34endif
35
36cc32-option = $(call try-run,\
37        $(CC_COMPAT) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
38cc32-disable-warning = $(call try-run,\
39	$(CC_COMPAT) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
40cc32-as-instr = $(call try-run,\
41	printf "%b\n" "$(1)" | $(CC_COMPAT) $(VDSO_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3))
42
43# We cannot use the global flags to compile the vDSO files, the main reason
44# being that the 32-bit compiler may be older than the main (64-bit) compiler
45# and therefore may not understand flags set using $(cc-option ...). Besides,
46# arch-specific options should be taken from the arm Makefile instead of the
47# arm64 one.
48# As a result we set our own flags here.
49
50# KBUILD_CPPFLAGS and NOSTDINC_FLAGS from top-level Makefile
51VDSO_CPPFLAGS := -D__KERNEL__ -nostdinc -isystem $(shell $(CC_COMPAT) -print-file-name=include)
52VDSO_CPPFLAGS += $(LINUXINCLUDE)
53
54# Common C and assembly flags
55# From top-level Makefile
56VDSO_CAFLAGS := $(VDSO_CPPFLAGS)
57ifneq ($(shell $(CC_COMPAT) --version 2>&1 | head -n 1 | grep clang),)
58VDSO_CAFLAGS += --target=$(notdir $(CROSS_COMPILE_COMPAT:%-=%))
59endif
60
61VDSO_CAFLAGS += $(call cc32-option,-fno-PIE)
62ifdef CONFIG_DEBUG_INFO
63VDSO_CAFLAGS += -g
64endif
65
66# From arm Makefile
67VDSO_CAFLAGS += $(call cc32-option,-fno-dwarf2-cfi-asm)
68VDSO_CAFLAGS += -mabi=aapcs-linux -mfloat-abi=soft
69ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)
70VDSO_CAFLAGS += -mbig-endian
71else
72VDSO_CAFLAGS += -mlittle-endian
73endif
74
75# From arm vDSO Makefile
76VDSO_CAFLAGS += -fPIC -fno-builtin -fno-stack-protector
77VDSO_CAFLAGS += -DDISABLE_BRANCH_PROFILING
78
79
80# Try to compile for ARMv8. If the compiler is too old and doesn't support it,
81# fall back to v7. There is no easy way to check for what architecture the code
82# is being compiled, so define a macro specifying that (see arch/arm/Makefile).
83VDSO_CAFLAGS += $(call cc32-option,-march=armv8-a -D__LINUX_ARM_ARCH__=8,\
84                                   -march=armv7-a -D__LINUX_ARM_ARCH__=7)
85
86VDSO_CFLAGS := $(VDSO_CAFLAGS)
87VDSO_CFLAGS += -DENABLE_COMPAT_VDSO=1
88# KBUILD_CFLAGS from top-level Makefile
89VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
90               -fno-strict-aliasing -fno-common \
91               -Werror-implicit-function-declaration \
92               -Wno-format-security \
93               -std=gnu89
94VDSO_CFLAGS  += -O2
95# Some useful compiler-dependent flags from top-level Makefile
96VDSO_CFLAGS += $(call cc32-option,-Wdeclaration-after-statement,)
97VDSO_CFLAGS += $(call cc32-option,-Wno-pointer-sign)
98VDSO_CFLAGS += -fno-strict-overflow
99VDSO_CFLAGS += $(call cc32-option,-Werror=strict-prototypes)
100VDSO_CFLAGS += -Werror=date-time
101VDSO_CFLAGS += $(call cc32-option,-Werror=incompatible-pointer-types)
102
103# The 32-bit compiler does not provide 128-bit integers, which are used in
104# some headers that are indirectly included from the vDSO code.
105# This hack makes the compiler happy and should trigger a warning/error if
106# variables of such type are referenced.
107VDSO_CFLAGS += -D__uint128_t='void*'
108# Silence some warnings coming from headers that operate on long's
109# (on GCC 4.8 or older, there is unfortunately no way to silence this warning)
110VDSO_CFLAGS += $(call cc32-disable-warning,shift-count-overflow)
111VDSO_CFLAGS += -Wno-int-to-pointer-cast
112
113# Compile as THUMB2 or ARM. Unwinding via frame-pointers in THUMB2 is
114# unreliable.
115ifeq ($(CONFIG_THUMB2_COMPAT_VDSO), y)
116VDSO_CFLAGS += -mthumb -fomit-frame-pointer
117else
118VDSO_CFLAGS += -marm
119endif
120
121VDSO_AFLAGS := $(VDSO_CAFLAGS)
122VDSO_AFLAGS += -D__ASSEMBLY__
123
124# Check for binutils support for dmb ishld
125dmbinstr := $(call cc32-as-instr,dmb ishld,-DCONFIG_AS_DMB_ISHLD=1)
126
127VDSO_CFLAGS += $(dmbinstr)
128VDSO_AFLAGS += $(dmbinstr)
129
130# From arm vDSO Makefile
131VDSO_LDFLAGS += -Bsymbolic --no-undefined -soname=linux-vdso.so.1
132VDSO_LDFLAGS += -z max-page-size=4096 -z common-page-size=4096
133VDSO_LDFLAGS += -nostdlib -shared --hash-style=sysv --build-id=sha1
134
135
136# Borrow vdsomunge.c from the arm vDSO
137# We have to use a relative path because scripts/Makefile.host prefixes
138# $(hostprogs) with $(obj)
139munge := ../../../arm/vdso/vdsomunge
140hostprogs := $(munge)
141
142c-obj-vdso := note.o
143c-obj-vdso-gettimeofday := vgettimeofday.o
144
145ifneq ($(c-gettimeofday-y),)
146VDSO_CFLAGS_gettimeofday_o += -include $(c-gettimeofday-y)
147endif
148
149VDSO_CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE) -Os
150
151# Build rules
152targets := $(c-obj-vdso) $(c-obj-vdso-gettimeofday) $(asm-obj-vdso) vdso.so vdso.so.dbg vdso.so.raw
153c-obj-vdso := $(addprefix $(obj)/, $(c-obj-vdso))
154c-obj-vdso-gettimeofday := $(addprefix $(obj)/, $(c-obj-vdso-gettimeofday))
155asm-obj-vdso := $(addprefix $(obj)/, $(asm-obj-vdso))
156obj-vdso := $(c-obj-vdso) $(c-obj-vdso-gettimeofday) $(asm-obj-vdso)
157
158obj-y += vdso.o
159targets += vdso.lds
160CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
161
162# Force dependency (vdso.s includes vdso.so through incbin)
163$(obj)/vdso.o: $(obj)/vdso.so
164
165include/generated/vdso32-offsets.h: $(obj)/vdso.so.dbg FORCE
166	$(call if_changed,vdsosym)
167
168# Strip rule for vdso.so
169$(obj)/vdso.so: OBJCOPYFLAGS := -S
170$(obj)/vdso.so: $(obj)/vdso.so.dbg FORCE
171	$(call if_changed,objcopy)
172
173$(obj)/vdso.so.dbg: $(obj)/vdso.so.raw $(obj)/$(munge) FORCE
174	$(call if_changed,vdsomunge)
175
176# Link rule for the .so file, .lds has to be first
177$(obj)/vdso.so.raw: $(src)/vdso.lds $(obj-vdso) FORCE
178	$(call if_changed,vdsold_and_vdso_check)
179
180# Compilation rules for the vDSO sources
181$(c-obj-vdso): %.o: %.c FORCE
182	$(call if_changed_dep,vdsocc)
183$(c-obj-vdso-gettimeofday): %.o: %.c FORCE
184	$(call if_changed_dep,vdsocc_gettimeofday)
185$(asm-obj-vdso): %.o: %.S FORCE
186	$(call if_changed_dep,vdsoas)
187
188# Actual build commands
189quiet_cmd_vdsold_and_vdso_check = LD32    $@
190      cmd_vdsold_and_vdso_check = $(cmd_vdsold); $(cmd_vdso_check)
191
192quiet_cmd_vdsold = LD32    $@
193      cmd_vdsold = $(LD_COMPAT) $(VDSO_LDFLAGS) \
194                   -T $(filter %.lds,$^) $(filter %.o,$^) -o $@
195quiet_cmd_vdsocc = CC32    $@
196      cmd_vdsocc = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) -c -o $@ $<
197quiet_cmd_vdsocc_gettimeofday = CC32    $@
198      cmd_vdsocc_gettimeofday = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) $(VDSO_CFLAGS_gettimeofday_o) -c -o $@ $<
199quiet_cmd_vdsoas = AS32    $@
200      cmd_vdsoas = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_AFLAGS) -c -o $@ $<
201
202quiet_cmd_vdsomunge = MUNGE   $@
203      cmd_vdsomunge = $(obj)/$(munge) $< $@
204
205# Generate vDSO offsets using helper script (borrowed from the 64-bit vDSO)
206gen-vdsosym := $(srctree)/$(src)/../vdso/gen_vdso_offsets.sh
207quiet_cmd_vdsosym = VDSOSYM $@
208# The AArch64 nm should be able to read an AArch32 binary
209      cmd_vdsosym = $(NM) $< | $(gen-vdsosym) | LC_ALL=C sort > $@
210
211# Install commands for the unstripped file
212quiet_cmd_vdso_install = INSTALL32 $@
213      cmd_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/vdso/vdso32.so
214
215vdso.so: $(obj)/vdso.so.dbg
216	@mkdir -p $(MODLIB)/vdso
217	$(call cmd,vdso_install)
218
219vdso_install: vdso.so
220