diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 3d6cca126178..c8b2d26f4957 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -838,37 +838,6 @@ static int add_ignore_alternatives(struct objtool_file *file) return 0; } -/* - * CONFIG_CFI_CLANG: Check if the section is a CFI jump table or a - * compiler-generated CFI handler. - */ -static bool is_cfi_section(struct section *sec) -{ - return (sec->name && - (!strncmp(sec->name, ".text..L.cfi.jumptable", 22) || - !strcmp(sec->name, ".text.__cfi_check"))); -} - -/* - * CONFIG_CFI_CLANG: Ignore CFI jump tables. - */ -static void add_cfi_jumptables(struct objtool_file *file) -{ - struct section *sec; - struct symbol *func; - struct instruction *insn; - - for_each_sec(file, sec) { - if (!is_cfi_section(sec)) - continue; - - list_for_each_entry(func, &sec->symbol_list, list) { - sym_for_each_insn(file, func, insn) - insn->ignore = true; - } - } -} - /* * Find the destination instructions for all jumps. */ @@ -939,9 +908,6 @@ static int add_jump_destinations(struct objtool_file *file) if (!strcmp(insn->sec->name, ".altinstr_replacement")) continue; - if (is_cfi_section(insn->sec)) - continue; - WARN_FUNC("can't find jump dest instruction at %s+0x%lx", insn->sec, insn->offset, dest_sec->name, dest_off); @@ -1049,9 +1015,6 @@ static int add_call_destinations(struct objtool_file *file) insn->call_dest = find_call_destination(reloc->sym->sec, dest_off); if (!insn->call_dest) { - if (is_cfi_section(reloc->sym->sec)) - continue; - WARN_FUNC("can't find call dest symbol at %s+0x%lx", insn->sec, insn->offset, reloc->sym->sec->name, @@ -1791,7 +1754,6 @@ static int decode_sections(struct objtool_file *file) add_ignores(file); add_uaccess_safe(file); - add_cfi_jumptables(file); ret = add_ignore_alternatives(file); if (ret) @@ -2654,8 +2616,7 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, if (dead_end_function(file, insn->call_dest)) return 0; - if (insn->type == INSN_CALL && insn->call_dest && - insn->call_dest->static_call_tramp) { + if (insn->type == INSN_CALL && insn->call_dest->static_call_tramp) { list_add_tail(&insn->static_call_node, &file->static_call_list); } diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index ccee8fc331f0..b3b307bf7ec9 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -350,6 +350,11 @@ static int read_sections(struct elf *elf) } sec->len = sec->sh.sh_size; + /* Detect -fsanitize=cfi related sections */ + if (!strcmp(sec->name, ".text.__cfi_check") || + !strncmp(sec->name, ".text..L.cfi.jumptable", 22)) + sec->cfi_jt = true; + list_add_tail(&sec->list, &elf->sections); elf_hash_add(elf->section_hash, &sec->hash, sec->idx); elf_hash_add(elf->section_name_hash, &sec->name_hash, str_hash(sec->name)); @@ -606,6 +611,33 @@ static int read_relocs(struct elf *elf) return -1; } + if (reloc->sym->sec->cfi_jt) { + struct symbol *sym = reloc->sym; + char *suffix; + char name[MAX_NAME_LEN + 1]; + size_t name_len; + struct symbol *new_sym; + + if (sym->type == STT_SECTION) + sym = find_func_by_offset(sym->sec, + reloc->addend); + if (sym) { + suffix = strstr(sym->name, ".cfi_jt"); + if (suffix) { + name_len = suffix - sym->name; + strncpy(name, sym->name, name_len); + name[name_len] = '\0'; + new_sym = find_symbol_by_name(elf, name); + if (!new_sym) { + WARN("wtf"); + return -1; + } + + reloc->sym = new_sym; + } + } + } + elf_add_reloc(elf, reloc); nr_reloc++; } diff --git a/tools/objtool/elf.h b/tools/objtool/elf.h index e6890cc70a25..bcc524d73f51 100644 --- a/tools/objtool/elf.h +++ b/tools/objtool/elf.h @@ -39,7 +39,7 @@ struct section { char *name; int idx; unsigned int len; - bool changed, text, rodata, noinstr; + bool changed, text, rodata, noinstr, cfi_jt; }; struct symbol { -- 2.30.0