objtool: Track init section
authorPeter Zijlstra <peterz@infradead.org>
Thu, 15 Sep 2022 11:11:08 +0000 (13:11 +0200)
committerPeter Zijlstra <peterz@infradead.org>
Mon, 17 Oct 2022 14:41:07 +0000 (16:41 +0200)
For future usage of .init.text exclusion track the init section in the
instruction decoder and use the result in retpoline validation.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20220915111145.910334431@infradead.org
tools/objtool/check.c
tools/objtool/include/objtool/elf.h

index 7174bba..bb7c819 100644 (file)
@@ -382,6 +382,15 @@ static int decode_instructions(struct objtool_file *file)
                    !strncmp(sec->name, ".text.__x86.", 12))
                        sec->noinstr = true;
 
+               /*
+                * .init.text code is ran before userspace and thus doesn't
+                * strictly need retpolines, except for modules which are
+                * loaded late, they very much do need retpoline in their
+                * .init.text
+                */
+               if (!strcmp(sec->name, ".init.text") && !opts.module)
+                       sec->init = true;
+
                for (offset = 0; offset < sec->sh.sh_size; offset += insn->len) {
                        insn = malloc(sizeof(*insn));
                        if (!insn) {
@@ -3748,13 +3757,7 @@ static int validate_retpoline(struct objtool_file *file)
                if (insn->retpoline_safe)
                        continue;
 
-               /*
-                * .init.text code is ran before userspace and thus doesn't
-                * strictly need retpolines, except for modules which are
-                * loaded late, they very much do need retpoline in their
-                * .init.text
-                */
-               if (!strcmp(insn->sec->name, ".init.text") && !opts.module)
+               if (insn->sec->init)
                        continue;
 
                if (insn->type == INSN_RETURN) {
index 16f4067..baa8085 100644 (file)
@@ -38,7 +38,7 @@ struct section {
        Elf_Data *data;
        char *name;
        int idx;
-       bool changed, text, rodata, noinstr;
+       bool changed, text, rodata, noinstr, init;
 };
 
 struct symbol {