Skip to content

Commit b490f45

Browse files
mirabPeter Zijlstra
authored andcommitted
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: Julien Thierry <[email protected]> Signed-off-by: Miroslav Benes <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Miroslav Benes <[email protected]> Acked-by: Josh Poimboeuf <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent b09fb65 commit b490f45

File tree

5 files changed

+21
-25
lines changed

5 files changed

+21
-25
lines changed

tools/objtool/arch.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ enum insn_type {
1919
INSN_CALL,
2020
INSN_CALL_DYNAMIC,
2121
INSN_RETURN,
22-
INSN_EXCEPTION_RETURN,
2322
INSN_CONTEXT_SWITCH,
2423
INSN_BUG,
2524
INSN_NOP,

tools/objtool/arch/x86/decode.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ int arch_decode_instruction(const struct elf *elf, const struct section *sec,
9494
rex_x = 0, modrm = 0, modrm_mod = 0, modrm_rm = 0,
9595
modrm_reg = 0, sib = 0;
9696
struct stack_op *op = NULL;
97+
struct symbol *sym;
9798

9899
x86_64 = is_x86_64(elf);
99100
if (x86_64 == -1)
@@ -469,17 +470,24 @@ int arch_decode_instruction(const struct elf *elf, const struct section *sec,
469470
break;
470471

471472
case 0xcf: /* iret */
472-
*type = INSN_EXCEPTION_RETURN;
473-
474-
ADD_OP(op) {
475-
/* add $40, %rsp */
476-
op->src.type = OP_SRC_ADD;
477-
op->src.reg = CFI_SP;
478-
op->src.offset = 5*8;
479-
op->dest.type = OP_DEST_REG;
480-
op->dest.reg = CFI_SP;
473+
/*
474+
* Handle sync_core(), which has an IRET to self.
475+
* All other IRET are in STT_NONE entry code.
476+
*/
477+
sym = find_symbol_containing(sec, offset);
478+
if (sym && sym->type == STT_FUNC) {
479+
ADD_OP(op) {
480+
/* add $40, %rsp */
481+
op->src.type = OP_SRC_ADD;
482+
op->src.reg = CFI_SP;
483+
op->src.offset = 5*8;
484+
op->dest.type = OP_DEST_REG;
485+
op->dest.reg = CFI_SP;
486+
}
487+
break;
481488
}
482-
break;
489+
490+
/* fallthrough */
483491

484492
case 0xca: /* retf */
485493
case 0xcb: /* retf */

tools/objtool/check.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2320,17 +2320,6 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,
23202320

23212321
break;
23222322

2323-
case INSN_EXCEPTION_RETURN:
2324-
/*
2325-
* This handles x86's sync_core() case, where we use an
2326-
* IRET to self. All 'normal' IRET instructions are in
2327-
* STT_NOTYPE entry symbols.
2328-
*/
2329-
if (func)
2330-
break;
2331-
2332-
return 0;
2333-
23342323
case INSN_CONTEXT_SWITCH:
23352324
if (func && (!next_insn || !next_insn->hint)) {
23362325
WARN_FUNC("unsupported instruction in callable function",

tools/objtool/elf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static void rb_add(struct rb_root *tree, struct rb_node *node,
6161
rb_insert_color(node, tree);
6262
}
6363

64-
static struct rb_node *rb_find_first(struct rb_root *tree, const void *key,
64+
static struct rb_node *rb_find_first(const struct rb_root *tree, const void *key,
6565
int (*cmp)(const void *key, const struct rb_node *))
6666
{
6767
struct rb_node *node = tree->rb_node;
@@ -189,7 +189,7 @@ struct symbol *find_func_by_offset(struct section *sec, unsigned long offset)
189189
return NULL;
190190
}
191191

192-
struct symbol *find_symbol_containing(struct section *sec, unsigned long offset)
192+
struct symbol *find_symbol_containing(const struct section *sec, unsigned long offset)
193193
{
194194
struct rb_node *node;
195195

tools/objtool/elf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ struct section *find_section_by_name(const struct elf *elf, const char *name);
124124
struct symbol *find_func_by_offset(struct section *sec, unsigned long offset);
125125
struct symbol *find_symbol_by_offset(struct section *sec, unsigned long offset);
126126
struct symbol *find_symbol_by_name(const struct elf *elf, const char *name);
127-
struct symbol *find_symbol_containing(struct section *sec, unsigned long offset);
127+
struct symbol *find_symbol_containing(const struct section *sec, unsigned long offset);
128128
struct rela *find_rela_by_dest(const struct elf *elf, struct section *sec, unsigned long offset);
129129
struct rela *find_rela_by_dest_range(const struct elf *elf, struct section *sec,
130130
unsigned long offset, unsigned int len);

0 commit comments

Comments
 (0)