blob: c874772520db92a34c87b3568a8ad8f713cf6972 [file] [log] [blame]
Lorenz Brun942f5e22022-01-27 15:03:10 +01001From d2ab95a534255d8d54640c84d05e266171e07328 Mon Sep 17 00:00:00 2001
2From: "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---
58 include/asm-generic/vmlinux.lds.h | 7 +++++++
59 1 file changed, 7 insertions(+)
60
61diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
62index f2984af2b85b..851c48a3c031 100644
63--- a/include/asm-generic/vmlinux.lds.h
64+++ b/include/asm-generic/vmlinux.lds.h
65@@ -903,7 +903,14 @@
66 #define PRINTK_INDEX
67 #endif
68
69+/*
70+ * Discard .note.gnu.property sections which are unused and have
71+ * different alignment requirement from kernel note sections.
72+ */
73 #define NOTES \
74+ /DISCARD/ : { \
75+ *(.note.gnu.property) \
76+ } \
77 .notes : AT(ADDR(.notes) - LOAD_OFFSET) { \
78 __start_notes = .; \
79 KEEP(*(.note.*)) \
80--
812.25.1
82