Thread (14 messages) 14 messages, 2 authors, 14d ago

[PATCH v2 2/6] objtool: Set ELF_F_LAYOUT flag to preserve vmlinux segment layout

flat view
COOLING14d

From: Shivang Upadhyay <hidden>
Date: 2026-09-29 05:52:57
Also in: linux-kbuild, lkml
Subsystem: objtool, the rest · Maintainers: Josh Poimboeuf, Peter Zijlstra, Linus Torvalds

From: Sathvika Vasireddy <redacted>

When objtool writes changes back to vmlinux with --ftr-fixup --link,
libelf recalculates the file layout and inserts padding between
sections. This corrupts the ELF segment structure, causing kexec to
fail with:

    ELF Note corrupted !
    Cannot determine the file type of vmlinux

This happens because libelf's default behavior assumes it can freely
rearrange section offsets when writing, which breaks the carefully
constructed vmlinux layout produced by the linker.

Set ELF_F_LAYOUT after elf_begin() to instruct libelf that the
application is responsible for the file layout. This prevents libelf
from inserting padding or repositioning sections while still allowing
data modifications to be written back.

Signed-off-by: Sathvika Vasireddy <redacted>
Signed-off-by: Shivang Upadhyay <redacted>
---
 tools/objtool/elf.c | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index a791f4ea6ec1..55c20a993f5d 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -1239,6 +1239,9 @@ struct elf *elf_open_read(const char *name, int flags)
 		goto err;
 	}
 
+	if (opts.ftr_fixup)
+		elf_flagelf(elf->elf, ELF_C_SET, ELF_F_LAYOUT);
+
 	if (!gelf_getehdr(elf->elf, &elf->ehdr)) {
 		ERROR_ELF("gelf_getehdr");
 		goto err;
-- 
2.54.0

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help