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