]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob
9b0a1ec94917230e959f1185abcc1b9fcb8e83f5
[thirdparty/kernel/stable-queue.git] /
1 From 466d696117db97802e4c2b2745f7af9c259ac92a Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Fri, 23 Oct 2020 21:50:47 -0700
4 Subject: RISC-V: Fix the VDSO symbol generaton for binutils-2.35+
5
6 From: Palmer Dabbelt <palmerdabbelt@google.com>
7
8 [ Upstream commit c2c81bb2f69138f902e1a58d3bef6ad97fb8a92c ]
9
10 We were relying on GNU ld's ability to re-link executable files in order
11 to extract our VDSO symbols. This behavior was deemed a bug as of
12 binutils-2.35 (specifically the binutils-gdb commit a87e1817a4 ("Have
13 the linker fail if any attempt to link in an executable is made."), but
14 as that has been backported to at least Debian's binutils-2.34 in may
15 manifest in other places.
16
17 The previous version of this was a bit of a mess: we were linking a
18 static executable version of the VDSO, containing only a subset of the
19 input symbols, which we then linked into the kernel. This worked, but
20 certainly wasn't a supported path through the toolchain. Instead this
21 new version parses the textual output of nm to produce a symbol table.
22 Both rely on near-zero addresses being linkable, but as we rely on weak
23 undefined symbols being linkable elsewhere I don't view this as a major
24 issue.
25
26 Fixes: e2c0cdfba7f6 ("RISC-V: User-facing API")
27 Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
28 Signed-off-by: Sasha Levin <sashal@kernel.org>
29 ---
30 arch/riscv/kernel/vdso/.gitignore | 1 +
31 arch/riscv/kernel/vdso/Makefile | 18 +++++++++---------
32 arch/riscv/kernel/vdso/so2s.sh | 6 ++++++
33 3 files changed, 16 insertions(+), 9 deletions(-)
34 create mode 100755 arch/riscv/kernel/vdso/so2s.sh
35
36 diff --git a/arch/riscv/kernel/vdso/.gitignore b/arch/riscv/kernel/vdso/.gitignore
37 index 11ebee9e4c1d6..3a19def868ecc 100644
38 --- a/arch/riscv/kernel/vdso/.gitignore
39 +++ b/arch/riscv/kernel/vdso/.gitignore
40 @@ -1,3 +1,4 @@
41 # SPDX-License-Identifier: GPL-2.0-only
42 vdso.lds
43 *.tmp
44 +vdso-syms.S
45 diff --git a/arch/riscv/kernel/vdso/Makefile b/arch/riscv/kernel/vdso/Makefile
46 index 7d6a94d45ec94..cb8f9e4cfcbf8 100644
47 --- a/arch/riscv/kernel/vdso/Makefile
48 +++ b/arch/riscv/kernel/vdso/Makefile
49 @@ -43,19 +43,14 @@ $(obj)/vdso.o: $(obj)/vdso.so
50 SYSCFLAGS_vdso.so.dbg = $(c_flags)
51 $(obj)/vdso.so.dbg: $(src)/vdso.lds $(obj-vdso) FORCE
52 $(call if_changed,vdsold)
53 +SYSCFLAGS_vdso.so.dbg = -shared -s -Wl,-soname=linux-vdso.so.1 \
54 + -Wl,--build-id -Wl,--hash-style=both
55
56 # We also create a special relocatable object that should mirror the symbol
57 # table and layout of the linked DSO. With ld --just-symbols we can then
58 # refer to these symbols in the kernel code rather than hand-coded addresses.
59 -
60 -SYSCFLAGS_vdso.so.dbg = -shared -s -Wl,-soname=linux-vdso.so.1 \
61 - -Wl,--build-id=sha1 -Wl,--hash-style=both
62 -$(obj)/vdso-dummy.o: $(src)/vdso.lds $(obj)/rt_sigreturn.o FORCE
63 - $(call if_changed,vdsold)
64 -
65 -LDFLAGS_vdso-syms.o := -r --just-symbols
66 -$(obj)/vdso-syms.o: $(obj)/vdso-dummy.o FORCE
67 - $(call if_changed,ld)
68 +$(obj)/vdso-syms.S: $(obj)/vdso.so FORCE
69 + $(call if_changed,so2s)
70
71 # strip rule for the .so file
72 $(obj)/%.so: OBJCOPYFLAGS := -S
73 @@ -73,6 +68,11 @@ quiet_cmd_vdsold = VDSOLD $@
74 $(patsubst %, -G __vdso_%, $(vdso-syms)) $@.tmp $@ && \
75 rm $@.tmp
76
77 +# Extracts symbol offsets from the VDSO, converting them into an assembly file
78 +# that contains the same symbols at the same offsets.
79 +quiet_cmd_so2s = SO2S $@
80 + cmd_so2s = $(NM) -D $< | $(srctree)/$(src)/so2s.sh > $@
81 +
82 # install commands for the unstripped file
83 quiet_cmd_vdso_install = INSTALL $@
84 cmd_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/vdso/$@
85 diff --git a/arch/riscv/kernel/vdso/so2s.sh b/arch/riscv/kernel/vdso/so2s.sh
86 new file mode 100755
87 index 0000000000000..e64cb6d9440e7
88 --- /dev/null
89 +++ b/arch/riscv/kernel/vdso/so2s.sh
90 @@ -0,0 +1,6 @@
91 +#!/bin/sh
92 +# SPDX-License-Identifier: GPL-2.0+
93 +# Copyright 2020 Palmer Dabbelt <palmerdabbelt@google.com>
94 +
95 +sed 's!\([0-9a-f]*\) T \([a-z0-9_]*\)\(@@LINUX_4.15\)*!.global \2\n.set \2,0x\1!' \
96 +| grep '^\.'
97 --
98 2.27.0
99