lkml.org 
[lkml]   [2021]   [Mar]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH 7/9] objtool: Allow archs to rewrite retpolines
When retpolines are employed, compilers typically emit calls to
retpoline thunks. Objtool recognises these calls and marks them as
dynamic calls.

Provide infrastructure for architectures to rewrite/augment what the
compiler wrote for us.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
tools/objtool/check.c | 23 +++++++++++++++++++++--
tools/objtool/include/objtool/arch.h | 3 +++
2 files changed, 24 insertions(+), 2 deletions(-)

--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -852,6 +852,14 @@ __weak bool arch_is_retpoline(struct sym
return false;
}

+
+__weak int arch_rewrite_retpoline(struct objtool_file *file,
+ struct instruction *insn,
+ struct reloc *reloc)
+{
+ return 0;
+}
+
/*
* Find the destination instructions for all jumps.
*/
@@ -885,6 +893,9 @@ static int add_jump_destinations(struct
insn->type = INSN_JUMP_DYNAMIC_CONDITIONAL;

insn->retpoline_safe = true;
+
+ arch_rewrite_retpoline(file, insn, reloc);
+
continue;
} else if (insn->func) {
/* internal or external sibling call (with reloc) */
@@ -1036,6 +1047,8 @@ static int add_call_destinations(struct
insn->type = INSN_CALL_DYNAMIC;
insn->retpoline_safe = true;

+ arch_rewrite_retpoline(file, insn, reloc);
+
remove_insn_ops(insn);
continue;

@@ -1212,6 +1225,8 @@ static int handle_group_alt(struct objto
dest_off = arch_jump_destination(insn);
if (dest_off == special_alt->new_off + special_alt->new_len)
insn->jump_dest = next_insn_same_sec(file, last_orig_insn);
+ else
+ insn->jump_dest = find_insn(file, insn->sec, dest_off);

if (!insn->jump_dest) {
WARN_FUNC("can't find alternative jump destination",
@@ -1797,11 +1812,15 @@ static int decode_sections(struct objtoo
if (ret)
return ret;

- ret = add_jump_destinations(file);
+ /*
+ * Must be before add_{jump,call}_destination; for they can add
+ * magic alternatives.
+ */
+ ret = add_special_section_alts(file);
if (ret)
return ret;

- ret = add_special_section_alts(file);
+ ret = add_jump_destinations(file);
if (ret)
return ret;

--- a/tools/objtool/include/objtool/arch.h
+++ b/tools/objtool/include/objtool/arch.h
@@ -82,6 +82,9 @@ unsigned long arch_jump_destination(stru
unsigned long arch_dest_reloc_offset(int addend);

const char *arch_nop_insn(int len);
+int arch_rewrite_retpoline(struct objtool_file *file,
+ struct instruction *insn,
+ struct reloc *reloc);

int arch_decode_hint_reg(struct instruction *insn, u8 sp_reg);


\
 
 \ /
  Last update: 2021-03-12 18:19    [W:0.234 / U:0.164 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site