blob: 44248be713e56004d9ce104d56e2df63952cda42 [file] [log] [blame]
Lorenz Brun50d39372023-03-27 22:20:15 +02001From c2b13908b9d655bf9a2baab256a8aaffa6e11565 Mon Sep 17 00:00:00 2001
Lorenz Brun942f5e22022-01-27 15:03:10 +01002From: "H.J. Lu" <hjl.tools@gmail.com>
3Date: Mon, 27 Apr 2020 18:49:00 -0700
4Subject: [PATCH] Discard .note.gnu.property sections in generic NOTES
5
6With the command-line option, -mx86-used-note=yes, the x86 assembler
7in binutils 2.32 and above generates a program property note in a note
8section, .note.gnu.property, to encode used x86 ISAs and features. But
9kernel linker script only contains a single NOTE segment:
10
11PHDRS {
12 text PT_LOAD FLAGS(5);
13 data PT_LOAD FLAGS(6);
14 percpu PT_LOAD FLAGS(6);
15 init PT_LOAD FLAGS(7);
16 note PT_NOTE FLAGS(0);
17}
18SECTIONS
19{
20...
21 .notes : AT(ADDR(.notes) - 0xffffffff80000000) { __start_notes = .; KEEP(*(.not
22e.*)) __stop_notes = .; } :text :note
23...
24}
25
26The NOTE segment generated by kernel linker script is aligned to 4 bytes.
27But .note.gnu.property section must be aligned to 8 bytes on x86-64 and
28we get
29
30[hjl@gnu-skx-1 linux]$ readelf -n vmlinux
31
32Displaying notes found in: .notes
33 Owner Data size Description
34 Xen 0x00000006 Unknown note type: (0x00000006)
35 description data: 6c 69 6e 75 78 00
36 Xen 0x00000004 Unknown note type: (0x00000007)
37 description data: 32 2e 36 00
38 xen-3.0 0x00000005 Unknown note type: (0x006e6558)
39 description data: 08 00 00 00 03
40readelf: Warning: note with invalid namesz and/or descsz found at offset 0x50
41readelf: Warning: type: 0xffffffff, namesize: 0x006e6558, descsize:
420x80000000, alignment: 8
43[hjl@gnu-skx-1 linux]$
44
45Since note.gnu.property section in kernel image is never used, this patch
46discards .note.gnu.property sections in kernel linker script by adding
47
48/DISCARD/ : {
49 *(.note.gnu.property)
50}
51
52before kernel NOTE segment in generic NOTES.
53
54Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
55Reviewed-by: Kees Cook <keescook@chromium.org>
56Rebased-by: Lorenz Brun <lorenz@monogon.tech>
57---
Lorenz Brun50d39372023-03-27 22:20:15 +020058 include/asm-generic/vmlinux.lds.h | 7 ++++++-
59 1 file changed, 6 insertions(+), 1 deletion(-)
Lorenz Brun942f5e22022-01-27 15:03:10 +010060
61diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
Lorenz Brun50d39372023-03-27 22:20:15 +020062index 8471717c5085..15c74f9a2999 100644
Lorenz Brun942f5e22022-01-27 15:03:10 +010063--- a/include/asm-generic/vmlinux.lds.h
64+++ b/include/asm-generic/vmlinux.lds.h
Lorenz Brun50d39372023-03-27 22:20:15 +020065@@ -906,9 +906,14 @@
66 /*
67 * Discard .note.GNU-stack, which is emitted as PROGBITS by the compiler.
68 * Otherwise, the type of .notes section would become PROGBITS instead of NOTES.
Lorenz Brun942f5e22022-01-27 15:03:10 +010069+ * Discard .note.gnu.property sections which are unused and have
70+ * different alignment requirement from kernel note sections.
Lorenz Brun50d39372023-03-27 22:20:15 +020071 */
Lorenz Brun942f5e22022-01-27 15:03:10 +010072 #define NOTES \
Lorenz Brun50d39372023-03-27 22:20:15 +020073- /DISCARD/ : { *(.note.GNU-stack) } \
74+ /DISCARD/ : { \
75+ *(.note.GNU-stack) \
Lorenz Brun942f5e22022-01-27 15:03:10 +010076+ *(.note.gnu.property) \
Lorenz Brun50d39372023-03-27 22:20:15 +020077+ } \
Lorenz Brun942f5e22022-01-27 15:03:10 +010078 .notes : AT(ADDR(.notes) - LOAD_OFFSET) { \
79 __start_notes = .; \
80 KEEP(*(.note.*)) \
81--
Lorenz Brun50d39372023-03-27 22:20:15 +0200822.39.2
Lorenz Brun942f5e22022-01-27 15:03:10 +010083