|
@@ -59,6 +59,31 @@ static struct instruction *next_insn_same_sec(struct objtool_file *file,
|
|
|
return next;
|
|
|
}
|
|
|
|
|
|
+static struct instruction *next_insn_same_func(struct objtool_file *file,
|
|
|
+ struct instruction *insn)
|
|
|
+{
|
|
|
+ struct instruction *next = list_next_entry(insn, list);
|
|
|
+ struct symbol *func = insn->func;
|
|
|
+
|
|
|
+ if (!func)
|
|
|
+ return NULL;
|
|
|
+
|
|
|
+ if (&next->list != &file->insn_list && next->func == func)
|
|
|
+ return next;
|
|
|
+
|
|
|
+ /* Check if we're already in the subfunction: */
|
|
|
+ if (func == func->cfunc)
|
|
|
+ return NULL;
|
|
|
+
|
|
|
+ /* Move to the subfunction: */
|
|
|
+ return find_insn(file, func->cfunc->sec, func->cfunc->offset);
|
|
|
+}
|
|
|
+
|
|
|
+#define func_for_each_insn_all(file, func, insn) \
|
|
|
+ for (insn = find_insn(file, func->sec, func->offset); \
|
|
|
+ insn; \
|
|
|
+ insn = next_insn_same_func(file, insn))
|
|
|
+
|
|
|
#define func_for_each_insn(file, func, insn) \
|
|
|
for (insn = find_insn(file, func->sec, func->offset); \
|
|
|
insn && &insn->list != &file->insn_list && \
|
|
@@ -149,10 +174,14 @@ static int __dead_end_function(struct objtool_file *file, struct symbol *func,
|
|
|
if (!strcmp(func->name, global_noreturns[i]))
|
|
|
return 1;
|
|
|
|
|
|
- if (!func->sec)
|
|
|
+ if (!func->len)
|
|
|
return 0;
|
|
|
|
|
|
- func_for_each_insn(file, func, insn) {
|
|
|
+ insn = find_insn(file, func->sec, func->offset);
|
|
|
+ if (!insn->func)
|
|
|
+ return 0;
|
|
|
+
|
|
|
+ func_for_each_insn_all(file, func, insn) {
|
|
|
empty = false;
|
|
|
|
|
|
if (insn->type == INSN_RETURN)
|
|
@@ -167,28 +196,17 @@ static int __dead_end_function(struct objtool_file *file, struct symbol *func,
|
|
|
* case, the function's dead-end status depends on whether the target
|
|
|
* of the sibling call returns.
|
|
|
*/
|
|
|
- func_for_each_insn(file, func, insn) {
|
|
|
- if (insn->sec != func->sec ||
|
|
|
- insn->offset >= func->offset + func->len)
|
|
|
- break;
|
|
|
-
|
|
|
+ func_for_each_insn_all(file, func, insn) {
|
|
|
if (insn->type == INSN_JUMP_UNCONDITIONAL) {
|
|
|
struct instruction *dest = insn->jump_dest;
|
|
|
- struct symbol *dest_func;
|
|
|
|
|
|
if (!dest)
|
|
|
/* sibling call to another file */
|
|
|
return 0;
|
|
|
|
|
|
- if (dest->sec != func->sec ||
|
|
|
- dest->offset < func->offset ||
|
|
|
- dest->offset >= func->offset + func->len) {
|
|
|
- /* local sibling call */
|
|
|
- dest_func = find_symbol_by_offset(dest->sec,
|
|
|
- dest->offset);
|
|
|
- if (!dest_func)
|
|
|
- continue;
|
|
|
+ if (dest->func && dest->func->pfunc != insn->func->pfunc) {
|
|
|
|
|
|
+ /* local sibling call */
|
|
|
if (recursion == 5) {
|
|
|
/*
|
|
|
* Infinite recursion: two functions
|
|
@@ -199,7 +217,7 @@ static int __dead_end_function(struct objtool_file *file, struct symbol *func,
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- return __dead_end_function(file, dest_func,
|
|
|
+ return __dead_end_function(file, dest->func,
|
|
|
recursion + 1);
|
|
|
}
|
|
|
}
|
|
@@ -426,7 +444,7 @@ static void add_ignores(struct objtool_file *file)
|
|
|
if (!ignore_func(file, func))
|
|
|
continue;
|
|
|
|
|
|
- func_for_each_insn(file, func, insn)
|
|
|
+ func_for_each_insn_all(file, func, insn)
|
|
|
insn->ignore = true;
|
|
|
}
|
|
|
}
|
|
@@ -786,9 +804,8 @@ out:
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-static int add_switch_table(struct objtool_file *file, struct symbol *func,
|
|
|
- struct instruction *insn, struct rela *table,
|
|
|
- struct rela *next_table)
|
|
|
+static int add_switch_table(struct objtool_file *file, struct instruction *insn,
|
|
|
+ struct rela *table, struct rela *next_table)
|
|
|
{
|
|
|
struct rela *rela = table;
|
|
|
struct instruction *alt_insn;
|
|
@@ -798,18 +815,13 @@ static int add_switch_table(struct objtool_file *file, struct symbol *func,
|
|
|
if (rela == next_table)
|
|
|
break;
|
|
|
|
|
|
- if (rela->sym->sec != insn->sec ||
|
|
|
- rela->addend <= func->offset ||
|
|
|
- rela->addend >= func->offset + func->len)
|
|
|
+ alt_insn = find_insn(file, rela->sym->sec, rela->addend);
|
|
|
+ if (!alt_insn)
|
|
|
break;
|
|
|
|
|
|
- alt_insn = find_insn(file, insn->sec, rela->addend);
|
|
|
- if (!alt_insn) {
|
|
|
- WARN("%s: can't find instruction at %s+0x%x",
|
|
|
- file->rodata->rela->name, insn->sec->name,
|
|
|
- rela->addend);
|
|
|
- return -1;
|
|
|
- }
|
|
|
+ /* Make sure the jmp dest is in the function or subfunction: */
|
|
|
+ if (alt_insn->func->pfunc != insn->func->pfunc)
|
|
|
+ break;
|
|
|
|
|
|
alt = malloc(sizeof(*alt));
|
|
|
if (!alt) {
|
|
@@ -947,7 +959,7 @@ static int add_func_switch_tables(struct objtool_file *file,
|
|
|
struct rela *rela, *prev_rela = NULL;
|
|
|
int ret;
|
|
|
|
|
|
- func_for_each_insn(file, func, insn) {
|
|
|
+ func_for_each_insn_all(file, func, insn) {
|
|
|
if (!last)
|
|
|
last = insn;
|
|
|
|
|
@@ -978,8 +990,7 @@ static int add_func_switch_tables(struct objtool_file *file,
|
|
|
* the beginning of another switch table in the same function.
|
|
|
*/
|
|
|
if (prev_jump) {
|
|
|
- ret = add_switch_table(file, func, prev_jump, prev_rela,
|
|
|
- rela);
|
|
|
+ ret = add_switch_table(file, prev_jump, prev_rela, rela);
|
|
|
if (ret)
|
|
|
return ret;
|
|
|
}
|
|
@@ -989,7 +1000,7 @@ static int add_func_switch_tables(struct objtool_file *file,
|
|
|
}
|
|
|
|
|
|
if (prev_jump) {
|
|
|
- ret = add_switch_table(file, func, prev_jump, prev_rela, NULL);
|
|
|
+ ret = add_switch_table(file, prev_jump, prev_rela, NULL);
|
|
|
if (ret)
|
|
|
return ret;
|
|
|
}
|
|
@@ -1753,15 +1764,13 @@ static int validate_branch(struct objtool_file *file, struct instruction *first,
|
|
|
while (1) {
|
|
|
next_insn = next_insn_same_sec(file, insn);
|
|
|
|
|
|
-
|
|
|
- if (file->c_file && func && insn->func && func != insn->func) {
|
|
|
+ if (file->c_file && func && insn->func && func != insn->func->pfunc) {
|
|
|
WARN("%s() falls through to next function %s()",
|
|
|
func->name, insn->func->name);
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
- if (insn->func)
|
|
|
- func = insn->func;
|
|
|
+ func = insn->func ? insn->func->pfunc : NULL;
|
|
|
|
|
|
if (func && insn->ignore) {
|
|
|
WARN_FUNC("BUG: why am I validating an ignored function?",
|
|
@@ -1782,7 +1791,7 @@ static int validate_branch(struct objtool_file *file, struct instruction *first,
|
|
|
|
|
|
i = insn;
|
|
|
save_insn = NULL;
|
|
|
- func_for_each_insn_continue_reverse(file, func, i) {
|
|
|
+ func_for_each_insn_continue_reverse(file, insn->func, i) {
|
|
|
if (i->save) {
|
|
|
save_insn = i;
|
|
|
break;
|
|
@@ -1869,7 +1878,7 @@ static int validate_branch(struct objtool_file *file, struct instruction *first,
|
|
|
case INSN_JUMP_UNCONDITIONAL:
|
|
|
if (insn->jump_dest &&
|
|
|
(!func || !insn->jump_dest->func ||
|
|
|
- func == insn->jump_dest->func)) {
|
|
|
+ insn->jump_dest->func->pfunc == func)) {
|
|
|
ret = validate_branch(file, insn->jump_dest,
|
|
|
state);
|
|
|
if (ret)
|
|
@@ -2064,7 +2073,7 @@ static int validate_functions(struct objtool_file *file)
|
|
|
|
|
|
for_each_sec(file, sec) {
|
|
|
list_for_each_entry(func, &sec->symbol_list, list) {
|
|
|
- if (func->type != STT_FUNC)
|
|
|
+ if (func->type != STT_FUNC || func->pfunc != func)
|
|
|
continue;
|
|
|
|
|
|
insn = find_insn(file, sec, func->offset);
|