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