[PATCH] Discard .note.gnu.property in vmlinux

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxx/
[2] https://lore.kernel.org/linux-arm-kernel/20210428172847.GC4022@xxxxxxx/
[3] https://lore.kernel.org/lkml/20180924201459.35923-1-hjl.tools@xxxxxxxxx/

Signed-off-by: Tianyi Liu <i.pear@xxxxxxxxxxx>
---
 include/asm-generic/vmlinux.lds.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index d1f57e4868ed..6db0f664c7d6 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -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							\
-- 
2.39.2




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux