]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.14.112/x86-vdso-use-ld-instead-of-cc-to-link.patch
Linux 4.9.169
[thirdparty/kernel/stable-queue.git] / releases / 4.14.112 / x86-vdso-use-ld-instead-of-cc-to-link.patch
1 From 71b2ce1b044539753bbca8628860162b0c53c4f6 Mon Sep 17 00:00:00 2001
2 From: Alistair Strachan <astrachan@google.com>
3 Date: Fri, 3 Aug 2018 10:39:31 -0700
4 Subject: x86: vdso: Use $LD instead of $CC to link
5
6 commit 379d98ddf41344273d9718556f761420f4dc80b3 upstream.
7
8 The vdso{32,64}.so can fail to link with CC=clang when clang tries to find
9 a suitable GCC toolchain to link these libraries with.
10
11 /usr/bin/ld: arch/x86/entry/vdso/vclock_gettime.o:
12 access beyond end of merged section (782)
13
14 This happens because the host environment leaked into the cross compiler
15 environment due to the way clang searches for suitable GCC toolchains.
16
17 Clang is a retargetable compiler, and each invocation of it must provide
18 --target=<something> --gcc-toolchain=<something> to allow it to find the
19 correct binutils for cross compilation. These flags had been added to
20 KBUILD_CFLAGS, but the vdso code uses CC and not KBUILD_CFLAGS (for various
21 reasons) which breaks clang's ability to find the correct linker when cross
22 compiling.
23
24 Most of the time this goes unnoticed because the host linker is new enough
25 to work anyway, or is incompatible and skipped, but this cannot be reliably
26 assumed.
27
28 This change alters the vdso makefile to just use LD directly, which
29 bypasses clang and thus the searching problem. The makefile will just use
30 ${CROSS_COMPILE}ld instead, which is always what we want. This matches the
31 method used to link vmlinux.
32
33 This drops references to DISABLE_LTO; this option doesn't seem to be set
34 anywhere, and not knowing what its possible values are, it's not clear how
35 to convert it from CC to LD flag.
36
37 Signed-off-by: Alistair Strachan <astrachan@google.com>
38 Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
39 Acked-by: Andy Lutomirski <luto@kernel.org>
40 Cc: "H. Peter Anvin" <hpa@zytor.com>
41 Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
42 Cc: kernel-team@android.com
43 Cc: joel@joelfernandes.org
44 Cc: Andi Kleen <andi.kleen@intel.com>
45 Link: https://lkml.kernel.org/r/20180803173931.117515-1-astrachan@google.com
46 Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
47 Signed-off-by: Sasha Levin <sashal@kernel.org>
48 ---
49 arch/x86/entry/vdso/Makefile | 22 +++++++++-------------
50 1 file changed, 9 insertions(+), 13 deletions(-)
51
52 diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vdso/Makefile
53 index 0a550dc5c525..0defcc939ab4 100644
54 --- a/arch/x86/entry/vdso/Makefile
55 +++ b/arch/x86/entry/vdso/Makefile
56 @@ -48,10 +48,8 @@ targets += $(vdso_img_sodbg)
57
58 export CPPFLAGS_vdso.lds += -P -C
59
60 -VDSO_LDFLAGS_vdso.lds = -m64 -Wl,-soname=linux-vdso.so.1 \
61 - -Wl,--no-undefined \
62 - -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096 \
63 - $(DISABLE_LTO)
64 +VDSO_LDFLAGS_vdso.lds = -m elf_x86_64 -soname linux-vdso.so.1 --no-undefined \
65 + -z max-page-size=4096 -z common-page-size=4096
66
67 $(obj)/vdso64.so.dbg: $(src)/vdso.lds $(vobjs) FORCE
68 $(call if_changed,vdso)
69 @@ -103,10 +101,8 @@ CFLAGS_REMOVE_vvar.o = -pg
70 #
71
72 CPPFLAGS_vdsox32.lds = $(CPPFLAGS_vdso.lds)
73 -VDSO_LDFLAGS_vdsox32.lds = -Wl,-m,elf32_x86_64 \
74 - -Wl,-soname=linux-vdso.so.1 \
75 - -Wl,-z,max-page-size=4096 \
76 - -Wl,-z,common-page-size=4096
77 +VDSO_LDFLAGS_vdsox32.lds = -m elf32_x86_64 -soname linux-vdso.so.1 \
78 + -z max-page-size=4096 -z common-page-size=4096
79
80 # 64-bit objects to re-brand as x32
81 vobjs64-for-x32 := $(filter-out $(vobjs-nox32),$(vobjs-y))
82 @@ -134,7 +130,7 @@ $(obj)/vdsox32.so.dbg: $(src)/vdsox32.lds $(vobjx32s) FORCE
83 $(call if_changed,vdso)
84
85 CPPFLAGS_vdso32.lds = $(CPPFLAGS_vdso.lds)
86 -VDSO_LDFLAGS_vdso32.lds = -m32 -Wl,-m,elf_i386 -Wl,-soname=linux-gate.so.1
87 +VDSO_LDFLAGS_vdso32.lds = -m elf_i386 -soname linux-gate.so.1
88
89 # This makes sure the $(obj) subdirectory exists even though vdso32/
90 # is not a kbuild sub-make subdirectory.
91 @@ -180,13 +176,13 @@ $(obj)/vdso32.so.dbg: FORCE \
92 # The DSO images are built using a special linker script.
93 #
94 quiet_cmd_vdso = VDSO $@
95 - cmd_vdso = $(CC) -nostdlib -o $@ \
96 + cmd_vdso = $(LD) -nostdlib -o $@ \
97 $(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \
98 - -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
99 + -T $(filter %.lds,$^) $(filter %.o,$^) && \
100 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
101
102 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=both) \
103 - $(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic $(LTO_CFLAGS)
104 +VDSO_LDFLAGS = -shared $(call ld-option, --hash-style=both) \
105 + $(call ld-option, --build-id) -Bsymbolic
106 GCOV_PROFILE := n
107
108 #
109 --
110 2.19.1
111