Skip to contentSkip to conversation

objtool: Fix function fallthrough detection

PATCH New Josh Poimboeuf 2 participants 5 messages May 13, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover objtool: Fix function fallthrough detection

Patch 1 is a minor objtool cleanup which is a prereq for patch 2.

Patch 2 fixes objtool function fallthrough detection.

Josh Poimboeuf (2):
objtool: Don't use 'ignore' flag for fake jumps
objtool: Fix function fallthrough detection

 tools/objtool/check.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
Signature · 1 line
2.17.2
#1 lore raw

PATCH 1/2 objtool: Don't use ignore flag for fake jumps

The ignore flag is set on fake jumps in order to keep add_jump_destinations() from setting their jump_dest, since it already got set when the fake jump was created.

But using the ignore flag is a bit of a hack. It's normally used to skip validation of an instruction, which doesn't really make sense for fake jumps.

Also, after the next patch, using the ignore flag for fake jumps can trigger a false "why am I validating an ignored function?" warning.

Instead just add an explicit check in add_jump_destinations() to skip fake jumps.

---
 tools/objtool/check.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
tools/objtool/check.c +5 -3
index ac743a1d53ab..90226791df6b 100644
@@ -28,6 +28,8 @@
 #include <linux/hashtable.h>
 #include <linux/kernel.h>
 
+#define FAKE_JUMP_OFFSET -1
+
 struct alternative {
 	struct list_head list;
 	struct instruction *insn;
@@ -568,7 +570,7 @@ static int add_jump_destinations(struct objtool_file *file)
 		    insn->type != INSN_JUMP_UNCONDITIONAL)
 			continue;
 
-		if (insn->ignore)
+		if (insn->ignore || insn->offset == FAKE_JUMP_OFFSET)
 			continue;
 
 		rela = find_rela_by_dest_range(insn->sec, insn->offset,
@@ -745,10 +747,10 @@ static int handle_group_alt(struct objtool_file *file,
 		clear_insn_state(&fake_jump->state);
 
 		fake_jump->sec = special_alt->new_sec;
-		fake_jump->offset = -1;
+		fake_jump->offset = FAKE_JUMP_OFFSET;
 		fake_jump->type = INSN_JUMP_UNCONDITIONAL;
 		fake_jump->jump_dest = list_next_entry(last_orig_insn, list);
-		fake_jump->ignore = true;
+		fake_jump->func = orig_insn->func;
 	}
 
 	if (!special_alt->new_len) {
Signature · 1 line
2.17.2
#3 lore raw

PATCH 2/2 objtool: Fix function fallthrough detection

In reply to Josh Poimboeuf

When a function falls through to the next function due to a compiler bug, objtool prints some obscure warnings. For example:

drivers/regulator/core.o: warning: objtool: regulator_count_voltages()+0x95: return with modified stack frame drivers/regulator/core.o: warning: objtool: regulator_count_voltages()+0x0: stack state mismatch: cfa1=7+32 cfa2=7+8

Instead it should be printing:

drivers/regulator/core.o: warning: objtool: regulator_supply_is_couple() falls through to next function regulator_count_voltages()

This used to work, but was broken by the following commit:

13810435b9a7 ("objtool: Support GCC 8's cold subfunctions").

The padding nops at the end of a function aren't actually part of the function, as defined by the symbol table. So the 'func' variable in validate_branch() is getting cleared to NULL when a padding nop is encountered, breaking the fallthrough detection.

If the current instruction doesn't have a function associated with it, just consider it to be part of the previously detected function by not overwriting the previous value of 'func'.

Fixes 13810435b9a7 ("objtool: Support GCC 8's cold subfunctions")
---
 tools/objtool/check.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/objtool/check.c +2 -1
index 90226791df6b..7325d89ccad9 100644
@@ -1959,7 +1959,8 @@ static int validate_branch(struct objtool_file *file, struct instruction *first,
 			return 1;
 		}
 
-		func = insn->func ? insn->func->pfunc : NULL;
+		if (insn->func)
+			func = insn->func->pfunc;
 
 		if (func && insn->ignore) {
 			WARN_FUNC("BUG: why am I validating an ignored function?",
Signature · 1 line
2.17.2
#2 lore raw

[tip:core/urgent] objtool: Don't use ignore flag for fake jumps

In reply to Josh Poimboeuf
objtool: Don't use ignore flag for fake jumps
Commit-ID:  e6da9567959e164f82bc81967e0d5b10dee870b4
Gitweb:     https://git.kernel.org/tip/e6da9567959e164f82bc81967e0d5b10dee870b4
Author:     Josh Poimboeuf <[email protected]>
AuthorDate: Mon, 13 May 2019 12:01:31 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 13 May 2019 20:31:17 +0200

objtool: Don't use ignore flag for fake jumps

The ignore flag is set on fake jumps in order to keep add_jump_destinations() from setting their jump_dest, since it already got set when the fake jump was created.

But using the ignore flag is a bit of a hack. It's normally used to skip validation of an instruction, which doesn't really make sense for fake jumps.

Also, after the next patch, using the ignore flag for fake jumps can trigger a false "why am I validating an ignored function?" warning.

Instead just add an explicit check in add_jump_destinations() to skip fake jumps.

---
 tools/objtool/check.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
tools/objtool/check.c +5 -3
index ac743a1d53ab..90226791df6b 100644
@@ -28,6 +28,8 @@
 #include <linux/hashtable.h>
 #include <linux/kernel.h>
 
+#define FAKE_JUMP_OFFSET -1
+
 struct alternative {
 	struct list_head list;
 	struct instruction *insn;
@@ -568,7 +570,7 @@ static int add_jump_destinations(struct objtool_file *file)
 		    insn->type != INSN_JUMP_UNCONDITIONAL)
 			continue;
 
-		if (insn->ignore)
+		if (insn->ignore || insn->offset == FAKE_JUMP_OFFSET)
 			continue;
 
 		rela = find_rela_by_dest_range(insn->sec, insn->offset,
@@ -745,10 +747,10 @@ static int handle_group_alt(struct objtool_file *file,
 		clear_insn_state(&fake_jump->state);
 
 		fake_jump->sec = special_alt->new_sec;
-		fake_jump->offset = -1;
+		fake_jump->offset = FAKE_JUMP_OFFSET;
 		fake_jump->type = INSN_JUMP_UNCONDITIONAL;
 		fake_jump->jump_dest = list_next_entry(last_orig_insn, list);
-		fake_jump->ignore = true;
+		fake_jump->func = orig_insn->func;
 	}
 
 	if (!special_alt->new_len) {
#4 lore raw
In reply to Josh Poimboeuf
objtool: Fix function fallthrough detection
Commit-ID:  e6f393bc939d566ce3def71232d8013de9aaadde
Gitweb:     https://git.kernel.org/tip/e6f393bc939d566ce3def71232d8013de9aaadde
Author:     Josh Poimboeuf <[email protected]>
AuthorDate: Mon, 13 May 2019 12:01:32 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 13 May 2019 20:31:17 +0200

objtool: Fix function fallthrough detection

When a function falls through to the next function due to a compiler bug, objtool prints some obscure warnings. For example:

drivers/regulator/core.o: warning: objtool: regulator_count_voltages()+0x95: return with modified stack frame drivers/regulator/core.o: warning: objtool: regulator_count_voltages()+0x0: stack state mismatch: cfa1=7+32 cfa2=7+8

Instead it should be printing:

drivers/regulator/core.o: warning: objtool: regulator_supply_is_couple() falls through to next function regulator_count_voltages()

This used to work, but was broken by the following commit:

13810435b9a7 ("objtool: Support GCC 8's cold subfunctions")

The padding nops at the end of a function aren't actually part of the function, as defined by the symbol table. So the 'func' variable in validate_branch() is getting cleared to NULL when a padding nop is encountered, breaking the fallthrough detection.

If the current instruction doesn't have a function associated with it, just consider it to be part of the previously detected function by not overwriting the previous value of 'func'.

---
 tools/objtool/check.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/objtool/check.c +2 -1
index 90226791df6b..7325d89ccad9 100644
@@ -1959,7 +1959,8 @@ static int validate_branch(struct objtool_file *file, struct instruction *first,
 			return 1;
 		}
 
-		func = insn->func ? insn->func->pfunc : NULL;
+		if (insn->func)
+			func = insn->func->pfunc;
 
 		if (func && insn->ignore) {
 			WARN_FUNC("BUG: why am I validating an ignored function?",