diff options
Diffstat (limited to 'recipes-kernel')
4 files changed, 282 insertions, 2 deletions
diff --git a/recipes-kernel/linux/linux-intel-rt_5.10.bb b/recipes-kernel/linux/linux-intel-rt_5.10.bb index b1a32c1a..ae0f45f2 100644 --- a/recipes-kernel/linux/linux-intel-rt_5.10.bb +++ b/recipes-kernel/linux/linux-intel-rt_5.10.bb | |||
@@ -11,7 +11,9 @@ python () { | |||
11 | 11 | ||
12 | LIC_FILES_CHKSUM = "file://COPYING;md5=6bc538ed5bd9a7fc9398086aedcd7e46" | 12 | LIC_FILES_CHKSUM = "file://COPYING;md5=6bc538ed5bd9a7fc9398086aedcd7e46" |
13 | SRC_URI_append = " file://0001-menuconfig-mconf-cfg-Allow-specification-of-ncurses-.patch \ | 13 | SRC_URI_append = " file://0001-menuconfig-mconf-cfg-Allow-specification-of-ncurses-.patch \ |
14 | " | 14 | file://objtool-fix-segfault-with-clang.patch \ |
15 | file://x86-entry-Emit-a-symbol-for-register-restoring-thunk.patch \ | ||
16 | " | ||
15 | 17 | ||
16 | KBRANCH = "5.10/preempt-rt" | 18 | KBRANCH = "5.10/preempt-rt" |
17 | KMETA_BRANCH = "yocto-5.10" | 19 | KMETA_BRANCH = "yocto-5.10" |
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 new file mode 100644 index 00000000..f4b1374f --- /dev/null +++ b/recipes-kernel/linux/linux-intel/objtool-fix-segfault-with-clang.patch | |||
@@ -0,0 +1,150 @@ | |||
1 | From 44f6a7c0755d8dd453c70557e11687bb080a6f21 Mon Sep 17 00:00:00 2001 | ||
2 | From: Josh Poimboeuf <jpoimboe@redhat.com> | ||
3 | Date: Mon, 14 Dec 2020 16:04:20 -0600 | ||
4 | Subject: [PATCH] objtool: Fix seg fault with Clang non-section symbols | ||
5 | |||
6 | The Clang assembler likes to strip section symbols, which means objtool | ||
7 | can't reference some text code by its section. This confuses objtool | ||
8 | greatly, causing it to seg fault. | ||
9 | |||
10 | The 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 | |||
14 | Factor out that code into a common helper and use it for static call | ||
15 | reloc generation as well. | ||
16 | |||
17 | Reported-by: Arnd Bergmann <arnd@kernel.org> | ||
18 | Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com> | ||
19 | Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> | ||
20 | Reviewed-by: Nick Desaulniers <ndesaulniers@google.com> | ||
21 | Reviewed-by: Miroslav Benes <mbenes@suse.cz> | ||
22 | Link: https://github.com/ClangBuiltLinux/linux/issues/1207 | ||
23 | Link: https://lkml.kernel.org/r/ba6b6c0f0dd5acbba66e403955a967d9fdd1726a.1607983452.git.jpoimboe@redhat.com | ||
24 | |||
25 | Upstream-Status: Backport | ||
26 | Signed-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 | |||
34 | diff --git a/tools/objtool/check.c b/tools/objtool/check.c | ||
35 | index 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; | ||
61 | diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c | ||
62 | index 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; | ||
98 | diff --git a/tools/objtool/elf.h b/tools/objtool/elf.h | ||
99 | index 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) \ | ||
111 | diff --git a/tools/objtool/orc_gen.c b/tools/objtool/orc_gen.c | ||
112 | index 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; | ||
diff --git a/recipes-kernel/linux/linux-intel/x86-entry-Emit-a-symbol-for-register-restoring-thunk.patch b/recipes-kernel/linux/linux-intel/x86-entry-Emit-a-symbol-for-register-restoring-thunk.patch new file mode 100644 index 00000000..3cd07c0a --- /dev/null +++ b/recipes-kernel/linux/linux-intel/x86-entry-Emit-a-symbol-for-register-restoring-thunk.patch | |||
@@ -0,0 +1,125 @@ | |||
1 | From 5e6dca82bcaa49348f9e5fcb48df4881f6d6c4ae Mon Sep 17 00:00:00 2001 | ||
2 | From: Nick Desaulniers <ndesaulniers@google.com> | ||
3 | Date: Tue, 12 Jan 2021 11:46:24 -0800 | ||
4 | Subject: [PATCH] x86/entry: Emit a symbol for register restoring thunk | ||
5 | |||
6 | Arnd found a randconfig that produces the warning: | ||
7 | |||
8 | arch/x86/entry/thunk_64.o: warning: objtool: missing symbol for insn at | ||
9 | offset 0x3e | ||
10 | |||
11 | when building with LLVM_IAS=1 (Clang's integrated assembler). Josh | ||
12 | notes: | ||
13 | |||
14 | With the LLVM assembler not generating section symbols, objtool has no | ||
15 | way to reference this code when it generates ORC unwinder entries, | ||
16 | because this code is outside of any ELF function. | ||
17 | |||
18 | The limitation now being imposed by objtool is that all code must be | ||
19 | contained in an ELF symbol. And .L symbols don't create such symbols. | ||
20 | |||
21 | So basically, you can use an .L symbol *inside* a function or a code | ||
22 | segment, you just can't use the .L symbol to contain the code using a | ||
23 | SYM_*_START/END annotation pair. | ||
24 | |||
25 | Fangrui notes that this optimization is helpful for reducing image size | ||
26 | when compiling with -ffunction-sections and -fdata-sections. I have | ||
27 | observed on the order of tens of thousands of symbols for the kernel | ||
28 | images built with those flags. | ||
29 | |||
30 | A patch has been authored against GNU binutils to match this behavior | ||
31 | of not generating unused section symbols ([1]), so this will | ||
32 | also become a problem for users of GNU binutils once they upgrade to 2.36. | ||
33 | |||
34 | Omit the .L prefix on a label so that the assembler will emit an entry | ||
35 | into the symbol table for the label, with STB_LOCAL binding. This | ||
36 | enables objtool to generate proper unwind info here with LLVM_IAS=1 or | ||
37 | GNU binutils 2.36+. | ||
38 | |||
39 | [ bp: Massage commit message. ] | ||
40 | |||
41 | Reported-by: Arnd Bergmann <arnd@arndb.de> | ||
42 | Suggested-by: Josh Poimboeuf <jpoimboe@redhat.com> | ||
43 | Suggested-by: Borislav Petkov <bp@alien8.de> | ||
44 | Suggested-by: Mark Brown <broonie@kernel.org> | ||
45 | Signed-off-by: Nick Desaulniers <ndesaulniers@google.com> | ||
46 | Signed-off-by: Borislav Petkov <bp@suse.de> | ||
47 | Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> | ||
48 | Acked-by: Josh Poimboeuf <jpoimboe@redhat.com> | ||
49 | Link: https://lkml.kernel.org/r/20210112194625.4181814-1-ndesaulniers@google.com | ||
50 | Link: https://github.com/ClangBuiltLinux/linux/issues/1209 | ||
51 | Link: https://reviews.llvm.org/D93783 | ||
52 | Link: https://sourceware.org/binutils/docs/as/Symbol-Names.html | ||
53 | Link: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=d1bcae833b32f1408485ce69f844dcd7ded093a8 [1] | ||
54 | |||
55 | Upstream-Status: Backport | ||
56 | Signed-off-by: Anuj Mittal <anuj.mittal@intel.com> | ||
57 | --- | ||
58 | Documentation/asm-annotations.rst | 5 +++++ | ||
59 | arch/x86/entry/thunk_64.S | 8 ++++---- | ||
60 | include/linux/linkage.h | 5 +++++ | ||
61 | 3 files changed, 14 insertions(+), 4 deletions(-) | ||
62 | |||
63 | diff --git a/Documentation/asm-annotations.rst b/Documentation/asm-annotations.rst | ||
64 | index 32ea57483378d..76424e0431f4b 100644 | ||
65 | --- a/Documentation/asm-annotations.rst | ||
66 | +++ b/Documentation/asm-annotations.rst | ||
67 | @@ -100,6 +100,11 @@ Instruction Macros | ||
68 | ~~~~~~~~~~~~~~~~~~ | ||
69 | This section covers ``SYM_FUNC_*`` and ``SYM_CODE_*`` enumerated above. | ||
70 | |||
71 | +``objtool`` requires that all code must be contained in an ELF symbol. Symbol | ||
72 | +names that have a ``.L`` prefix do not emit symbol table entries. ``.L`` | ||
73 | +prefixed symbols can be used within a code region, but should be avoided for | ||
74 | +denoting a range of code via ``SYM_*_START/END`` annotations. | ||
75 | + | ||
76 | * ``SYM_FUNC_START`` and ``SYM_FUNC_START_LOCAL`` are supposed to be **the | ||
77 | most frequent markings**. They are used for functions with standard calling | ||
78 | conventions -- global and local. Like in C, they both align the functions to | ||
79 | diff --git a/arch/x86/entry/thunk_64.S b/arch/x86/entry/thunk_64.S | ||
80 | index ccd32877a3c41..c9a9fbf1655f3 100644 | ||
81 | --- a/arch/x86/entry/thunk_64.S | ||
82 | +++ b/arch/x86/entry/thunk_64.S | ||
83 | @@ -31,7 +31,7 @@ SYM_FUNC_START_NOALIGN(\name) | ||
84 | .endif | ||
85 | |||
86 | call \func | ||
87 | - jmp .L_restore | ||
88 | + jmp __thunk_restore | ||
89 | SYM_FUNC_END(\name) | ||
90 | _ASM_NOKPROBE(\name) | ||
91 | .endm | ||
92 | @@ -44,7 +44,7 @@ SYM_FUNC_END(\name) | ||
93 | #endif | ||
94 | |||
95 | #ifdef CONFIG_PREEMPTION | ||
96 | -SYM_CODE_START_LOCAL_NOALIGN(.L_restore) | ||
97 | +SYM_CODE_START_LOCAL_NOALIGN(__thunk_restore) | ||
98 | popq %r11 | ||
99 | popq %r10 | ||
100 | popq %r9 | ||
101 | @@ -56,6 +56,6 @@ SYM_CODE_START_LOCAL_NOALIGN(.L_restore) | ||
102 | popq %rdi | ||
103 | popq %rbp | ||
104 | ret | ||
105 | - _ASM_NOKPROBE(.L_restore) | ||
106 | -SYM_CODE_END(.L_restore) | ||
107 | + _ASM_NOKPROBE(__thunk_restore) | ||
108 | +SYM_CODE_END(__thunk_restore) | ||
109 | #endif | ||
110 | diff --git a/include/linux/linkage.h b/include/linux/linkage.h | ||
111 | index 5bcfbd972e970..dbf8506decca0 100644 | ||
112 | --- a/include/linux/linkage.h | ||
113 | +++ b/include/linux/linkage.h | ||
114 | @@ -178,6 +178,11 @@ | ||
115 | * Objtool generates debug info for both FUNC & CODE, but needs special | ||
116 | * annotations for each CODE's start (to describe the actual stack frame). | ||
117 | * | ||
118 | + * Objtool requires that all code must be contained in an ELF symbol. Symbol | ||
119 | + * names that have a .L prefix do not emit symbol table entries. .L | ||
120 | + * prefixed symbols can be used within a code region, but should be avoided for | ||
121 | + * denoting a range of code via ``SYM_*_START/END`` annotations. | ||
122 | + * | ||
123 | * ALIAS -- does not generate debug info -- the aliased function will | ||
124 | */ | ||
125 | |||
diff --git a/recipes-kernel/linux/linux-intel_5.10.bb b/recipes-kernel/linux/linux-intel_5.10.bb index caf2c899..585dea49 100644 --- a/recipes-kernel/linux/linux-intel_5.10.bb +++ b/recipes-kernel/linux/linux-intel_5.10.bb | |||
@@ -5,7 +5,10 @@ KMETA_BRANCH = "yocto-5.10" | |||
5 | 5 | ||
6 | LIC_FILES_CHKSUM = "file://COPYING;md5=6bc538ed5bd9a7fc9398086aedcd7e46" | 6 | LIC_FILES_CHKSUM = "file://COPYING;md5=6bc538ed5bd9a7fc9398086aedcd7e46" |
7 | 7 | ||
8 | SRC_URI_append = " file://0001-menuconfig-mconf-cfg-Allow-specification-of-ncurses-.patch" | 8 | SRC_URI_append = " file://0001-menuconfig-mconf-cfg-Allow-specification-of-ncurses-.patch \ |
9 | file://objtool-fix-segfault-with-clang.patch \ | ||
10 | file://x86-entry-Emit-a-symbol-for-register-restoring-thunk.patch \ | ||
11 | " | ||
9 | 12 | ||
10 | DEPENDS += "elfutils-native openssl-native util-linux-native" | 13 | DEPENDS += "elfutils-native openssl-native util-linux-native" |
11 | 14 | ||