xref: /openbmc/linux/arch/arm64/kernel/vdso32/Makefile (revision 8dd3cdea)
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
107
108
109# Borrow vdsomunge.c from the arm vDSO
110# We have to use a relative path because scripts/Makefile.host prefixes
111# $(hostprogs) with $(obj)
112munge := ../../../arm/vdso/vdsomunge
113hostprogs := $(munge)
114
115c-obj-vdso := note.o
116c-obj-vdso-gettimeofday := vgettimeofday.o
117
118ifneq ($(c-gettimeofday-y),)
119VDSO_CFLAGS_gettimeofday_o += -include $(c-gettimeofday-y)
120endif
121
122VDSO_CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE) -Os
123
124# Build rules
125targets := $(c-obj-vdso) $(c-obj-vdso-gettimeofday) $(asm-obj-vdso) vdso.so vdso.so.dbg vdso.so.raw
126c-obj-vdso := $(addprefix $(obj)/, $(c-obj-vdso))
127c-obj-vdso-gettimeofday := $(addprefix $(obj)/, $(c-obj-vdso-gettimeofday))
128asm-obj-vdso := $(addprefix $(obj)/, $(asm-obj-vdso))
129obj-vdso := $(c-obj-vdso) $(c-obj-vdso-gettimeofday) $(asm-obj-vdso)
130
131targets += vdso.lds
132CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
133
134# Force dependency (vdso.s includes vdso.so through incbin)
135$(obj)/vdso.o: $(obj)/vdso.so
136
137include/generated/vdso32-offsets.h: $(obj)/vdso.so.dbg FORCE
138	$(call if_changed,vdsosym)
139
140# Strip rule for vdso.so
141$(obj)/vdso.so: OBJCOPYFLAGS := -S
142$(obj)/vdso.so: $(obj)/vdso.so.dbg FORCE
143	$(call if_changed,objcopy)
144
145$(obj)/vdso.so.dbg: $(obj)/vdso.so.raw $(obj)/$(munge) FORCE
146	$(call if_changed,vdsomunge)
147
148# Link rule for the .so file, .lds has to be first
149$(obj)/vdso.so.raw: $(src)/vdso.lds $(obj-vdso) FORCE
150	$(call if_changed,vdsold_and_vdso_check)
151
152# Compilation rules for the vDSO sources
153$(c-obj-vdso): %.o: %.c FORCE
154	$(call if_changed_dep,vdsocc)
155$(c-obj-vdso-gettimeofday): %.o: %.c FORCE
156	$(call if_changed_dep,vdsocc_gettimeofday)
157$(asm-obj-vdso): %.o: %.S FORCE
158	$(call if_changed_dep,vdsoas)
159
160# Actual build commands
161quiet_cmd_vdsold_and_vdso_check = LD32    $@
162      cmd_vdsold_and_vdso_check = $(cmd_vdsold); $(cmd_vdso_check)
163
164quiet_cmd_vdsold = LD32    $@
165      cmd_vdsold = $(LD_COMPAT) $(VDSO_LDFLAGS) \
166                   -T $(filter %.lds,$^) $(filter %.o,$^) -o $@
167quiet_cmd_vdsocc = CC32    $@
168      cmd_vdsocc = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) -c -o $@ $<
169quiet_cmd_vdsocc_gettimeofday = CC32    $@
170      cmd_vdsocc_gettimeofday = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) $(VDSO_CFLAGS_gettimeofday_o) -c -o $@ $<
171quiet_cmd_vdsoas = AS32    $@
172      cmd_vdsoas = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_AFLAGS) -c -o $@ $<
173
174quiet_cmd_vdsomunge = MUNGE   $@
175      cmd_vdsomunge = $(obj)/$(munge) $< $@
176
177# Generate vDSO offsets using helper script (borrowed from the 64-bit vDSO)
178gen-vdsosym := $(srctree)/$(src)/../vdso/gen_vdso_offsets.sh
179quiet_cmd_vdsosym = VDSOSYM $@
180# The AArch64 nm should be able to read an AArch32 binary
181      cmd_vdsosym = $(NM) $< | $(gen-vdsosym) | LC_ALL=C sort > $@
182
183# Install commands for the unstripped file
184quiet_cmd_vdso_install = INSTALL32 $@
185      cmd_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/vdso/vdso32.so
186
187vdso.so: $(obj)/vdso.so.dbg
188	@mkdir -p $(MODLIB)/vdso
189	$(call cmd,vdso_install)
190
191vdso_install: vdso.so
192