Skip to content

Commit 0bcba95

Browse files
jpoimboegregkh
authored andcommitted
objtool: Support GCC 8 '-fnoreorder-functions'
[ Upstream commit 08b393d ] Since the following commit: cd77849 ("objtool: Fix GCC 8 cold subfunction detection for aliased functions") ... if the kernel is built with EXTRA_CFLAGS='-fno-reorder-functions', objtool can get stuck in an infinite loop. That flag causes the new GCC 8 cold subfunctions to be placed in .text instead of .text.unlikely. But it also has an unfortunate quirk: in the symbol table, the subfunction (e.g., nmi_panic.cold.7) is nested inside the parent (nmi_panic). That function overlap confuses objtool, and causes it to get into an infinite loop in next_insn_same_func(). Here's Allan's description of the loop: "Objtool iterates through the instructions in nmi_panic using next_insn_same_func. Once it reaches the end of nmi_panic at 0x534 it jumps to 0x528 as that's the start of nmi_panic.cold.7. However, since the instructions starting at 0x528 are still associated with nmi_panic objtool will get stuck in a loop, continually jumping back to 0x528 after reaching 0x534." Fix it by shortening the length of the parent function so that the functions no longer overlap. Reported-and-analyzed-by: Allan Xavier <[email protected]> Signed-off-by: Josh Poimboeuf <[email protected]> Cc: Allan Xavier <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Brian Gerst <[email protected]> Cc: Denys Vlasenko <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: http://lkml.kernel.org/r/9e704c52bee651129b036be14feda317ae5606ae.1530136978.git.jpoimboe@redhat.com Signed-off-by: Ingo Molnar <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent e793dc3 commit 0bcba95

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

tools/objtool/elf.c

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -302,19 +302,34 @@ static int read_symbols(struct elf *elf)
302302
continue;
303303
sym->pfunc = sym->cfunc = sym;
304304
coldstr = strstr(sym->name, ".cold.");
305-
if (coldstr) {
306-
coldstr[0] = '\0';
307-
pfunc = find_symbol_by_name(elf, sym->name);
308-
coldstr[0] = '.';
309-
310-
if (!pfunc) {
311-
WARN("%s(): can't find parent function",
312-
sym->name);
313-
goto err;
314-
}
315-
316-
sym->pfunc = pfunc;
317-
pfunc->cfunc = sym;
305+
if (!coldstr)
306+
continue;
307+
308+
coldstr[0] = '\0';
309+
pfunc = find_symbol_by_name(elf, sym->name);
310+
coldstr[0] = '.';
311+
312+
if (!pfunc) {
313+
WARN("%s(): can't find parent function",
314+
sym->name);
315+
goto err;
316+
}
317+
318+
sym->pfunc = pfunc;
319+
pfunc->cfunc = sym;
320+
321+
/*
322+
* Unfortunately, -fnoreorder-functions puts the child
323+
* inside the parent. Remove the overlap so we can
324+
* have sane assumptions.
325+
*
326+
* Note that pfunc->len now no longer matches
327+
* pfunc->sym.st_size.
328+
*/
329+
if (sym->sec == pfunc->sec &&
330+
sym->offset >= pfunc->offset &&
331+
sym->offset + sym->len == pfunc->offset + pfunc->len) {
332+
pfunc->len -= sym->len;
318333
}
319334
}
320335
}

0 commit comments

Comments
 (0)