1
+ From a011a363720775823e6a291ab62096ae94374bb8 Mon Sep 17 00:00:00 2001
2
+ From: =?UTF-8?q?Rafael=20=C3=81vila=20de=20Esp=C3=ADndola?=
3
+
4
+ Date: Wed, 19 Dec 2018 11:01:43 -0800
5
+ Subject: [PATCH 1/5] x86/build: Mark per-CPU symbols as absolute explicitly
6
+ for LLD
7
+ MIME-Version: 1.0
8
+ Content-Type: text/plain; charset=UTF-8
9
+ Content-Transfer-Encoding: 8bit
10
+
11
+ [ Upstream commit d071ae09a4a1414c1433d5ae9908959a7325b0ad ]
12
+
13
+ Accessing per-CPU variables is done by finding the offset of the
14
+ variable in the per-CPU block and adding it to the address of the
15
+ respective CPU's block.
16
+
17
+ Section 3.10.8 of ld.bfd's documentation states:
18
+
19
+ For expressions involving numbers, relative addresses and absolute
20
+ addresses, ld follows these rules to evaluate terms:
21
+
22
+ Other binary operations, that is, between two relative addresses
23
+ not in the same section, or between a relative address and an
24
+ absolute address, first convert any non-absolute term to an
25
+ absolute address before applying the operator."
26
+
27
+ Note that LLVM's linker does not adhere to the GNU ld's implementation
28
+ and as such requires implicitly-absolute terms to be explicitly marked
29
+ as absolute in the linker script. If not, it fails currently with:
30
+
31
+ ld.lld: error: ./arch/x86/kernel/vmlinux.lds:153: at least one side of the expression must be absolute
32
+ ld.lld: error: ./arch/x86/kernel/vmlinux.lds:154: at least one side of the expression must be absolute
33
+ Makefile:1040: recipe for target 'vmlinux' failed
34
+
35
+ This is not a functional change for ld.bfd which converts the term to an
36
+ absolute symbol anyways as specified above.
37
+
38
+ Based on a previous submission by Tri Vo <
[email protected] >.
39
+
40
+ Reported-by: Dmitry Golovin <
[email protected] >
41
+ Signed-off-by: Rafael Ávila de Espíndola <
[email protected] >
42
+ [ Update commit message per Boris' and Michael's suggestions. ]
43
+ Signed-off-by: Nick Desaulniers <
[email protected] >
44
+ [ Massage commit message more, fix typos. ]
45
+ Signed-off-by: Borislav Petkov <
[email protected] >
46
+ Tested-by: Dmitry Golovin <
[email protected] >
47
+ Cc: "H. Peter Anvin" <
[email protected] >
48
+ Cc: Andy Lutomirski <
[email protected] >
49
+ Cc: Brijesh Singh <
[email protected] >
50
+
51
+ Cc: Ingo Molnar <
[email protected] >
52
+ Cc: Joerg Roedel <
[email protected] >
53
+ Cc: Masahiro Yamada <
[email protected] >
54
+ Cc: Masami Hiramatsu <
[email protected] >
55
+ Cc: Thomas Gleixner <
[email protected] >
56
+
57
+
58
+
59
+
60
+ Link: https://lkml.kernel.org/r/
[email protected]
61
+ Signed-off-by: Sasha Levin <
[email protected] >
62
+ ---
63
+ arch/x86/kernel/vmlinux.lds.S | 2 +-
64
+ 1 file changed, 1 insertion(+), 1 deletion(-)
65
+
66
+ diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
67
+ index a703842b54de..17e1e60b6b40 100644
68
+ --- a/arch/x86/kernel/vmlinux.lds.S
69
+ +++ b/arch/x86/kernel/vmlinux.lds.S
70
+ @@ -365,7 +365,7 @@ SECTIONS
71
+ * Per-cpu symbols which need to be offset from __per_cpu_load
72
+ * for the boot processor.
73
+ */
74
+ - #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
75
+ + #define INIT_PER_CPU(x) init_per_cpu__##x = ABSOLUTE(x) + __per_cpu_load
76
+ INIT_PER_CPU(gdt_page);
77
+ INIT_PER_CPU(irq_stack_union);
78
+
79
+ - -
80
+ 2.21.0
81
+
82
+
83
+ From 9a607e600adedd84e58205ae812974322094efe5 Mon Sep 17 00:00:00 2001
84
+ From: Nick Desaulniers <
[email protected] >
85
+ Date: Mon, 11 Feb 2019 11:30:04 -0800
86
+ Subject: [PATCH 2/5] kbuild: clang: choose GCC_TOOLCHAIN_DIR not on LD
87
+
88
+ commit ad15006cc78459d059af56729c4d9bed7c7fd860 upstream.
89
+
90
+ This causes an issue when trying to build with `make LD=ld.lld` if
91
+ ld.lld and the rest of your cross tools aren't in the same directory
92
+ (ex. /usr/local/bin) (as is the case for Android's build system), as the
93
+ GCC_TOOLCHAIN_DIR then gets set based on `which $(LD)` which will point
94
+ where LLVM tools are, not GCC/binutils tools are located.
95
+
96
+ Instead, select the GCC_TOOLCHAIN_DIR based on another tool provided by
97
+ binutils for which LLVM does not provide a substitute for, such as
98
+ elfedit.
99
+
100
+ Fixes: 785f11aa595b ("kbuild: Add better clang cross build support")
101
+ Link: https://github.com/ClangBuiltLinux/linux/issues/341
102
+ Suggested-by: Nathan Chancellor <
[email protected] >
103
+ Reviewed-by: Nathan Chancellor <
[email protected] >
104
+ Tested-by: Nathan Chancellor <
[email protected] >
105
+ Signed-off-by: Nick Desaulniers <
[email protected] >
106
+ Signed-off-by: Masahiro Yamada <
[email protected] >
107
+ Signed-off-by: Nathan Chancellor <
[email protected] >
108
+ ---
109
+ Makefile | 2 +-
110
+ 1 file changed, 1 insertion(+), 1 deletion(-)
111
+
112
+ diff --git a/Makefile b/Makefile
113
+ index 35be7983ef2d..7bf3fb717921 100644
114
+ --- a/Makefile
115
+ +++ b/Makefile
116
+ @@ -610,7 +610,7 @@ all: vmlinux
117
+ ifeq ($(cc-name),clang)
118
+ ifneq ($(CROSS_COMPILE),)
119
+ CLANG_TARGET := --target=$(notdir $(CROSS_COMPILE:%-=%))
120
+ - GCC_TOOLCHAIN_DIR := $(dir $(shell which $(LD)))
121
+ + GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
122
+ CLANG_PREFIX := --prefix=$(GCC_TOOLCHAIN_DIR)
123
+ GCC_TOOLCHAIN := $(realpath $(GCC_TOOLCHAIN_DIR)/..)
124
+ endif
125
+ - -
126
+ 2.21.0
127
+
128
+
129
+ From c0cccc8cb3c2a4c74550f7cabbfe1a05426a0d45 Mon Sep 17 00:00:00 2001
130
+ From: George Rimar <
[email protected] >
131
+ Date: Fri, 11 Jan 2019 12:10:12 -0800
132
+ Subject: [PATCH 3/5] x86/build: Specify elf_i386 linker emulation explicitly
133
+ for i386 objects
134
+
135
+ commit 927185c124d62a9a4d35878d7f6d432a166b74e3 upstream.
136
+
137
+ The kernel uses the OUTPUT_FORMAT linker script command in it's linker
138
+ scripts. Most of the time, the -m option is passed to the linker with
139
+ correct architecture, but sometimes (at least for x86_64) the -m option
140
+ contradicts the OUTPUT_FORMAT directive.
141
+
142
+ Specifically, arch/x86/boot and arch/x86/realmode/rm produce i386 object
143
+ files, but are linked with the -m elf_x86_64 linker flag when building
144
+ for x86_64.
145
+
146
+ The GNU linker manpage doesn't explicitly state any tie-breakers between
147
+ - m and OUTPUT_FORMAT. But with BFD and Gold linkers, OUTPUT_FORMAT
148
+ overrides the emulation value specified with the -m option.
149
+
150
+ LLVM lld has a different behavior, however. When supplied with
151
+ contradicting -m and OUTPUT_FORMAT values it fails with the following
152
+ error message:
153
+
154
+ ld.lld: error: arch/x86/realmode/rm/header.o is incompatible with elf_x86_64
155
+
156
+ Therefore, just add the correct -m after the incorrect one (it overrides
157
+ it), so the linker invocation looks like this:
158
+
159
+ ld -m elf_x86_64 -z max-page-size=0x200000 -m elf_i386 --emit-relocs -T \
160
+ realmode.lds header.o trampoline_64.o stack.o reboot.o -o realmode.elf
161
+
162
+ This is not a functional change for GNU ld, because (although not
163
+ explicitly documented) OUTPUT_FORMAT overrides -m EMULATION.
164
+
165
+ Tested by building x86_64 kernel with GNU gcc/ld toolchain and booting
166
+ it in QEMU.
167
+
168
+ [ bp: massage and clarify text. ]
169
+
170
+ Suggested-by: Dmitry Golovin <
[email protected] >
171
+ Signed-off-by: George Rimar <
[email protected] >
172
+ Signed-off-by: Tri Vo <
[email protected] >
173
+ Signed-off-by: Borislav Petkov <
[email protected] >
174
+ Tested-by: Tri Vo <
[email protected] >
175
+ Tested-by: Nick Desaulniers <
[email protected] >
176
+ Cc: "H. Peter Anvin" <
[email protected] >
177
+ Cc: Ingo Molnar <
[email protected] >
178
+ Cc: Michael Matz <
[email protected] >
179
+ Cc: Thomas Gleixner <
[email protected] >
180
+
181
+
182
+
183
+
184
+ Link: https://lkml.kernel.org/r/
[email protected]
185
+ [nc: Fix conflicts due to lack of commit 58ab5e0c2c40 ("Kbuild: arch:
186
+ look for generated headers in obtree") in this tree]
187
+ Signed-off-by: Nathan Chancellor <
[email protected] >
188
+ ---
189
+ arch/x86/boot/Makefile | 2 +-
190
+ arch/x86/realmode/rm/Makefile | 2 +-
191
+ 2 files changed, 2 insertions(+), 2 deletions(-)
192
+
193
+ diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
194
+ index 6da2cd0897f3..e94745321cac 100644
195
+ --- a/arch/x86/boot/Makefile
196
+ +++ b/arch/x86/boot/Makefile
197
+ @@ -100,7 +100,7 @@ $(obj)/zoffset.h: $(obj)/compressed/vmlinux FORCE
198
+ AFLAGS_header.o += -I$(obj)
199
+ $(obj)/header.o: $(obj)/voffset.h $(obj)/zoffset.h
200
+
201
+ - LDFLAGS_setup.elf := -T
202
+ + LDFLAGS_setup.elf := -m elf_i386 -T
203
+ $(obj)/setup.elf: $(src)/setup.ld $(SETUP_OBJS) FORCE
204
+ $(call if_changed,ld)
205
+
206
+ diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
207
+ index 2730d775ef9a..228cb16962ba 100644
208
+ --- a/arch/x86/realmode/rm/Makefile
209
+ +++ b/arch/x86/realmode/rm/Makefile
210
+ @@ -43,7 +43,7 @@ $(obj)/pasyms.h: $(REALMODE_OBJS) FORCE
211
+ targets += realmode.lds
212
+ $(obj)/realmode.lds: $(obj)/pasyms.h
213
+
214
+ - LDFLAGS_realmode.elf := --emit-relocs -T
215
+ + LDFLAGS_realmode.elf := -m elf_i386 --emit-relocs -T
216
+ CPPFLAGS_realmode.lds += -P -C -I$(obj)
217
+
218
+ targets += realmode.elf
219
+ - -
220
+ 2.21.0
221
+
222
+
223
+ From ea44fbb53e24856dd3a2e90ed641acb0f61c695a Mon Sep 17 00:00:00 2001
224
+ From: Alistair Strachan <
[email protected] >
225
+ Date: Fri, 3 Aug 2018 10:39:31 -0700
226
+ Subject: [PATCH 4/5] x86: vdso: Use $LD instead of $CC to link
227
+
228
+ commit 379d98ddf41344273d9718556f761420f4dc80b3 upstream.
229
+
230
+ The vdso{32,64}.so can fail to link with CC=clang when clang tries to find
231
+ a suitable GCC toolchain to link these libraries with.
232
+
233
+ /usr/bin/ld: arch/x86/entry/vdso/vclock_gettime.o:
234
+ access beyond end of merged section (782)
235
+
236
+ This happens because the host environment leaked into the cross compiler
237
+ environment due to the way clang searches for suitable GCC toolchains.
238
+
239
+ Clang is a retargetable compiler, and each invocation of it must provide
240
+ - -target=<something> --gcc-toolchain=<something> to allow it to find the
241
+ correct binutils for cross compilation. These flags had been added to
242
+ KBUILD_CFLAGS, but the vdso code uses CC and not KBUILD_CFLAGS (for various
243
+ reasons) which breaks clang's ability to find the correct linker when cross
244
+ compiling.
245
+
246
+ Most of the time this goes unnoticed because the host linker is new enough
247
+ to work anyway, or is incompatible and skipped, but this cannot be reliably
248
+ assumed.
249
+
250
+ This change alters the vdso makefile to just use LD directly, which
251
+ bypasses clang and thus the searching problem. The makefile will just use
252
+ ${CROSS_COMPILE}ld instead, which is always what we want. This matches the
253
+ method used to link vmlinux.
254
+
255
+ This drops references to DISABLE_LTO; this option doesn't seem to be set
256
+ anywhere, and not knowing what its possible values are, it's not clear how
257
+ to convert it from CC to LD flag.
258
+
259
+ Signed-off-by: Alistair Strachan <
[email protected] >
260
+ Signed-off-by: Thomas Gleixner <
[email protected] >
261
+ Acked-by: Andy Lutomirski <
[email protected] >
262
+ Cc: "H. Peter Anvin" <
[email protected] >
263
+ Cc: Greg Kroah-Hartman <
[email protected] >
264
+
265
+
266
+ Cc: Andi Kleen <
[email protected] >
267
+ Link: https://lkml.kernel.org/r/
[email protected]
268
+ Signed-off-by: Nathan Chancellor <
[email protected] >
269
+ ---
270
+ arch/x86/entry/vdso/Makefile | 22 +++++++++-------------
271
+ 1 file changed, 9 insertions(+), 13 deletions(-)
272
+
273
+ diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vdso/Makefile
274
+ index 265c0ed68118..84c4a7105c2a 100644
275
+ --- a/arch/x86/entry/vdso/Makefile
276
+ +++ b/arch/x86/entry/vdso/Makefile
277
+ @@ -41,10 +41,8 @@ targets += $(vdso_img_sodbg)
278
+
279
+ export CPPFLAGS_vdso.lds += -P -C
280
+
281
+ - VDSO_LDFLAGS_vdso.lds = -m64 -Wl,-soname=linux-vdso.so.1 \
282
+ - -Wl,--no-undefined \
283
+ - -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096 \
284
+ - $(DISABLE_LTO)
285
+ + VDSO_LDFLAGS_vdso.lds = -m elf_x86_64 -soname linux-vdso.so.1 --no-undefined \
286
+ + -z max-page-size=4096 -z common-page-size=4096
287
+
288
+ $(obj)/vdso64.so.dbg: $(src)/vdso.lds $(vobjs) FORCE
289
+ $(call if_changed,vdso)
290
+ @@ -90,10 +88,8 @@ CFLAGS_REMOVE_vvar.o = -pg
291
+ #
292
+
293
+ CPPFLAGS_vdsox32.lds = $(CPPFLAGS_vdso.lds)
294
+ - VDSO_LDFLAGS_vdsox32.lds = -Wl,-m,elf32_x86_64 \
295
+ - -Wl,-soname=linux-vdso.so.1 \
296
+ - -Wl,-z,max-page-size=4096 \
297
+ - -Wl,-z,common-page-size=4096
298
+ + VDSO_LDFLAGS_vdsox32.lds = -m elf32_x86_64 -soname linux-vdso.so.1 \
299
+ + -z max-page-size=4096 -z common-page-size=4096
300
+
301
+ # 64-bit objects to re-brand as x32
302
+ vobjs64-for-x32 := $(filter-out $(vobjs-nox32),$(vobjs-y))
303
+ @@ -121,7 +117,7 @@ $(obj)/vdsox32.so.dbg: $(src)/vdsox32.lds $(vobjx32s) FORCE
304
+ $(call if_changed,vdso)
305
+
306
+ CPPFLAGS_vdso32.lds = $(CPPFLAGS_vdso.lds)
307
+ - VDSO_LDFLAGS_vdso32.lds = -m32 -Wl,-m,elf_i386 -Wl,-soname=linux-gate.so.1
308
+ + VDSO_LDFLAGS_vdso32.lds = -m elf_i386 -soname linux-gate.so.1
309
+
310
+ # This makes sure the $(obj) subdirectory exists even though vdso32/
311
+ # is not a kbuild sub-make subdirectory.
312
+ @@ -157,13 +153,13 @@ $(obj)/vdso32.so.dbg: FORCE \
313
+ # The DSO images are built using a special linker script.
314
+ #
315
+ quiet_cmd_vdso = VDSO $@
316
+ - cmd_vdso = $(CC) -nostdlib -o $@ \
317
+ + cmd_vdso = $(LD) -nostdlib -o $@ \
318
+ $(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \
319
+ - -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
320
+ + -T $(filter %.lds,$^) $(filter %.o,$^) && \
321
+ sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
322
+
323
+ - VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=both) \
324
+ - $(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic $(LTO_CFLAGS)
325
+ + VDSO_LDFLAGS = -shared $(call ld-option, --hash-style=both) \
326
+ + $(call ld-option, --build-id) -Bsymbolic
327
+ GCOV_PROFILE := n
328
+
329
+ #
330
+ - -
331
+ 2.21.0
332
+
333
+
334
+ From b22299ee0b94b2e2ed1492d38631a05492e42c63 Mon Sep 17 00:00:00 2001
335
+ From: Nick Desaulniers <
[email protected] >
336
+ Date: Thu, 6 Dec 2018 11:12:31 -0800
337
+ Subject: [PATCH 5/5] x86/vdso: Drop implicit common-page-size linker flag
338
+
339
+ commit ac3e233d29f7f77f28243af0132057d378d3ea58 upstream.
340
+
341
+ GNU linker's -z common-page-size's default value is based on the target
342
+ architecture. arch/x86/entry/vdso/Makefile sets it to the architecture
343
+ default, which is implicit and redundant. Drop it.
344
+
345
+ Fixes: 2aae950b21e4 ("x86_64: Add vDSO for x86-64 with gettimeofday/clock_gettime/getcpu")
346
+ Reported-by: Dmitry Golovin <
[email protected] >
347
+ Reported-by: Bill Wendling <
[email protected] >
348
+ Suggested-by: Dmitry Golovin <
[email protected] >
349
+ Suggested-by: Rui Ueyama <
[email protected] >
350
+ Signed-off-by: Nick Desaulniers <
[email protected] >
351
+ Signed-off-by: Borislav Petkov <
[email protected] >
352
+ Acked-by: Andy Lutomirski <
[email protected] >
353
+ Cc: Andi Kleen <
[email protected] >
354
+ Cc: Fangrui Song <
[email protected] >
355
+ Cc: "H. Peter Anvin" <
[email protected] >
356
+ Cc: Ingo Molnar <
[email protected] >
357
+ Cc: Thomas Gleixner <
[email protected] >
358
+
359
+ Link: https://lkml.kernel.org/r/
[email protected]
360
+ Link: https://bugs.llvm.org/show_bug.cgi?id=38774
361
+ Link: https://github.com/ClangBuiltLinux/linux/issues/31
362
+ Signed-off-by: Nathan Chancellor <
[email protected] >
363
+ ---
364
+ arch/x86/entry/vdso/Makefile | 4 ++--
365
+ 1 file changed, 2 insertions(+), 2 deletions(-)
366
+
367
+ diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vdso/Makefile
368
+ index 84c4a7105c2a..297dda4d5947 100644
369
+ --- a/arch/x86/entry/vdso/Makefile
370
+ +++ b/arch/x86/entry/vdso/Makefile
371
+ @@ -42,7 +42,7 @@ targets += $(vdso_img_sodbg)
372
+ export CPPFLAGS_vdso.lds += -P -C
373
+
374
+ VDSO_LDFLAGS_vdso.lds = -m elf_x86_64 -soname linux-vdso.so.1 --no-undefined \
375
+ - -z max-page-size=4096 -z common-page-size=4096
376
+ + -z max-page-size=4096
377
+
378
+ $(obj)/vdso64.so.dbg: $(src)/vdso.lds $(vobjs) FORCE
379
+ $(call if_changed,vdso)
380
+ @@ -89,7 +89,7 @@ CFLAGS_REMOVE_vvar.o = -pg
381
+
382
+ CPPFLAGS_vdsox32.lds = $(CPPFLAGS_vdso.lds)
383
+ VDSO_LDFLAGS_vdsox32.lds = -m elf32_x86_64 -soname linux-vdso.so.1 \
384
+ - -z max-page-size=4096 -z common-page-size=4096
385
+ + -z max-page-size=4096
386
+
387
+ # 64-bit objects to re-brand as x32
388
+ vobjs64-for-x32 := $(filter-out $(vobjs-nox32),$(vobjs-y))
389
+ - -
390
+ 2.21.0
0 commit comments