objtool: Rewrite add_ignores()
authorPeter Zijlstra <peterz@infradead.org>
Wed, 27 Feb 2019 13:04:13 +0000 (14:04 +0100)
committerIngo Molnar <mingo@kernel.org>
Wed, 3 Apr 2019 09:02:24 +0000 (11:02 +0200)
The whole add_ignores() thing was wildly weird; rewrite it according
to 'modern' ways.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
tools/objtool/check.c
tools/objtool/check.h

index 950d0f62d22b37f208768e361465bf3ef38050b6..8d8191f25381b4bdb57d25ba7ad918771614104f 100644 (file)
@@ -104,29 +104,6 @@ static struct instruction *next_insn_same_func(struct objtool_file *file,
        for (insn = next_insn_same_sec(file, insn); insn;               \
             insn = next_insn_same_sec(file, insn))
 
-/*
- * Check if the function has been manually whitelisted with the
- * STACK_FRAME_NON_STANDARD macro, or if it should be automatically whitelisted
- * due to its use of a context switching instruction.
- */
-static bool ignore_func(struct objtool_file *file, struct symbol *func)
-{
-       struct rela *rela;
-
-       /* check for STACK_FRAME_NON_STANDARD */
-       if (file->whitelist && file->whitelist->rela)
-               list_for_each_entry(rela, &file->whitelist->rela->rela_list, list) {
-                       if (rela->sym->type == STT_SECTION &&
-                           rela->sym->sec == func->sec &&
-                           rela->addend == func->offset)
-                               return true;
-                       if (rela->sym->type == STT_FUNC && rela->sym == func)
-                               return true;
-               }
-
-       return false;
-}
-
 /*
  * This checks to see if the given function is a "noreturn" function.
  *
@@ -436,18 +413,31 @@ static void add_ignores(struct objtool_file *file)
        struct instruction *insn;
        struct section *sec;
        struct symbol *func;
+       struct rela *rela;
 
-       for_each_sec(file, sec) {
-               list_for_each_entry(func, &sec->symbol_list, list) {
-                       if (func->type != STT_FUNC)
-                               continue;
+       sec = find_section_by_name(file->elf, ".rela.discard.func_stack_frame_non_standard");
+       if (!sec)
+               return;
 
-                       if (!ignore_func(file, func))
+       list_for_each_entry(rela, &sec->rela_list, list) {
+               switch (rela->sym->type) {
+               case STT_FUNC:
+                       func = rela->sym;
+                       break;
+
+               case STT_SECTION:
+                       func = find_symbol_by_offset(rela->sym->sec, rela->addend);
+                       if (!func || func->type != STT_FUNC)
                                continue;
+                       break;
 
-                       func_for_each_insn_all(file, func, insn)
-                               insn->ignore = true;
+               default:
+                       WARN("unexpected relocation symbol type in %s: %d", sec->name, rela->sym->type);
+                       continue;
                }
+
+               func_for_each_insn_all(file, func, insn)
+                       insn->ignore = true;
        }
 }
 
@@ -2199,7 +2189,6 @@ int check(const char *_objname, bool orc)
 
        INIT_LIST_HEAD(&file.insn_list);
        hash_init(file.insn_hash);
-       file.whitelist = find_section_by_name(file.elf, ".discard.func_stack_frame_non_standard");
        file.c_file = find_section_by_name(file.elf, ".comment");
        file.ignore_unreachables = no_unreachable;
        file.hints = false;
index e6e8a655b5563e84bcd5d67eee13a446db81cc31..d8896eb43521284135c77073733beb3f7d58b37d 100644 (file)
@@ -60,7 +60,6 @@ struct objtool_file {
        struct elf *elf;
        struct list_head insn_list;
        DECLARE_HASHTABLE(insn_hash, 16);
-       struct section *whitelist;
        bool ignore_unreachables, c_file, hints, rodata;
 };