1 # SPDX-License-Identifier: GPL-2.0
6 # Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
7 # the inclusion of generic Makefile.
8 ARCH_REL_TYPE_ABS := R_ARM_JUMP_SLOT|R_ARM_GLOB_DAT|R_ARM_ABS32
9 include $(srctree)/lib/vdso/Makefile
11 # Same as cc-*option, but using COMPATCC instead of CC
12 ifeq ($(CONFIG_CC_IS_CLANG), y)
13 COMPATCC ?= $(CC) --target=$(notdir $(CROSS_COMPILE_COMPAT:%-=%))
15 COMPATCC ?= $(CROSS_COMPILE_COMPAT)gcc
18 cc32-option = $(call try-run,\
19 $(COMPATCC) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
20 cc32-disable-warning = $(call try-run,\
21 $(COMPATCC) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
22 cc32-ldoption = $(call try-run,\
23 $(COMPATCC) $(1) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
24 cc32-as-instr = $(call try-run,\
25 printf "%b\n" "$(1)" | $(COMPATCC) $(VDSO_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3))
27 # We cannot use the global flags to compile the vDSO files, the main reason
28 # being that the 32-bit compiler may be older than the main (64-bit) compiler
29 # and therefore may not understand flags set using $(cc-option ...). Besides,
30 # arch-specific options should be taken from the arm Makefile instead of the
32 # As a result we set our own flags here.
34 # From top-level Makefile
36 VDSO_CPPFLAGS := -nostdinc -isystem $(shell $(COMPATCC) -print-file-name=include)
37 VDSO_CPPFLAGS += $(LINUXINCLUDE)
38 VDSO_CPPFLAGS += $(KBUILD_CPPFLAGS)
40 # Common C and assembly flags
41 # From top-level Makefile
42 VDSO_CAFLAGS := $(VDSO_CPPFLAGS)
43 VDSO_CAFLAGS += $(call cc32-option,-fno-PIE)
44 ifdef CONFIG_DEBUG_INFO
49 VDSO_CAFLAGS += $(call cc32-option,-fno-dwarf2-cfi-asm)
50 VDSO_CAFLAGS += -mabi=aapcs-linux -mfloat-abi=soft
51 ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)
52 VDSO_CAFLAGS += -mbig-endian
54 VDSO_CAFLAGS += -mlittle-endian
57 # From arm vDSO Makefile
58 VDSO_CAFLAGS += -fPIC -fno-builtin -fno-stack-protector
59 VDSO_CAFLAGS += -DDISABLE_BRANCH_PROFILING
62 # Try to compile for ARMv8. If the compiler is too old and doesn't support it,
63 # fall back to v7. There is no easy way to check for what architecture the code
64 # is being compiled, so define a macro specifying that (see arch/arm/Makefile).
65 VDSO_CAFLAGS += $(call cc32-option,-march=armv8-a -D__LINUX_ARM_ARCH__=8,\
66 -march=armv7-a -D__LINUX_ARM_ARCH__=7)
68 VDSO_CFLAGS := $(VDSO_CAFLAGS)
69 VDSO_CFLAGS += -DENABLE_COMPAT_VDSO=1
70 # KBUILD_CFLAGS from top-level Makefile
71 VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
72 -fno-strict-aliasing -fno-common \
73 -Werror-implicit-function-declaration \
74 -Wno-format-security \
77 # Some useful compiler-dependent flags from top-level Makefile
78 VDSO_CFLAGS += $(call cc32-option,-Wdeclaration-after-statement,)
79 VDSO_CFLAGS += $(call cc32-option,-Wno-pointer-sign)
80 VDSO_CFLAGS += $(call cc32-option,-fno-strict-overflow)
81 VDSO_CFLAGS += $(call cc32-option,-Werror=strict-prototypes)
82 VDSO_CFLAGS += $(call cc32-option,-Werror=date-time)
83 VDSO_CFLAGS += $(call cc32-option,-Werror=incompatible-pointer-types)
85 # The 32-bit compiler does not provide 128-bit integers, which are used in
86 # some headers that are indirectly included from the vDSO code.
87 # This hack makes the compiler happy and should trigger a warning/error if
88 # variables of such type are referenced.
89 VDSO_CFLAGS += -D__uint128_t='void*'
90 # Silence some warnings coming from headers that operate on long's
91 # (on GCC 4.8 or older, there is unfortunately no way to silence this warning)
92 VDSO_CFLAGS += $(call cc32-disable-warning,shift-count-overflow)
93 VDSO_CFLAGS += -Wno-int-to-pointer-cast
95 VDSO_AFLAGS := $(VDSO_CAFLAGS)
96 VDSO_AFLAGS += -D__ASSEMBLY__
98 # Check for binutils support for dmb ishld
99 dmbinstr := $(call cc32-as-instr,dmb ishld,-DCONFIG_AS_DMB_ISHLD=1)
101 VDSO_CFLAGS += $(dmbinstr)
102 VDSO_AFLAGS += $(dmbinstr)
104 VDSO_LDFLAGS := $(VDSO_CPPFLAGS)
105 # From arm vDSO Makefile
106 VDSO_LDFLAGS += -Wl,-Bsymbolic -Wl,--no-undefined -Wl,-soname=linux-vdso.so.1
107 VDSO_LDFLAGS += -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096
108 VDSO_LDFLAGS += -nostdlib -shared -mfloat-abi=soft
109 VDSO_LDFLAGS += -Wl,--hash-style=sysv
110 VDSO_LDFLAGS += -Wl,--build-id
111 VDSO_LDFLAGS += $(call cc32-ldoption,-fuse-ld=bfd)
114 # Borrow vdsomunge.c from the arm vDSO
115 # We have to use a relative path because scripts/Makefile.host prefixes
116 # $(hostprogs-y) with $(obj)
117 munge := ../../../arm/vdso/vdsomunge
118 hostprogs-y := $(munge)
121 c-obj-vdso-gettimeofday := vgettimeofday.o
122 asm-obj-vdso := sigreturn.o
124 ifneq ($(c-gettimeofday-y),)
125 VDSO_CFLAGS_gettimeofday_o += -include $(c-gettimeofday-y)
128 VDSO_CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE) -Os
131 targets := $(c-obj-vdso) $(c-obj-vdso-gettimeofday) $(asm-obj-vdso) vdso.so vdso.so.dbg vdso.so.raw
132 c-obj-vdso := $(addprefix $(obj)/, $(c-obj-vdso))
133 c-obj-vdso-gettimeofday := $(addprefix $(obj)/, $(c-obj-vdso-gettimeofday))
134 asm-obj-vdso := $(addprefix $(obj)/, $(asm-obj-vdso))
135 obj-vdso := $(c-obj-vdso) $(c-obj-vdso-gettimeofday) $(asm-obj-vdso)
139 CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
141 # Force dependency (vdso.s includes vdso.so through incbin)
142 $(obj)/vdso.o: $(obj)/vdso.so
144 include/generated/vdso32-offsets.h: $(obj)/vdso.so.dbg FORCE
145 $(call if_changed,vdsosym)
147 # Strip rule for vdso.so
148 $(obj)/vdso.so: OBJCOPYFLAGS := -S
149 $(obj)/vdso.so: $(obj)/vdso.so.dbg FORCE
150 $(call if_changed,objcopy)
152 $(obj)/vdso.so.dbg: $(obj)/vdso.so.raw $(obj)/$(munge) FORCE
153 $(call if_changed,vdsomunge)
155 # Link rule for the .so file, .lds has to be first
156 $(obj)/vdso.so.raw: $(src)/vdso.lds $(obj-vdso) FORCE
157 $(call if_changed,vdsold_and_vdso_check)
159 # Compilation rules for the vDSO sources
160 $(c-obj-vdso): %.o: %.c FORCE
161 $(call if_changed_dep,vdsocc)
162 $(c-obj-vdso-gettimeofday): %.o: %.c FORCE
163 $(call if_changed_dep,vdsocc_gettimeofday)
164 $(asm-obj-vdso): %.o: %.S FORCE
165 $(call if_changed_dep,vdsoas)
167 # Actual build commands
168 quiet_cmd_vdsold_and_vdso_check = LD32 $@
169 cmd_vdsold_and_vdso_check = $(cmd_vdsold); $(cmd_vdso_check)
171 quiet_cmd_vdsold = LD32 $@
172 cmd_vdsold = $(COMPATCC) -Wp,-MD,$(depfile) $(VDSO_LDFLAGS) \
173 -Wl,-T $(filter %.lds,$^) $(filter %.o,$^) -o $@
174 quiet_cmd_vdsocc = CC32 $@
175 cmd_vdsocc = $(COMPATCC) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) -c -o $@ $<
176 quiet_cmd_vdsocc_gettimeofday = CC32 $@
177 cmd_vdsocc_gettimeofday = $(COMPATCC) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) $(VDSO_CFLAGS_gettimeofday_o) -c -o $@ $<
178 quiet_cmd_vdsoas = AS32 $@
179 cmd_vdsoas = $(COMPATCC) -Wp,-MD,$(depfile) $(VDSO_AFLAGS) -c -o $@ $<
181 quiet_cmd_vdsomunge = MUNGE $@
182 cmd_vdsomunge = $(obj)/$(munge) $< $@
184 # Generate vDSO offsets using helper script (borrowed from the 64-bit vDSO)
185 gen-vdsosym := $(srctree)/$(src)/../vdso/gen_vdso_offsets.sh
186 quiet_cmd_vdsosym = VDSOSYM $@
187 # The AArch64 nm should be able to read an AArch32 binary
188 cmd_vdsosym = $(NM) $< | $(gen-vdsosym) | LC_ALL=C sort > $@
190 # Install commands for the unstripped file
191 quiet_cmd_vdso_install = INSTALL $@
192 cmd_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/vdso/vdso32.so
194 vdso.so: $(obj)/vdso.so.dbg
195 @mkdir -p $(MODLIB)/vdso
196 $(call cmd,vdso_install)
198 vdso_install: vdso.so