]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
objtool: Support per-function rodata sections
authorAllan Xavier <allan.x.xavier@oracle.com>
Fri, 7 Sep 2018 13:12:01 +0000 (08:12 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 25 Jun 2019 03:36:50 +0000 (11:36 +0800)
commit 4a60aa05a0634241ce17f957bf9fb5ac1eed6576 upstream.

Add support for processing switch jump tables in objects with multiple
.rodata sections, such as those created by '-ffunction-sections' and
'-fdata-sections'.  Currently, objtool always looks in .rodata for jump
table information, which results in many "sibling call from callable
instruction with modified stack frame" warnings with objects compiled
using those flags.

The fix is comprised of three parts:

1. Flagging all .rodata sections when importing ELF information for
   easier checking later.

2. Keeping a reference to the section each relocation is from in order
   to get the list_head for the other relocations in that section.

3. Finding jump tables by following relocations to .rodata sections,
   rather than always referencing a single global .rodata section.

The patch has been tested without data sections enabled and no
differences in the resulting orc unwind information were seen.

Note that as objtool adds terminators to end of each .text section the
unwind information generated between a function+data sections build and
a normal build aren't directly comparable. Manual inspection suggests
that objtool is now generating the correct information, or at least
making more of an effort to do so than it did previously.

Signed-off-by: Allan Xavier <allan.x.xavier@oracle.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/099bdc375195c490dda04db777ee0b95d566ded1.1536325914.git.jpoimboe@redhat.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
tools/objtool/check.c
tools/objtool/check.h
tools/objtool/elf.c
tools/objtool/elf.h

index 95326c6a7a2492dc5f63d764f68500ea6906ab56..7d748e272572fce0209ae3e3b08213540c862f68 100644 (file)
@@ -814,7 +814,7 @@ static int add_switch_table(struct objtool_file *file, struct instruction *insn,
        struct symbol *pfunc = insn->func->pfunc;
        unsigned int prev_offset = 0;
 
-       list_for_each_entry_from(rela, &file->rodata->rela->rela_list, list) {
+       list_for_each_entry_from(rela, &table->rela_sec->rela_list, list) {
                if (rela == next_table)
                        break;
 
@@ -904,6 +904,7 @@ static struct rela *find_switch_table(struct objtool_file *file,
 {
        struct rela *text_rela, *rodata_rela;
        struct instruction *orig_insn = insn;
+       struct section *rodata_sec;
        unsigned long table_offset;
 
        /*
@@ -931,10 +932,13 @@ static struct rela *find_switch_table(struct objtool_file *file,
                /* look for a relocation which references .rodata */
                text_rela = find_rela_by_dest_range(insn->sec, insn->offset,
                                                    insn->len);
-               if (!text_rela || text_rela->sym != file->rodata->sym)
+               if (!text_rela || text_rela->sym->type != STT_SECTION ||
+                   !text_rela->sym->sec->rodata)
                        continue;
 
                table_offset = text_rela->addend;
+               rodata_sec = text_rela->sym->sec;
+
                if (text_rela->type == R_X86_64_PC32)
                        table_offset += 4;
 
@@ -942,10 +946,10 @@ static struct rela *find_switch_table(struct objtool_file *file,
                 * Make sure the .rodata address isn't associated with a
                 * symbol.  gcc jump tables are anonymous data.
                 */
-               if (find_symbol_containing(file->rodata, table_offset))
+               if (find_symbol_containing(rodata_sec, table_offset))
                        continue;
 
-               rodata_rela = find_rela_by_dest(file->rodata, table_offset);
+               rodata_rela = find_rela_by_dest(rodata_sec, table_offset);
                if (rodata_rela) {
                        /*
                         * Use of RIP-relative switch jumps is quite rare, and
@@ -1030,7 +1034,7 @@ static int add_switch_table_alts(struct objtool_file *file)
        struct symbol *func;
        int ret;
 
-       if (!file->rodata || !file->rodata->rela)
+       if (!file->rodata)
                return 0;
 
        for_each_sec(file, sec) {
@@ -1175,10 +1179,33 @@ static int read_retpoline_hints(struct objtool_file *file)
        return 0;
 }
 
+static void mark_rodata(struct objtool_file *file)
+{
+       struct section *sec;
+       bool found = false;
+
+       /*
+        * This searches for the .rodata section or multiple .rodata.func_name
+        * sections if -fdata-sections is being used. The .str.1.1 and .str.1.8
+        * rodata sections are ignored as they don't contain jump tables.
+        */
+       for_each_sec(file, sec) {
+               if (!strncmp(sec->name, ".rodata", 7) &&
+                   !strstr(sec->name, ".str1.")) {
+                       sec->rodata = true;
+                       found = true;
+               }
+       }
+
+       file->rodata = found;
+}
+
 static int decode_sections(struct objtool_file *file)
 {
        int ret;
 
+       mark_rodata(file);
+
        ret = decode_instructions(file);
        if (ret)
                return ret;
@@ -2150,7 +2177,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.rodata = find_section_by_name(file.elf, ".rodata");
        file.c_file = find_section_by_name(file.elf, ".comment");
        file.ignore_unreachables = no_unreachable;
        file.hints = false;
index c6b68fcb926ff76c6e44675ff636c16f3552a184..a039521b67530ea0d2201ef77c64877937840cdc 100644 (file)
@@ -60,8 +60,8 @@ struct objtool_file {
        struct elf *elf;
        struct list_head insn_list;
        DECLARE_HASHTABLE(insn_hash, 16);
-       struct section *rodata, *whitelist;
-       bool ignore_unreachables, c_file, hints;
+       struct section *whitelist;
+       bool ignore_unreachables, c_file, hints, rodata;
 };
 
 int check(const char *objname, bool orc);
index dd4ed7c3c062608cbd87a44592996a7578cc8772..e6cef5a160e77748d083ac9e6a8764cd5ff1bec3 100644 (file)
@@ -390,6 +390,7 @@ static int read_relas(struct elf *elf)
                        rela->offset = rela->rela.r_offset;
                        symndx = GELF_R_SYM(rela->rela.r_info);
                        rela->sym = find_symbol_by_index(elf, symndx);
+                       rela->rela_sec = sec;
                        if (!rela->sym) {
                                WARN("can't find rela entry symbol %d for %s",
                                     symndx, sec->name);
index de5cd2ddded987bf524be46e446bd1e814422761..bc97ed86b9cd8ebd3fc8e9e1512d8d06b3e96d14 100644 (file)
@@ -48,7 +48,7 @@ struct section {
        char *name;
        int idx;
        unsigned int len;
-       bool changed, text;
+       bool changed, text, rodata;
 };
 
 struct symbol {
@@ -68,6 +68,7 @@ struct rela {
        struct list_head list;
        struct hlist_node hash;
        GElf_Rela rela;
+       struct section *rela_sec;
        struct symbol *sym;
        unsigned int type;
        unsigned long offset;