Skip to content

Commit bd841d6

Browse files
jpoimboesuryasaimadhu
authored andcommitted
objtool: Fix CONFIG_UBSAN_TRAP unreachable warnings
CONFIG_UBSAN_TRAP causes GCC to emit a UD2 whenever it encounters an unreachable code path. This includes __builtin_unreachable(). Because the BUG() macro uses __builtin_unreachable() after it emits its own UD2, this results in a double UD2. In this case objtool rightfully detects that the second UD2 is unreachable: init/main.o: warning: objtool: repair_env_string()+0x1c8: unreachable instruction We weren't able to figure out a way to get rid of the double UD2s, so just silence the warning. Reported-by: Randy Dunlap <[email protected]> Signed-off-by: Josh Poimboeuf <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Kees Cook <[email protected]> Reviewed-by: Miroslav Benes <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/6653ad73c6b59c049211bd7c11ed3809c20ee9f5.1585761021.git.jpoimboe@redhat.com
1 parent 8f3d9f3 commit bd841d6

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

tools/objtool/check.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2364,14 +2364,27 @@ static bool ignore_unreachable_insn(struct instruction *insn)
23642364
!strcmp(insn->sec->name, ".altinstr_aux"))
23652365
return true;
23662366

2367+
if (!insn->func)
2368+
return false;
2369+
2370+
/*
2371+
* CONFIG_UBSAN_TRAP inserts a UD2 when it sees
2372+
* __builtin_unreachable(). The BUG() macro has an unreachable() after
2373+
* the UD2, which causes GCC's undefined trap logic to emit another UD2
2374+
* (or occasionally a JMP to UD2).
2375+
*/
2376+
if (list_prev_entry(insn, list)->dead_end &&
2377+
(insn->type == INSN_BUG ||
2378+
(insn->type == INSN_JUMP_UNCONDITIONAL &&
2379+
insn->jump_dest && insn->jump_dest->type == INSN_BUG)))
2380+
return true;
2381+
23672382
/*
23682383
* Check if this (or a subsequent) instruction is related to
23692384
* CONFIG_UBSAN or CONFIG_KASAN.
23702385
*
23712386
* End the search at 5 instructions to avoid going into the weeds.
23722387
*/
2373-
if (!insn->func)
2374-
return false;
23752388
for (i = 0; i < 5; i++) {
23762389

23772390
if (is_kasan_insn(insn) || is_ubsan_insn(insn))

0 commit comments

Comments
 (0)