xref: /openbmc/linux/arch/arm64/kernel/vdso32/Makefile (revision 6b342707)
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               -std=gnu89
72VDSO_CFLAGS  += -O2
73# Some useful compiler-dependent flags from top-level Makefile
74VDSO_CFLAGS += $(call cc32-option,-Wdeclaration-after-statement,)
75VDSO_CFLAGS += $(call cc32-option,-Wno-pointer-sign)
76VDSO_CFLAGS += -fno-strict-overflow
77VDSO_CFLAGS += $(call cc32-option,-Werror=strict-prototypes)
78VDSO_CFLAGS += -Werror=date-time
79VDSO_CFLAGS += $(call cc32-option,-Werror=incompatible-pointer-types)
80
81# The 32-bit compiler does not provide 128-bit integers, which are used in
82# some headers that are indirectly included from the vDSO code.
83# This hack makes the compiler happy and should trigger a warning/error if
84# variables of such type are referenced.
85VDSO_CFLAGS += -D__uint128_t='void*'
86# Silence some warnings coming from headers that operate on long's
87# (on GCC 4.8 or older, there is unfortunately no way to silence this warning)
88VDSO_CFLAGS += $(call cc32-disable-warning,shift-count-overflow)
89VDSO_CFLAGS += -Wno-int-to-pointer-cast
90
91# Compile as THUMB2 or ARM. Unwinding via frame-pointers in THUMB2 is
92# unreliable.
93ifeq ($(CONFIG_THUMB2_COMPAT_VDSO), y)
94VDSO_CFLAGS += -mthumb -fomit-frame-pointer
95else
96VDSO_CFLAGS += -marm
97endif
98
99VDSO_AFLAGS := $(VDSO_CAFLAGS)
100VDSO_AFLAGS += -D__ASSEMBLY__
101
102# From arm vDSO Makefile
103VDSO_LDFLAGS += -Bsymbolic --no-undefined -soname=linux-vdso.so.1
104VDSO_LDFLAGS += -z max-page-size=4096 -z common-page-size=4096
105VDSO_LDFLAGS += -shared --hash-style=sysv --build-id=sha1
106
107
108# Borrow vdsomunge.c from the arm vDSO
109# We have to use a relative path because scripts/Makefile.host prefixes
110# $(hostprogs) with $(obj)
111munge := ../../../arm/vdso/vdsomunge
112hostprogs := $(munge)
113
114c-obj-vdso := note.o
115c-obj-vdso-gettimeofday := vgettimeofday.o
116
117ifneq ($(c-gettimeofday-y),)
118VDSO_CFLAGS_gettimeofday_o += -include $(c-gettimeofday-y)
119endif
120
121VDSO_CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE) -Os
122
123# Build rules
124targets := $(c-obj-vdso) $(c-obj-vdso-gettimeofday) $(asm-obj-vdso) vdso.so vdso.so.dbg vdso.so.raw
125c-obj-vdso := $(addprefix $(obj)/, $(c-obj-vdso))
126c-obj-vdso-gettimeofday := $(addprefix $(obj)/, $(c-obj-vdso-gettimeofday))
127asm-obj-vdso := $(addprefix $(obj)/, $(asm-obj-vdso))
128obj-vdso := $(c-obj-vdso) $(c-obj-vdso-gettimeofday) $(asm-obj-vdso)
129
130targets += vdso.lds
131CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
132
133# Force dependency (vdso.s includes vdso.so through incbin)
134$(obj)/vdso.o: $(obj)/vdso.so
135
136include/generated/vdso32-offsets.h: $(obj)/vdso.so.dbg FORCE
137	$(call if_changed,vdsosym)
138
139# Strip rule for vdso.so
140$(obj)/vdso.so: OBJCOPYFLAGS := -S
141$(obj)/vdso.so: $(obj)/vdso.so.dbg FORCE
142	$(call if_changed,objcopy)
143
144$(obj)/vdso.so.dbg: $(obj)/vdso.so.raw $(obj)/$(munge) FORCE
145	$(call if_changed,vdsomunge)
146
147# Link rule for the .so file, .lds has to be first
148$(obj)/vdso.so.raw: $(src)/vdso.lds $(obj-vdso) FORCE
149	$(call if_changed,vdsold_and_vdso_check)
150
151# Compilation rules for the vDSO sources
152$(c-obj-vdso): %.o: %.c FORCE
153	$(call if_changed_dep,vdsocc)
154$(c-obj-vdso-gettimeofday): %.o: %.c FORCE
155	$(call if_changed_dep,vdsocc_gettimeofday)
156$(asm-obj-vdso): %.o: %.S FORCE
157	$(call if_changed_dep,vdsoas)
158
159# Actual build commands
160quiet_cmd_vdsold_and_vdso_check = LD32    $@
161      cmd_vdsold_and_vdso_check = $(cmd_vdsold); $(cmd_vdso_check)
162
163quiet_cmd_vdsold = LD32    $@
164      cmd_vdsold = $(LD_COMPAT) $(VDSO_LDFLAGS) \
165                   -T $(filter %.lds,$^) $(filter %.o,$^) -o $@
166quiet_cmd_vdsocc = CC32    $@
167      cmd_vdsocc = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) -c -o $@ $<
168quiet_cmd_vdsocc_gettimeofday = CC32    $@
169      cmd_vdsocc_gettimeofday = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) $(VDSO_CFLAGS_gettimeofday_o) -c -o $@ $<
170quiet_cmd_vdsoas = AS32    $@
171      cmd_vdsoas = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_AFLAGS) -c -o $@ $<
172
173quiet_cmd_vdsomunge = MUNGE   $@
174      cmd_vdsomunge = $(obj)/$(munge) $< $@
175
176# Generate vDSO offsets using helper script (borrowed from the 64-bit vDSO)
177gen-vdsosym := $(srctree)/$(src)/../vdso/gen_vdso_offsets.sh
178quiet_cmd_vdsosym = VDSOSYM $@
179# The AArch64 nm should be able to read an AArch32 binary
180      cmd_vdsosym = $(NM) $< | $(gen-vdsosym) | LC_ALL=C sort > $@
181
182# Install commands for the unstripped file
183quiet_cmd_vdso_install = INSTALL32 $@
184      cmd_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/vdso/vdso32.so
185
186vdso.so: $(obj)/vdso.so.dbg
187	@mkdir -p $(MODLIB)/vdso
188	$(call cmd,vdso_install)
189
190vdso_install: vdso.so
191