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