]> git.itanic.dy.fi Git - linux-stable/commitdiff
objtool: Classify symbols
authorPeter Zijlstra <peterz@infradead.org>
Tue, 26 Oct 2021 12:01:33 +0000 (14:01 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 23 Jul 2022 10:53:49 +0000 (12:53 +0200)
commit 1739c66eb7bd5f27f1b69a5a26e10e8327d1e136 upstream.

In order to avoid calling str*cmp() on symbol names, over and over, do
them all once upfront and store the result.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Borislav Petkov <bp@suse.de>
Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>
Tested-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/r/20211026120309.658539311@infradead.org
[cascardo: no pv_target on struct symbol, because of missing
 db2b0c5d7b6f19b3c2cab08c531b65342eb5252b]
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
tools/objtool/check.c
tools/objtool/include/objtool/elf.h

index 8b3435af989a2742938dd86a4046eed251d2ef7c..236f34ea1be27057cffbc506ac0c255614de388b 100644 (file)
@@ -859,8 +859,7 @@ static void add_call_dest(struct objtool_file *file, struct instruction *insn,
         * so they need a little help, NOP out any KCOV calls from noinstr
         * text.
         */
-       if (insn->sec->noinstr &&
-           !strncmp(insn->call_dest->name, "__sanitizer_cov_", 16)) {
+       if (insn->sec->noinstr && insn->call_dest->kcov) {
                if (reloc) {
                        reloc->type = R_NONE;
                        elf_write_reloc(file->elf, reloc);
@@ -884,7 +883,7 @@ static void add_call_dest(struct objtool_file *file, struct instruction *insn,
                }
        }
 
-       if (mcount && !strcmp(insn->call_dest->name, "__fentry__")) {
+       if (mcount && insn->call_dest->fentry) {
                if (sibling)
                        WARN_FUNC("Tail call to __fentry__ !?!?", insn->sec, insn->offset);
 
@@ -934,7 +933,7 @@ static int add_jump_destinations(struct objtool_file *file)
                } else if (reloc->sym->type == STT_SECTION) {
                        dest_sec = reloc->sym->sec;
                        dest_off = arch_dest_reloc_offset(reloc->addend);
-               } else if (arch_is_retpoline(reloc->sym)) {
+               } else if (reloc->sym->retpoline_thunk) {
                        /*
                         * Retpoline jumps are really dynamic jumps in
                         * disguise, so convert them accordingly.
@@ -1075,7 +1074,7 @@ static int add_call_destinations(struct objtool_file *file)
 
                        add_call_dest(file, insn, dest, false);
 
-               } else if (arch_is_retpoline(reloc->sym)) {
+               } else if (reloc->sym->retpoline_thunk) {
                        /*
                         * Retpoline calls are really dynamic calls in
                         * disguise, so convert them accordingly.
@@ -1759,17 +1758,28 @@ static int read_intra_function_calls(struct objtool_file *file)
        return 0;
 }
 
-static int read_static_call_tramps(struct objtool_file *file)
+static int classify_symbols(struct objtool_file *file)
 {
        struct section *sec;
        struct symbol *func;
 
        for_each_sec(file, sec) {
                list_for_each_entry(func, &sec->symbol_list, list) {
-                       if (func->bind == STB_GLOBAL &&
-                           !strncmp(func->name, STATIC_CALL_TRAMP_PREFIX_STR,
+                       if (func->bind != STB_GLOBAL)
+                               continue;
+
+                       if (!strncmp(func->name, STATIC_CALL_TRAMP_PREFIX_STR,
                                     strlen(STATIC_CALL_TRAMP_PREFIX_STR)))
                                func->static_call_tramp = true;
+
+                       if (arch_is_retpoline(func))
+                               func->retpoline_thunk = true;
+
+                       if (!strcmp(func->name, "__fentry__"))
+                               func->fentry = true;
+
+                       if (!strncmp(func->name, "__sanitizer_cov_", 16))
+                               func->kcov = true;
                }
        }
 
@@ -1831,7 +1841,7 @@ static int decode_sections(struct objtool_file *file)
        /*
         * Must be before add_{jump_call}_destination.
         */
-       ret = read_static_call_tramps(file);
+       ret = classify_symbols(file);
        if (ret)
                return ret;
 
@@ -1889,9 +1899,9 @@ static int decode_sections(struct objtool_file *file)
 
 static bool is_fentry_call(struct instruction *insn)
 {
-       if (insn->type == INSN_CALL && insn->call_dest &&
-           insn->call_dest->type == STT_NOTYPE &&
-           !strcmp(insn->call_dest->name, "__fentry__"))
+       if (insn->type == INSN_CALL &&
+           insn->call_dest &&
+           insn->call_dest->fentry)
                return true;
 
        return false;
index 4443652856187a7e385cf85977c5f2dd16d8dfa2..d3915f5e0c736bce37c5e9c901b863144827269d 100644 (file)
@@ -54,8 +54,11 @@ struct symbol {
        unsigned long offset;
        unsigned int len;
        struct symbol *pfunc, *cfunc, *alias;
-       bool uaccess_safe;
-       bool static_call_tramp;
+       u8 uaccess_safe      : 1;
+       u8 static_call_tramp : 1;
+       u8 retpoline_thunk   : 1;
+       u8 fentry            : 1;
+       u8 kcov              : 1;
 };
 
 struct reloc {