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