diff options
Diffstat (limited to 'tools/objtool/check.c')
| -rw-r--r-- | tools/objtool/check.c | 52 | 
1 files changed, 36 insertions, 16 deletions
diff --git a/tools/objtool/check.c b/tools/objtool/check.c index f744617c9946..c0e26ad1fa7e 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -267,12 +267,13 @@ static int decode_instructions(struct objtool_file *file)  						      &insn->immediate,  						      &insn->stack_op);  			if (ret) -				return ret; +				goto err;  			if (!insn->type || insn->type > INSN_LAST) {  				WARN_FUNC("invalid instruction type %d",  					  insn->sec, insn->offset, insn->type); -				return -1; +				ret = -1; +				goto err;  			}  			hash_add(file->insn_hash, &insn->hash, insn->offset); @@ -296,6 +297,10 @@ static int decode_instructions(struct objtool_file *file)  	}  	return 0; + +err: +	free(insn); +	return ret;  }  /* @@ -1203,24 +1208,39 @@ static int update_insn_state(struct instruction *insn, struct insn_state *state)  		switch (op->src.type) {  		case OP_SRC_REG: -			if (op->src.reg == CFI_SP && op->dest.reg == CFI_BP) { +			if (op->src.reg == CFI_SP && op->dest.reg == CFI_BP && +			    cfa->base == CFI_SP && +			    regs[CFI_BP].base == CFI_CFA && +			    regs[CFI_BP].offset == -cfa->offset) { + +				/* mov %rsp, %rbp */ +				cfa->base = op->dest.reg; +				state->bp_scratch = false; +			} -				if (cfa->base == CFI_SP && -				    regs[CFI_BP].base == CFI_CFA && -				    regs[CFI_BP].offset == -cfa->offset) { +			else if (op->src.reg == CFI_SP && +				 op->dest.reg == CFI_BP && state->drap) { -					/* mov %rsp, %rbp */ -					cfa->base = op->dest.reg; -					state->bp_scratch = false; -				} +				/* drap: mov %rsp, %rbp */ +				regs[CFI_BP].base = CFI_BP; +				regs[CFI_BP].offset = -state->stack_size; +				state->bp_scratch = false; +			} -				else if (state->drap) { +			else if (op->src.reg == CFI_SP && cfa->base == CFI_SP) { -					/* drap: mov %rsp, %rbp */ -					regs[CFI_BP].base = CFI_BP; -					regs[CFI_BP].offset = -state->stack_size; -					state->bp_scratch = false; -				} +				/* +				 * mov %rsp, %reg +				 * +				 * This is needed for the rare case where GCC +				 * does: +				 * +				 *   mov    %rsp, %rax +				 *   ... +				 *   mov    %rax, %rsp +				 */ +				state->vals[op->dest.reg].base = CFI_CFA; +				state->vals[op->dest.reg].offset = -state->stack_size;  			}  			else if (op->dest.reg == cfa->base) {  |