Skip to content

Commit 97dab2a

Browse files
jpoimboeIngo Molnar
authored andcommitted
objtool: Fix object file corruption
Arnd Bergmann reported that a randconfig build was failing with the following link error: built-in.o: member arch/x86/kernel/time.o in archive is not an object It turns out the link failed because the time.o file had been corrupted by objtool: nm: arch/x86/kernel/time.o: File format not recognized In certain rare cases, when a .o file's ORC table is very small, the .data section size doesn't change because it's page aligned. Because all the existing sections haven't changed size, libelf doesn't detect any section header changes, and so it doesn't update the section header table properly. Instead it writes junk in the section header entries for the new ORC sections. Make sure libelf properly updates the section header table by setting the ELF_F_DIRTY flag in the top level elf struct. Reported-by: Arnd Bergmann <[email protected]> Signed-off-by: Josh Poimboeuf <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Fixes: 627fce1 ("objtool: Add ORC unwind table generation") Link: http://lkml.kernel.org/r/e650fd0f2d8a209d1409a9785deb101fdaed55fb.1505459813.git.jpoimboe@redhat.com Signed-off-by: Ingo Molnar <[email protected]>
1 parent df968c9 commit 97dab2a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

tools/objtool/elf.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,20 +563,25 @@ int elf_write(struct elf *elf)
563563
struct section *sec;
564564
Elf_Scn *s;
565565

566+
/* Update section headers for changed sections: */
566567
list_for_each_entry(sec, &elf->sections, list) {
567568
if (sec->changed) {
568569
s = elf_getscn(elf->elf, sec->idx);
569570
if (!s) {
570571
WARN_ELF("elf_getscn");
571572
return -1;
572573
}
573-
if (!gelf_update_shdr (s, &sec->sh)) {
574+
if (!gelf_update_shdr(s, &sec->sh)) {
574575
WARN_ELF("gelf_update_shdr");
575576
return -1;
576577
}
577578
}
578579
}
579580

581+
/* Make sure the new section header entries get updated properly. */
582+
elf_flagelf(elf->elf, ELF_C_SET, ELF_F_DIRTY);
583+
584+
/* Write all changes to the file. */
580585
if (elf_update(elf->elf, ELF_C_WRITE) < 0) {
581586
WARN_ELF("elf_update");
582587
return -1;

0 commit comments

Comments
 (0)