Skip to content

Commit 14db1f0

Browse files
ihalipjpoimboe
authored andcommitted
objtool: Ignore unreachable trap after call to noreturn functions
With CONFIG_UBSAN_TRAP enabled, the compiler may insert a trap instruction after a call to a noreturn function. In this case, objtool warns that the UD2 instruction is unreachable. This is a behavior seen with Clang, from the oldest version capable of building the mainline x64_64 kernel (9.0), to the latest experimental version (12.0). Objtool silences similar warnings (trap after dead end instructions), so so expand that check to include dead end functions. Cc: Nick Desaulniers <ndesaulniers@google.com> Cc: Rong Chen <rong.a.chen@intel.com> Cc: Marco Elver <elver@google.com> Cc: Philip Li <philip.li@intel.com> Cc: Borislav Petkov <bp@alien8.de> Cc: kasan-dev@googlegroups.com Cc: x86@kernel.org Cc: clang-built-linux@googlegroups.com BugLink: ClangBuiltLinux#1148 Link: https://lore.kernel.org/lkml/CAKwvOdmptEpi8fiOyWUo=AiZJiX+Z+VHJOM2buLPrWsMTwLnyw@mail.gmail.com Suggested-by: Nick Desaulniers <ndesaulniers@google.com> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com> Tested-by: Nick Desaulniers <ndesaulniers@google.com> Reported-by: kbuild test robot <lkp@intel.com> Signed-off-by: Ilie Halip <ilie.halip@gmail.com> Tested-by: Sedat Dilek <sedat.dilek@gmail.com> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
1 parent 2b232a2 commit 14db1f0

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

tools/objtool/check.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2638,9 +2638,10 @@ static bool is_ubsan_insn(struct instruction *insn)
26382638
"__ubsan_handle_builtin_unreachable"));
26392639
}
26402640

2641-
static bool ignore_unreachable_insn(struct instruction *insn)
2641+
static bool ignore_unreachable_insn(struct objtool_file *file, struct instruction *insn)
26422642
{
26432643
int i;
2644+
struct instruction *prev_insn;
26442645

26452646
if (insn->ignore || insn->type == INSN_NOP)
26462647
return true;
@@ -2668,8 +2669,11 @@ static bool ignore_unreachable_insn(struct instruction *insn)
26682669
* __builtin_unreachable(). The BUG() macro has an unreachable() after
26692670
* the UD2, which causes GCC's undefined trap logic to emit another UD2
26702671
* (or occasionally a JMP to UD2).
2672+
*
2673+
* It may also insert a UD2 after calling a __noreturn function.
26712674
*/
2672-
if (list_prev_entry(insn, list)->dead_end &&
2675+
prev_insn = list_prev_entry(insn, list);
2676+
if ((prev_insn->dead_end || dead_end_function(file, prev_insn->call_dest)) &&
26732677
(insn->type == INSN_BUG ||
26742678
(insn->type == INSN_JUMP_UNCONDITIONAL &&
26752679
insn->jump_dest && insn->jump_dest->type == INSN_BUG)))
@@ -2796,7 +2800,7 @@ static int validate_reachable_instructions(struct objtool_file *file)
27962800
return 0;
27972801

27982802
for_each_insn(file, insn) {
2799-
if (insn->visited || ignore_unreachable_insn(insn))
2803+
if (insn->visited || ignore_unreachable_insn(file, insn))
28002804
continue;
28012805

28022806
WARN_FUNC("unreachable instruction", insn->sec, insn->offset);

0 commit comments

Comments
 (0)