From: Tianyi Liu <i.pear@outlook.com>
To: arnd@arndb.de
Cc: hjl.tools@gmail.com, linux-arch@vger.kernel.org,
linux-kernel@vger.kernel.org, bpf@vger.kernel.org,
Tianyi Liu <i.pear@outlook.com>
Subject: [PATCH] Discard .note.gnu.property in vmlinux
Date: Wed, 1 Mar 2023 14:22:32 +0800 [thread overview]
Message-ID: <SY4P282MB108446E9ED9FB180AE717D5F9DAD9@SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM> (raw)
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(-)
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
reply other threads:[~2023-03-01 6:23 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=SY4P282MB108446E9ED9FB180AE717D5F9DAD9@SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM \
--to=i.pear@outlook.com \
--cc=arnd@arndb.de \
--cc=bpf@vger.kernel.org \
--cc=hjl.tools@gmail.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®