xref: /openbmc/linux/arch/arm64/kernel/vdso32/Makefile (revision 568b9de4)
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
11COMPATCC := $(CROSS_COMPILE_COMPAT)gcc
12
13# Same as cc-*option, but using COMPATCC instead of CC
14cc32-option = $(call try-run,\
15        $(COMPATCC) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
16cc32-disable-warning = $(call try-run,\
17	$(COMPATCC) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
18cc32-ldoption = $(call try-run,\
19        $(COMPATCC) $(1) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
20
21# We cannot use the global flags to compile the vDSO files, the main reason
22# being that the 32-bit compiler may be older than the main (64-bit) compiler
23# and therefore may not understand flags set using $(cc-option ...). Besides,
24# arch-specific options should be taken from the arm Makefile instead of the
25# arm64 one.
26# As a result we set our own flags here.
27
28# From top-level Makefile
29# NOSTDINC_FLAGS
30VDSO_CPPFLAGS := -nostdinc -isystem $(shell $(COMPATCC) -print-file-name=include)
31VDSO_CPPFLAGS += $(LINUXINCLUDE)
32VDSO_CPPFLAGS += $(KBUILD_CPPFLAGS)
33
34# Common C and assembly flags
35# From top-level Makefile
36VDSO_CAFLAGS := $(VDSO_CPPFLAGS)
37VDSO_CAFLAGS += $(call cc32-option,-fno-PIE)
38ifdef CONFIG_DEBUG_INFO
39VDSO_CAFLAGS += -g
40endif
41ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(COMPATCC)), y)
42VDSO_CAFLAGS += -DCC_HAVE_ASM_GOTO
43endif
44
45# From arm Makefile
46VDSO_CAFLAGS += $(call cc32-option,-fno-dwarf2-cfi-asm)
47VDSO_CAFLAGS += -mabi=aapcs-linux -mfloat-abi=soft
48ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)
49VDSO_CAFLAGS += -mbig-endian
50else
51VDSO_CAFLAGS += -mlittle-endian
52endif
53
54# From arm vDSO Makefile
55VDSO_CAFLAGS += -fPIC -fno-builtin -fno-stack-protector
56VDSO_CAFLAGS += -DDISABLE_BRANCH_PROFILING
57
58# Try to compile for ARMv8. If the compiler is too old and doesn't support it,
59# fall back to v7. There is no easy way to check for what architecture the code
60# is being compiled, so define a macro specifying that (see arch/arm/Makefile).
61VDSO_CAFLAGS += $(call cc32-option,-march=armv8-a -D__LINUX_ARM_ARCH__=8,\
62                                   -march=armv7-a -D__LINUX_ARM_ARCH__=7)
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 += $(call cc32-option,-fno-strict-overflow)
77VDSO_CFLAGS += $(call cc32-option,-Werror=strict-prototypes)
78VDSO_CFLAGS += $(call cc32-option,-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
91VDSO_AFLAGS := $(VDSO_CAFLAGS)
92VDSO_AFLAGS += -D__ASSEMBLY__
93
94VDSO_LDFLAGS := $(VDSO_CPPFLAGS)
95# From arm vDSO Makefile
96VDSO_LDFLAGS += -Wl,-Bsymbolic -Wl,--no-undefined -Wl,-soname=linux-vdso.so.1
97VDSO_LDFLAGS += -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096
98VDSO_LDFLAGS += -nostdlib -shared -mfloat-abi=soft
99VDSO_LDFLAGS += -Wl,--hash-style=sysv
100VDSO_LDFLAGS += -Wl,--build-id
101VDSO_LDFLAGS += $(call cc32-ldoption,-fuse-ld=bfd)
102
103
104# Borrow vdsomunge.c from the arm vDSO
105# We have to use a relative path because scripts/Makefile.host prefixes
106# $(hostprogs-y) with $(obj)
107munge := ../../../arm/vdso/vdsomunge
108hostprogs-y := $(munge)
109
110c-obj-vdso := note.o
111c-obj-vdso-gettimeofday := vgettimeofday.o
112asm-obj-vdso := sigreturn.o
113
114ifneq ($(c-gettimeofday-y),)
115VDSO_CFLAGS_gettimeofday_o += -include $(c-gettimeofday-y)
116endif
117
118VDSO_CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE) -Os
119
120# Build rules
121targets := $(c-obj-vdso) $(c-obj-vdso-gettimeofday) $(asm-obj-vdso) vdso.so vdso.so.dbg vdso.so.raw
122c-obj-vdso := $(addprefix $(obj)/, $(c-obj-vdso))
123c-obj-vdso-gettimeofday := $(addprefix $(obj)/, $(c-obj-vdso-gettimeofday))
124asm-obj-vdso := $(addprefix $(obj)/, $(asm-obj-vdso))
125obj-vdso := $(c-obj-vdso) $(c-obj-vdso-gettimeofday) $(asm-obj-vdso)
126
127obj-y += vdso.o
128extra-y += vdso.lds
129CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
130
131# Force dependency (vdso.s includes vdso.so through incbin)
132$(obj)/vdso.o: $(obj)/vdso.so
133
134include/generated/vdso32-offsets.h: $(obj)/vdso.so.dbg FORCE
135	$(call if_changed,vdsosym)
136
137# Strip rule for vdso.so
138$(obj)/vdso.so: OBJCOPYFLAGS := -S
139$(obj)/vdso.so: $(obj)/vdso.so.dbg FORCE
140	$(call if_changed,objcopy)
141
142$(obj)/vdso.so.dbg: $(obj)/vdso.so.raw $(obj)/$(munge) FORCE
143	$(call if_changed,vdsomunge)
144
145# Link rule for the .so file, .lds has to be first
146$(obj)/vdso.so.raw: $(src)/vdso.lds $(obj-vdso) FORCE
147	$(call if_changed,vdsold)
148	$(call if_changed,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 = VDSOL   $@
160      cmd_vdsold = $(COMPATCC) -Wp,-MD,$(depfile) $(VDSO_LDFLAGS) \
161                   -Wl,-T $(filter %.lds,$^) $(filter %.o,$^) -o $@
162quiet_cmd_vdsocc = VDSOC   $@
163      cmd_vdsocc = $(COMPATCC) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) -c -o $@ $<
164quiet_cmd_vdsocc_gettimeofday = VDSOC_GTD   $@
165      cmd_vdsocc_gettimeofday = $(COMPATCC) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) $(VDSO_CFLAGS_gettimeofday_o) -c -o $@ $<
166quiet_cmd_vdsoas = VDSOA   $@
167      cmd_vdsoas = $(COMPATCC) -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 = INSTALL $@
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