Skip to content

Commit 0d75977

Browse files
jpoimboeIngo Molnar
authored andcommitted
objtool: Ignore end-of-section jumps for KCOV/GCOV
When KCOV or GCOV is enabled, dead code can be left behind, in which case objtool silences unreachable and undefined behavior (fallthrough) warnings. Fallthrough warnings, and their variant "end of section" warnings, were silenced with the following commit: 6b023c7 ("objtool: Silence more KCOV warnings") Another variant of a fallthrough warning is a jump to the end of a function. If that function happens to be at the end of a section, the jump destination doesn't actually exist. Normally that would be a fatal objtool error, but for KCOV/GCOV it's just another undefined behavior fallthrough. Silence it like the others. Fixes the following warning: drivers/iommu/dma-iommu.o: warning: objtool: iommu_dma_sw_msi+0x92: can't find jump dest instruction at .text+0x54d5 Fixes: 6b023c7 ("objtool: Silence more KCOV warnings") Reported-by: Randy Dunlap <rdunlap@infradead.org> Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Link: https://lore.kernel.org/r/08fbe7d7e1e20612206f1df253077b94f178d93e.1743481539.git.jpoimboe@kernel.org Closes: https://lore.kernel.org/314f8809-cd59-479b-97d7-49356bf1c8d1@infradead.org/
1 parent 55c7803 commit 0d75977

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

tools/objtool/check.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,6 +1488,8 @@ static int add_jump_destinations(struct objtool_file *file)
14881488
int ret;
14891489

14901490
for_each_insn(file, insn) {
1491+
struct symbol *func = insn_func(insn);
1492+
14911493
if (insn->jump_dest) {
14921494
/*
14931495
* handle_group_alt() may have previously set
@@ -1513,7 +1515,7 @@ static int add_jump_destinations(struct objtool_file *file)
15131515
} else if (reloc->sym->return_thunk) {
15141516
add_return_call(file, insn, true);
15151517
continue;
1516-
} else if (insn_func(insn)) {
1518+
} else if (func) {
15171519
/*
15181520
* External sibling call or internal sibling call with
15191521
* STT_FUNC reloc.
@@ -1548,6 +1550,15 @@ static int add_jump_destinations(struct objtool_file *file)
15481550
continue;
15491551
}
15501552

1553+
/*
1554+
* GCOV/KCOV dead code can jump to the end of the
1555+
* function/section.
1556+
*/
1557+
if (file->ignore_unreachables && func &&
1558+
dest_sec == insn->sec &&
1559+
dest_off == func->offset + func->len)
1560+
continue;
1561+
15511562
WARN_INSN(insn, "can't find jump dest instruction at %s+0x%lx",
15521563
dest_sec->name, dest_off);
15531564
return -1;
@@ -1574,8 +1585,7 @@ static int add_jump_destinations(struct objtool_file *file)
15741585
/*
15751586
* Cross-function jump.
15761587
*/
1577-
if (insn_func(insn) && insn_func(jump_dest) &&
1578-
insn_func(insn) != insn_func(jump_dest)) {
1588+
if (func && insn_func(jump_dest) && func != insn_func(jump_dest)) {
15791589

15801590
/*
15811591
* For GCC 8+, create parent/child links for any cold
@@ -1592,10 +1602,10 @@ static int add_jump_destinations(struct objtool_file *file)
15921602
* case where the parent function's only reference to a
15931603
* subfunction is through a jump table.
15941604
*/
1595-
if (!strstr(insn_func(insn)->name, ".cold") &&
1605+
if (!strstr(func->name, ".cold") &&
15961606
strstr(insn_func(jump_dest)->name, ".cold")) {
1597-
insn_func(insn)->cfunc = insn_func(jump_dest);
1598-
insn_func(jump_dest)->pfunc = insn_func(insn);
1607+
func->cfunc = insn_func(jump_dest);
1608+
insn_func(jump_dest)->pfunc = func;
15991609
}
16001610
}
16011611

0 commit comments

Comments
 (0)