@@ -891,9 +891,13 @@
/*
* Discard .note.GNU-stack, which is emitted as PROGBITS by the compiler.
* Otherwise, the type of .notes section would become PROGBITS instead of NOTES.
+ *
+ * Discard .note.gnu.property, which is 8-byte aligned and emitted by the
+ * compiler. Otherwise, the .notes section will be 8-byte aligned and other
+ * notes cannot be read.
*/
#define NOTES \
- /DISCARD/ : { *(.note.GNU-stack) } \
+ /DISCARD/ : { *(.note.GNU-stack) *(.note.gnu.property) } \
.notes : AT(ADDR(.notes) - LOAD_OFFSET) { \
BOUNDED_SECTION_BY(.note.*, _notes) \
} NOTES_HEADERS \
When the kernel image is finally linked, all the notes are packed into a single .notes section, but these notes may have different alignments. binutils above 2.32 adds a ".note.gnu.property" section to the compiled output, which is 4-byte aligned on 32-bit, but 8-byte aligned on 64-bit. At present, the notes generated by both the ELFNOTE macro and the VDSO linker script are 4-byte aligned. So in a 64-bit kernel, packing segments with different alignments will cause LibElf and tools like readelf to crush or to read wrong values [1][2]. This patch discards ".note.gnu.property" from vmlinux. Note that H.J. Lu has submitted a similar patch in the past[3], but it was not merged. [1] https://lore.kernel.org/bpf/57830c30-cd77-40cf-9cd1-3bb608aa602e@app.fastmail.com/ [2] https://lore.kernel.org/linux-arm-kernel/20210428172847.GC4022@arm.com/ [3] https://lore.kernel.org/lkml/20180924201459.35923-1-hjl.tools@gmail.com/ Signed-off-by: Tianyi Liu <i.pear@outlook.com> --- include/asm-generic/vmlinux.lds.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)