]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
objtool: Move mark_rodata() to elf.c
authorJosh Poimboeuf <jpoimboe@kernel.org>
Mon, 13 Apr 2026 01:35:03 +0000 (18:35 -0700)
committerJosh Poimboeuf <jpoimboe@kernel.org>
Tue, 5 May 2026 04:16:01 +0000 (21:16 -0700)
Move the sec->rodata marking from check.c to elf.c so it's set during
ELF reading rather than during the check pipeline.  This makes the
rodata flag available to all objtool users, including klp-diff which
reads ELF files directly without running check().

Add an is_rodata_sec() helper to elf.h for consistency with
is_text_sec() and is_string_sec().

Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Song Liu <song@kernel.org>
Reviewed-by: Miroslav Benes <mbenes@suse.cz>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
tools/objtool/check.c
tools/objtool/elf.c
tools/objtool/include/objtool/elf.h

index e3604b1201f9eaf43619ad2399cd67947deb1d3c..e7579c4e46dcaa0306d138ced312eca25811d433 100644 (file)
@@ -2566,7 +2566,6 @@ static int classify_symbols(struct objtool_file *file)
 static void mark_rodata(struct objtool_file *file)
 {
        struct section *sec;
-       bool found = false;
 
        /*
         * Search for the following rodata sections, each of which can
@@ -2579,15 +2578,11 @@ static void mark_rodata(struct objtool_file *file)
         * .rodata.str1.* sections are ignored; they don't contain jump tables.
         */
        for_each_sec(file->elf, sec) {
-               if ((!strncmp(sec->name, ".rodata", 7) &&
-                    !strstr(sec->name, ".str1.")) ||
-                   !strncmp(sec->name, ".data.rel.ro", 12)) {
-                       sec->rodata = true;
-                       found = true;
+               if (is_rodata_sec(sec)) {
+                       file->rodata = true;
+                       return;
                }
        }
-
-       file->rodata = found;
 }
 
 static void mark_holes(struct objtool_file *file)
index dc39132f71c148a8d83e01e6e792cf403f23cf23..87c6e00749c60183565018d367eacf960a12ed12 100644 (file)
@@ -1138,6 +1138,17 @@ static int read_relocs(struct elf *elf)
        return 0;
 }
 
+static void mark_rodata(struct elf *elf)
+{
+       struct section *sec;
+
+       for_each_sec(elf, sec) {
+               if ((strstarts(sec->name, ".rodata") && !strstr(sec->name, ".str1.")) ||
+                   strstarts(sec->name, ".data.rel.ro"))
+                       sec->rodata = true;
+       }
+}
+
 struct elf *elf_open_read(const char *name, int flags)
 {
        struct elf *elf;
@@ -1188,6 +1199,8 @@ struct elf *elf_open_read(const char *name, int flags)
        if (read_sections(elf))
                goto err;
 
+       mark_rodata(elf);
+
        if (read_symbols(elf))
                goto err;
 
index 00b04029023e616aac7e7b7dfb43840b1056d7da..ab5f7017ec34310be4c3be96f7b85e35d244c85e 100644 (file)
@@ -317,6 +317,11 @@ static inline bool is_text_sec(struct section *sec)
        return sec->sh.sh_flags & SHF_EXECINSTR;
 }
 
+static inline bool is_rodata_sec(struct section *sec)
+{
+       return sec->rodata;
+}
+
 static inline bool sec_changed(struct section *sec)
 {
        return sec->_changed;