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