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