Commit b490f453 authored by Miroslav Benes's avatar Miroslav Benes Committed by Peter Zijlstra

objtool: Move the IRET hack into the arch decoder

Quoting Julien:

  "And the other suggestion is my other email was that you don't even
  need to add INSN_EXCEPTION_RETURN. You can keep IRET as
  INSN_CONTEXT_SWITCH by default and x86 decoder lookups the symbol
  conaining an iret. If it's a function symbol, it can just set the type
  to INSN_OTHER so that it caries on to the next instruction after
  having handled the stack_op."
Suggested-by: default avatarJulien Thierry <jthierry@redhat.com>
Signed-off-by: default avatarMiroslav Benes <mbenes@suse.cz>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: default avatarMiroslav Benes <mbenes@suse.cz>
Acked-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
Link: https://lkml.kernel.org/r/20200428191659.913283807@infradead.org
parent b09fb65e
...@@ -19,7 +19,6 @@ enum insn_type { ...@@ -19,7 +19,6 @@ enum insn_type {
INSN_CALL, INSN_CALL,
INSN_CALL_DYNAMIC, INSN_CALL_DYNAMIC,
INSN_RETURN, INSN_RETURN,
INSN_EXCEPTION_RETURN,
INSN_CONTEXT_SWITCH, INSN_CONTEXT_SWITCH,
INSN_BUG, INSN_BUG,
INSN_NOP, INSN_NOP,
......
...@@ -94,6 +94,7 @@ int arch_decode_instruction(const struct elf *elf, const struct section *sec, ...@@ -94,6 +94,7 @@ int arch_decode_instruction(const struct elf *elf, const struct section *sec,
rex_x = 0, modrm = 0, modrm_mod = 0, modrm_rm = 0, rex_x = 0, modrm = 0, modrm_mod = 0, modrm_rm = 0,
modrm_reg = 0, sib = 0; modrm_reg = 0, sib = 0;
struct stack_op *op = NULL; struct stack_op *op = NULL;
struct symbol *sym;
x86_64 = is_x86_64(elf); x86_64 = is_x86_64(elf);
if (x86_64 == -1) if (x86_64 == -1)
...@@ -469,8 +470,12 @@ int arch_decode_instruction(const struct elf *elf, const struct section *sec, ...@@ -469,8 +470,12 @@ int arch_decode_instruction(const struct elf *elf, const struct section *sec,
break; break;
case 0xcf: /* iret */ case 0xcf: /* iret */
*type = INSN_EXCEPTION_RETURN; /*
* Handle sync_core(), which has an IRET to self.
* All other IRET are in STT_NONE entry code.
*/
sym = find_symbol_containing(sec, offset);
if (sym && sym->type == STT_FUNC) {
ADD_OP(op) { ADD_OP(op) {
/* add $40, %rsp */ /* add $40, %rsp */
op->src.type = OP_SRC_ADD; op->src.type = OP_SRC_ADD;
...@@ -480,6 +485,9 @@ int arch_decode_instruction(const struct elf *elf, const struct section *sec, ...@@ -480,6 +485,9 @@ int arch_decode_instruction(const struct elf *elf, const struct section *sec,
op->dest.reg = CFI_SP; op->dest.reg = CFI_SP;
} }
break; break;
}
/* fallthrough */
case 0xca: /* retf */ case 0xca: /* retf */
case 0xcb: /* retf */ case 0xcb: /* retf */
......
...@@ -2320,17 +2320,6 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, ...@@ -2320,17 +2320,6 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,
break; break;
case INSN_EXCEPTION_RETURN:
/*
* This handles x86's sync_core() case, where we use an
* IRET to self. All 'normal' IRET instructions are in
* STT_NOTYPE entry symbols.
*/
if (func)
break;
return 0;
case INSN_CONTEXT_SWITCH: case INSN_CONTEXT_SWITCH:
if (func && (!next_insn || !next_insn->hint)) { if (func && (!next_insn || !next_insn->hint)) {
WARN_FUNC("unsupported instruction in callable function", WARN_FUNC("unsupported instruction in callable function",
......
...@@ -61,7 +61,7 @@ static void rb_add(struct rb_root *tree, struct rb_node *node, ...@@ -61,7 +61,7 @@ static void rb_add(struct rb_root *tree, struct rb_node *node,
rb_insert_color(node, tree); rb_insert_color(node, tree);
} }
static struct rb_node *rb_find_first(struct rb_root *tree, const void *key, static struct rb_node *rb_find_first(const struct rb_root *tree, const void *key,
int (*cmp)(const void *key, const struct rb_node *)) int (*cmp)(const void *key, const struct rb_node *))
{ {
struct rb_node *node = tree->rb_node; struct rb_node *node = tree->rb_node;
...@@ -189,7 +189,7 @@ struct symbol *find_func_by_offset(struct section *sec, unsigned long offset) ...@@ -189,7 +189,7 @@ struct symbol *find_func_by_offset(struct section *sec, unsigned long offset)
return NULL; return NULL;
} }
struct symbol *find_symbol_containing(struct section *sec, unsigned long offset) struct symbol *find_symbol_containing(const struct section *sec, unsigned long offset)
{ {
struct rb_node *node; struct rb_node *node;
......
...@@ -124,7 +124,7 @@ struct section *find_section_by_name(const struct elf *elf, const char *name); ...@@ -124,7 +124,7 @@ struct section *find_section_by_name(const struct elf *elf, const char *name);
struct symbol *find_func_by_offset(struct section *sec, unsigned long offset); struct symbol *find_func_by_offset(struct section *sec, unsigned long offset);
struct symbol *find_symbol_by_offset(struct section *sec, unsigned long offset); struct symbol *find_symbol_by_offset(struct section *sec, unsigned long offset);
struct symbol *find_symbol_by_name(const struct elf *elf, const char *name); struct symbol *find_symbol_by_name(const struct elf *elf, const char *name);
struct symbol *find_symbol_containing(struct section *sec, unsigned long offset); struct symbol *find_symbol_containing(const struct section *sec, unsigned long offset);
struct rela *find_rela_by_dest(const struct elf *elf, struct section *sec, unsigned long offset); struct rela *find_rela_by_dest(const struct elf *elf, struct section *sec, unsigned long offset);
struct rela *find_rela_by_dest_range(const struct elf *elf, struct section *sec, struct rela *find_rela_by_dest_range(const struct elf *elf, struct section *sec,
unsigned long offset, unsigned int len); unsigned long offset, unsigned int len);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment