public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Julien Thierry <jthierry@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: jpoimboe@redhat.com, peterz@infradead.org, raphael.gault@arm.com,
	Julien Thierry <jthierry@redhat.com>
Subject: [PATCH v2 07/10] objtool: check: Allow save/restore hint in non standard function symbols
Date: Fri, 27 Mar 2020 15:28:44 +0000	[thread overview]
Message-ID: <20200327152847.15294-8-jthierry@redhat.com> (raw)
In-Reply-To: <20200327152847.15294-1-jthierry@redhat.com>

The kernel code base provides CODE_SYM_START/END to declare assembly
code sequences that don't follow function standard calling conventions.

As non-C/non-standard code, these sequences can very much benefit from
unwind hints. However, when a restore unwind_hint is used in a
non-function code sequence, objtool will crash when looking for the
corresponding save hint.

Record the code symbol an instruction belongs to and look for save hints
belonging to the same code symbol as the restore hint.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
---
 tools/objtool/check.c | 27 +++++++++++++++++++--------
 tools/objtool/check.h |  1 +
 2 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 65809c74f6a8..fb1ddde66b48 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -236,7 +236,7 @@ static void clear_insn_state(struct insn_state *state)
 static int decode_instructions(struct objtool_file *file)
 {
 	struct section *sec;
-	struct symbol *func;
+	struct symbol *sym;
 	unsigned long offset;
 	struct instruction *insn;
 	unsigned long nr_insns = 0;
@@ -278,18 +278,22 @@ static int decode_instructions(struct objtool_file *file)
 			nr_insns++;
 		}
 
-		list_for_each_entry(func, &sec->symbol_list, list) {
-			if (func->type != STT_FUNC || func->alias != func)
+		list_for_each_entry(sym, &sec->symbol_list, list) {
+			if ((sym->type != STT_FUNC && sym->type != STT_NOTYPE) ||
+			     sym->alias != sym)
 				continue;
 
-			if (!find_insn(file, sec, func->offset)) {
+			if (!find_insn(file, sec, sym->offset)) {
 				WARN("%s(): can't find starting instruction",
-				     func->name);
+				     sym->name);
 				return -1;
 			}
 
-			sym_for_each_insn(file, func, insn)
-				insn->func = func;
+			sym_for_each_insn(file, sym, insn) {
+				insn->code_sym = sym;
+				if (sym->type == STT_FUNC)
+					insn->func = sym;
+			}
 		}
 	}
 
@@ -758,6 +762,7 @@ static int handle_group_alt(struct objtool_file *file,
 		fake_jump->type = INSN_JUMP_UNCONDITIONAL;
 		fake_jump->jump_dest = list_next_entry(last_orig_insn, list);
 		fake_jump->func = orig_insn->func;
+		fake_jump->code_sym = orig_insn->code_sym;
 	}
 
 	if (!special_alt->new_len) {
@@ -2065,9 +2070,15 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,
 			if (insn->restore) {
 				struct instruction *save_insn, *i;
 
+				if (!insn->code_sym) {
+					WARN_FUNC("restore instruction doesn't belong to any symbol",
+						  insn->sec, insn->offset);
+					return 1;
+				}
+
 				i = insn;
 				save_insn = NULL;
-				sym_for_each_insn_continue_reverse(file, func, i) {
+				sym_for_each_insn_continue_reverse(file, insn->code_sym, i) {
 					if (i->save) {
 						save_insn = i;
 						break;
diff --git a/tools/objtool/check.h b/tools/objtool/check.h
index f0ce8ffe7135..d1b55961474c 100644
--- a/tools/objtool/check.h
+++ b/tools/objtool/check.h
@@ -42,6 +42,7 @@ struct instruction {
 	struct rela *jump_table;
 	struct list_head alts;
 	struct symbol *func;
+	struct symbol *code_sym;
 	struct stack_op stack_op;
 	struct insn_state state;
 	struct orc_entry orc;
-- 
2.21.1


  parent reply	other threads:[~2020-03-27 15:29 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-27 15:28 [PATCH v2 00/10] Objtool updates for easier portability Julien Thierry
2020-03-27 15:28 ` [PATCH v2 01/10] objtool: Move header sync-check ealier in build Julien Thierry
2020-04-01 12:32   ` Miroslav Benes
2020-04-01 12:44     ` Julien Thierry
2020-04-01 12:55       ` Miroslav Benes
2020-04-02 17:12   ` Josh Poimboeuf
2020-04-02 17:17     ` Josh Poimboeuf
2020-03-27 15:28 ` [PATCH v2 02/10] objtool: check: Remove redundant checks on operand type Julien Thierry
2020-03-27 15:28 ` [PATCH v2 03/10] objtool: check: Clean instruction state before each function validation Julien Thierry
2020-03-27 15:28 ` [PATCH v2 04/10] objtool: check: Ignore empty alternative groups Julien Thierry
2020-04-01 12:53   ` Miroslav Benes
2020-04-01 13:43     ` Julien Thierry
2020-04-01 13:48       ` Miroslav Benes
2020-03-27 15:28 ` [PATCH v2 05/10] objtool: check: Remove check preventing branches within alternative Julien Thierry
2020-05-01 18:22   ` [tip: objtool/core] objtool: " tip-bot2 for Julien Thierry
2020-03-27 15:28 ` [PATCH v2 06/10] objtool: check: Use arch specific values in restore_reg() Julien Thierry
2020-03-27 15:28 ` Julien Thierry [this message]
2020-04-01 13:54   ` [PATCH v2 07/10] objtool: check: Allow save/restore hint in non standard function symbols Miroslav Benes
2020-04-01 14:06     ` Julien Thierry
2020-03-27 15:28 ` [PATCH v2 08/10] objtool: Add abstraction for computation of symbols offsets Julien Thierry
2020-03-27 15:28 ` [PATCH v2 09/10] objtool: Split generic and arch specific CFI definitions Julien Thierry
2020-03-27 15:28 ` [PATCH v2 10/10] objtool: Support multiple stack_op per instruction Julien Thierry
2020-04-02 17:54   ` Josh Poimboeuf
2020-04-02 18:25     ` Peter Zijlstra
2020-04-03  8:01     ` Julien Thierry
2020-04-03 14:55       ` Josh Poimboeuf
2020-04-22 22:24   ` [tip: objtool/core] " tip-bot2 for Julien Thierry
2020-04-23  7:49   ` tip-bot2 for Julien Thierry
2020-04-23 11:15     ` Peter Zijlstra
2020-04-02 17:58 ` [PATCH v2 00/10] Objtool updates for easier portability Josh Poimboeuf
2020-04-02 18:30   ` Peter Zijlstra
2020-04-03  7:17     ` Miroslav Benes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200327152847.15294-8-jthierry@redhat.com \
    --to=jthierry@redhat.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=raphael.gault@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox