Messages in this thread Patch in this message | | | Date | Thu, 14 Oct 2021 17:43:25 +0200 | From | Peter Zijlstra <> | Subject | Re: [PATCH 1/9] objtool,x86: Replace alternatives with .retpoline_sites |
| |
On Wed, Oct 13, 2021 at 01:11:35PM -0700, Josh Poimboeuf wrote:
> Guess it shouldn't be called arch_rewrite_retpolines() anymore. And it > can be moved to check.c next to create_static_call_sections(). > > Also is it possible to remove the arch_is_retpoline() check in > get_alt_entry()? I'm having trouble remembering why that was needed in > the first place.
Makes sense...
--- +++ b/tools/objtool/arch/x86/decode.c @@ -711,52 +711,6 @@ const char *arch_ret_insn(int len) return ret[len-1]; } -int arch_rewrite_retpolines(struct objtool_file *file) -{ - struct instruction *insn; - struct section *sec; - int idx; - - sec = find_section_by_name(file->elf, ".retpoline_sites"); - if (sec) { - WARN("file already has .retpoline_sites, skipping"); - return 0; - } - - idx = 0; - list_for_each_entry(insn, &file->retpoline_call_list, call_node) - idx++; - - if (!idx) - return 0; - - sec = elf_create_section(file->elf, ".retpoline_sites", 0, - sizeof(int), idx); - if (!sec) { - WARN("elf_create_section: .retpoline_sites"); - return -1; - } - - idx = 0; - list_for_each_entry(insn, &file->retpoline_call_list, call_node) { - - int *site = (int *)sec->data->d_buf + idx; - *site = 0; - - if (elf_add_reloc_to_insn(file->elf, sec, - idx * sizeof(int), - R_X86_64_PC32, - insn->sec, insn->offset)) { - WARN("elf_add_reloc_to_insn: .retpoline_sites"); - return -1; - } - - idx++; - } - - return 0; -} - int arch_decode_hint_reg(u8 sp_reg, int *base) { switch (sp_reg) { --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -683,6 +683,52 @@ static int create_static_call_sections(s return 0; } +static int create_retpoline_sites_sections(struct objtool_file *file) +{ + struct instruction *insn; + struct section *sec; + int idx; + + sec = find_section_by_name(file->elf, ".retpoline_sites"); + if (sec) { + WARN("file already has .retpoline_sites, skipping"); + return 0; + } + + idx = 0; + list_for_each_entry(insn, &file->retpoline_call_list, call_node) + idx++; + + if (!idx) + return 0; + + sec = elf_create_section(file->elf, ".retpoline_sites", 0, + sizeof(int), idx); + if (!sec) { + WARN("elf_create_section: .retpoline_sites"); + return -1; + } + + idx = 0; + list_for_each_entry(insn, &file->retpoline_call_list, call_node) { + + int *site = (int *)sec->data->d_buf + idx; + *site = 0; + + if (elf_add_reloc_to_insn(file->elf, sec, + idx * sizeof(int), + R_X86_64_PC32, + insn->sec, insn->offset)) { + WARN("elf_add_reloc_to_insn: .retpoline_sites"); + return -1; + } + + idx++; + } + + return 0; +} + static int create_mcount_loc_sections(struct objtool_file *file) { struct section *sec; @@ -1950,11 +1996,6 @@ static void mark_rodata(struct objtool_f file->rodata = found; } -__weak int arch_rewrite_retpolines(struct objtool_file *file) -{ - return 0; -} - static int decode_sections(struct objtool_file *file) { int ret; @@ -2027,15 +2068,6 @@ static int decode_sections(struct objtoo if (ret) return ret; - /* - * Must be after add_special_section_alts(), since this will emit - * alternatives. Must be after add_{jump,call}_destination(), since - * those create the call insn lists. - */ - ret = arch_rewrite_retpolines(file); - if (ret) - return ret; - return 0; } @@ -3438,6 +3470,13 @@ int check(struct objtool_file *file) goto out; warnings += ret; + if (retpoline) { + ret = create_retpoline_sites_sections(file); + if (ret < 0) + goto out; + warnings += ret; + } + if (mcount) { ret = create_mcount_loc_sections(file); if (ret < 0) --- a/tools/objtool/special.c +++ b/tools/objtool/special.c @@ -109,14 +109,6 @@ static int get_alt_entry(struct elf *elf return -1; } - /* - * Skip retpoline .altinstr_replacement... we already rewrite the - * instructions for retpolines anyway, see arch_is_retpoline() - * usage in add_{call,jump}_destinations(). - */ - if (arch_is_retpoline(new_reloc->sym)) - return 1; - reloc_to_sec_off(new_reloc, &alt->new_sec, &alt->new_off); /* _ASM_EXTABLE_EX hack */
| |