summaryrefslogtreecommitdiffstats
path: root/recipes-kernel/linux/linux-intel/objtool-fix-segfault-with-clang.patch
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-kernel/linux/linux-intel/objtool-fix-segfault-with-clang.patch')
-rw-r--r--recipes-kernel/linux/linux-intel/objtool-fix-segfault-with-clang.patch150
1 files changed, 0 insertions, 150 deletions
diff --git a/recipes-kernel/linux/linux-intel/objtool-fix-segfault-with-clang.patch b/recipes-kernel/linux/linux-intel/objtool-fix-segfault-with-clang.patch
deleted file mode 100644
index f4b1374f..00000000
--- a/recipes-kernel/linux/linux-intel/objtool-fix-segfault-with-clang.patch
+++ /dev/null
@@ -1,150 +0,0 @@
1From 44f6a7c0755d8dd453c70557e11687bb080a6f21 Mon Sep 17 00:00:00 2001
2From: Josh Poimboeuf <jpoimboe@redhat.com>
3Date: Mon, 14 Dec 2020 16:04:20 -0600
4Subject: [PATCH] objtool: Fix seg fault with Clang non-section symbols
5
6The Clang assembler likes to strip section symbols, which means objtool
7can't reference some text code by its section. This confuses objtool
8greatly, causing it to seg fault.
9
10The fix is similar to what was done before, for ORC reloc generation:
11
12 e81e07244325 ("objtool: Support Clang non-section symbols in ORC generation")
13
14Factor out that code into a common helper and use it for static call
15reloc generation as well.
16
17Reported-by: Arnd Bergmann <arnd@kernel.org>
18Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
19Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
20Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
21Reviewed-by: Miroslav Benes <mbenes@suse.cz>
22Link: https://github.com/ClangBuiltLinux/linux/issues/1207
23Link: https://lkml.kernel.org/r/ba6b6c0f0dd5acbba66e403955a967d9fdd1726a.1607983452.git.jpoimboe@redhat.com
24
25Upstream-Status: Backport
26Signed-off-by: Anuj Mittal <anuj.mittal@intel.com>
27---
28 tools/objtool/check.c | 11 +++++++++--
29 tools/objtool/elf.c | 26 ++++++++++++++++++++++++++
30 tools/objtool/elf.h | 2 ++
31 tools/objtool/orc_gen.c | 29 +++++------------------------
32 4 files changed, 42 insertions(+), 26 deletions(-)
33
34diff --git a/tools/objtool/check.c b/tools/objtool/check.c
35index c6ab44543c92a..5f8d3eed78a18 100644
36--- a/tools/objtool/check.c
37+++ b/tools/objtool/check.c
38@@ -467,13 +467,20 @@ static int create_static_call_sections(struct objtool_file *file)
39
40 /* populate reloc for 'addr' */
41 reloc = malloc(sizeof(*reloc));
42+
43 if (!reloc) {
44 perror("malloc");
45 return -1;
46 }
47 memset(reloc, 0, sizeof(*reloc));
48- reloc->sym = insn->sec->sym;
49- reloc->addend = insn->offset;
50+
51+ insn_to_reloc_sym_addend(insn->sec, insn->offset, reloc);
52+ if (!reloc->sym) {
53+ WARN_FUNC("static call tramp: missing containing symbol",
54+ insn->sec, insn->offset);
55+ return -1;
56+ }
57+
58 reloc->type = R_X86_64_PC32;
59 reloc->offset = idx * sizeof(struct static_call_site);
60 reloc->sec = reloc_sec;
61diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
62index 4e1d7460574b4..be89c741ba9a0 100644
63--- a/tools/objtool/elf.c
64+++ b/tools/objtool/elf.c
65@@ -262,6 +262,32 @@ struct reloc *find_reloc_by_dest(const struct elf *elf, struct section *sec, uns
66 return find_reloc_by_dest_range(elf, sec, offset, 1);
67 }
68
69+void insn_to_reloc_sym_addend(struct section *sec, unsigned long offset,
70+ struct reloc *reloc)
71+{
72+ if (sec->sym) {
73+ reloc->sym = sec->sym;
74+ reloc->addend = offset;
75+ return;
76+ }
77+
78+ /*
79+ * The Clang assembler strips section symbols, so we have to reference
80+ * the function symbol instead:
81+ */
82+ reloc->sym = find_symbol_containing(sec, offset);
83+ if (!reloc->sym) {
84+ /*
85+ * Hack alert. This happens when we need to reference the NOP
86+ * pad insn immediately after the function.
87+ */
88+ reloc->sym = find_symbol_containing(sec, offset - 1);
89+ }
90+
91+ if (reloc->sym)
92+ reloc->addend = offset - reloc->sym->offset;
93+}
94+
95 static int read_sections(struct elf *elf)
96 {
97 Elf_Scn *s = NULL;
98diff --git a/tools/objtool/elf.h b/tools/objtool/elf.h
99index 807f8c6700974..e6890cc70a25b 100644
100--- a/tools/objtool/elf.h
101+++ b/tools/objtool/elf.h
102@@ -140,6 +140,8 @@ struct reloc *find_reloc_by_dest(const struct elf *elf, struct section *sec, uns
103 struct reloc *find_reloc_by_dest_range(const struct elf *elf, struct section *sec,
104 unsigned long offset, unsigned int len);
105 struct symbol *find_func_containing(struct section *sec, unsigned long offset);
106+void insn_to_reloc_sym_addend(struct section *sec, unsigned long offset,
107+ struct reloc *reloc);
108 int elf_rebuild_reloc_section(struct elf *elf, struct section *sec);
109
110 #define for_each_sec(file, sec) \
111diff --git a/tools/objtool/orc_gen.c b/tools/objtool/orc_gen.c
112index 235663b96adc7..9ce68b385a1b8 100644
113--- a/tools/objtool/orc_gen.c
114+++ b/tools/objtool/orc_gen.c
115@@ -105,30 +105,11 @@ static int create_orc_entry(struct elf *elf, struct section *u_sec, struct secti
116 }
117 memset(reloc, 0, sizeof(*reloc));
118
119- if (insn_sec->sym) {
120- reloc->sym = insn_sec->sym;
121- reloc->addend = insn_off;
122- } else {
123- /*
124- * The Clang assembler doesn't produce section symbols, so we
125- * have to reference the function symbol instead:
126- */
127- reloc->sym = find_symbol_containing(insn_sec, insn_off);
128- if (!reloc->sym) {
129- /*
130- * Hack alert. This happens when we need to reference
131- * the NOP pad insn immediately after the function.
132- */
133- reloc->sym = find_symbol_containing(insn_sec,
134- insn_off - 1);
135- }
136- if (!reloc->sym) {
137- WARN("missing symbol for insn at offset 0x%lx\n",
138- insn_off);
139- return -1;
140- }
141-
142- reloc->addend = insn_off - reloc->sym->offset;
143+ insn_to_reloc_sym_addend(insn_sec, insn_off, reloc);
144+ if (!reloc->sym) {
145+ WARN("missing symbol for insn at offset 0x%lx",
146+ insn_off);
147+ return -1;
148 }
149
150 reloc->type = R_X86_64_PC32;