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 COMPATCC := $(CROSS_COMPILE_COMPAT)gcc
13 # Same as cc-*option, but using COMPATCC instead of CC
14 cc32-option = $(call try-run,\
15 $(COMPATCC) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
16 cc32-disable-warning = $(call try-run,\
17 $(COMPATCC) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
18 cc32-ldoption = $(call try-run,\
19 $(COMPATCC) $(1) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
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
26 # As a result we set our own flags here.
28 # From top-level Makefile
30 VDSO_CPPFLAGS := -nostdinc -isystem $(shell $(COMPATCC) -print-file-name=include)
31 VDSO_CPPFLAGS += $(LINUXINCLUDE)
32 VDSO_CPPFLAGS += $(KBUILD_CPPFLAGS)
34 # Common C and assembly flags
35 # From top-level Makefile
36 VDSO_CAFLAGS := $(VDSO_CPPFLAGS)
37 VDSO_CAFLAGS += $(call cc32-option,-fno-PIE)
38 ifdef CONFIG_DEBUG_INFO
41 ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(COMPATCC)), y)
42 VDSO_CAFLAGS += -DCC_HAVE_ASM_GOTO
46 VDSO_CAFLAGS += $(call cc32-option,-fno-dwarf2-cfi-asm)
47 VDSO_CAFLAGS += -mabi=aapcs-linux -mfloat-abi=soft
48 ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)
49 VDSO_CAFLAGS += -mbig-endian
51 VDSO_CAFLAGS += -mlittle-endian
54 # From arm vDSO Makefile
55 VDSO_CAFLAGS += -fPIC -fno-builtin -fno-stack-protector
56 VDSO_CAFLAGS += -DDISABLE_BRANCH_PROFILING
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).
61 VDSO_CAFLAGS += $(call cc32-option,-march=armv8-a -D__LINUX_ARM_ARCH__=8,\
62 -march=armv7-a -D__LINUX_ARM_ARCH__=7)
64 VDSO_CFLAGS := $(VDSO_CAFLAGS)
65 VDSO_CFLAGS += -DENABLE_COMPAT_VDSO=1
66 # KBUILD_CFLAGS from top-level Makefile
67 VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
68 -fno-strict-aliasing -fno-common \
69 -Werror-implicit-function-declaration \
70 -Wno-format-security \
73 # Some useful compiler-dependent flags from top-level Makefile
74 VDSO_CFLAGS += $(call cc32-option,-Wdeclaration-after-statement,)
75 VDSO_CFLAGS += $(call cc32-option,-Wno-pointer-sign)
76 VDSO_CFLAGS += $(call cc32-option,-fno-strict-overflow)
77 VDSO_CFLAGS += $(call cc32-option,-Werror=strict-prototypes)
78 VDSO_CFLAGS += $(call cc32-option,-Werror=date-time)
79 VDSO_CFLAGS += $(call cc32-option,-Werror=incompatible-pointer-types)
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.
85 VDSO_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)
88 VDSO_CFLAGS += $(call cc32-disable-warning,shift-count-overflow)
89 VDSO_CFLAGS += -Wno-int-to-pointer-cast
91 VDSO_AFLAGS := $(VDSO_CAFLAGS)
92 VDSO_AFLAGS += -D__ASSEMBLY__
94 VDSO_LDFLAGS := $(VDSO_CPPFLAGS)
95 # From arm vDSO Makefile
96 VDSO_LDFLAGS += -Wl,-Bsymbolic -Wl,--no-undefined -Wl,-soname=linux-vdso.so.1
97 VDSO_LDFLAGS += -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096
98 VDSO_LDFLAGS += -nostdlib -shared -mfloat-abi=soft
99 VDSO_LDFLAGS += -Wl,--hash-style=sysv
100 VDSO_LDFLAGS += -Wl,--build-id
101 VDSO_LDFLAGS += $(call cc32-ldoption,-fuse-ld=bfd)
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)
107 munge := ../../../arm/vdso/vdsomunge
108 hostprogs-y := $(munge)
111 c-obj-vdso-gettimeofday := vgettimeofday.o
112 asm-obj-vdso := sigreturn.o
114 ifneq ($(c-gettimeofday-y),)
115 VDSO_CFLAGS_gettimeofday_o += -include $(c-gettimeofday-y)
118 VDSO_CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE) -Os
121 targets := $(c-obj-vdso) $(c-obj-vdso-gettimeofday) $(asm-obj-vdso) vdso.so vdso.so.dbg vdso.so.raw
122 c-obj-vdso := $(addprefix $(obj)/, $(c-obj-vdso))
123 c-obj-vdso-gettimeofday := $(addprefix $(obj)/, $(c-obj-vdso-gettimeofday))
124 asm-obj-vdso := $(addprefix $(obj)/, $(asm-obj-vdso))
125 obj-vdso := $(c-obj-vdso) $(c-obj-vdso-gettimeofday) $(asm-obj-vdso)
129 CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
131 # Force dependency (vdso.s includes vdso.so through incbin)
132 $(obj)/vdso.o: $(obj)/vdso.so
134 include/generated/vdso32-offsets.h: $(obj)/vdso.so.dbg FORCE
135 $(call if_changed,vdsosym)
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)
142 $(obj)/vdso.so.dbg: $(obj)/vdso.so.raw $(obj)/$(munge) FORCE
143 $(call if_changed,vdsomunge)
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)
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)
158 # Actual build commands
159 quiet_cmd_vdsold = VDSOL $@
160 cmd_vdsold = $(COMPATCC) -Wp,-MD,$(depfile) $(VDSO_LDFLAGS) \
161 -Wl,-T $(filter %.lds,$^) $(filter %.o,$^) -o $@
162 quiet_cmd_vdsocc = VDSOC $@
163 cmd_vdsocc = $(COMPATCC) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) -c -o $@ $<
164 quiet_cmd_vdsocc_gettimeofday = VDSOC_GTD $@
165 cmd_vdsocc_gettimeofday = $(COMPATCC) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) $(VDSO_CFLAGS_gettimeofday_o) -c -o $@ $<
166 quiet_cmd_vdsoas = VDSOA $@
167 cmd_vdsoas = $(COMPATCC) -Wp,-MD,$(depfile) $(VDSO_AFLAGS) -c -o $@ $<
169 quiet_cmd_vdsomunge = MUNGE $@
170 cmd_vdsomunge = $(obj)/$(munge) $< $@
172 # Generate vDSO offsets using helper script (borrowed from the 64-bit vDSO)
173 gen-vdsosym := $(srctree)/$(src)/../vdso/gen_vdso_offsets.sh
174 quiet_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 > $@
178 # Install commands for the unstripped file
179 quiet_cmd_vdso_install = INSTALL $@
180 cmd_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/vdso/vdso32.so
182 vdso.so: $(obj)/vdso.so.dbg
183 @mkdir -p $(MODLIB)/vdso
184 $(call cmd,vdso_install)
186 vdso_install: vdso.so