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