Skip to content

Commit 7bd2a60

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
objtool: Cache instruction relocs
Track the reloc of instructions in the new instruction->reloc field to avoid having to look them up again later. ( Technically x86 instructions can have two relocations, but not jumps and calls, for which we're using this. ) Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Reviewed-by: Miroslav Benes <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 43d5430 commit 7bd2a60

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

tools/objtool/check.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,25 @@ __weak bool arch_is_retpoline(struct symbol *sym)
797797
return false;
798798
}
799799

800+
#define NEGATIVE_RELOC ((void *)-1L)
801+
802+
static struct reloc *insn_reloc(struct objtool_file *file, struct instruction *insn)
803+
{
804+
if (insn->reloc == NEGATIVE_RELOC)
805+
return NULL;
806+
807+
if (!insn->reloc) {
808+
insn->reloc = find_reloc_by_dest_range(file->elf, insn->sec,
809+
insn->offset, insn->len);
810+
if (!insn->reloc) {
811+
insn->reloc = NEGATIVE_RELOC;
812+
return NULL;
813+
}
814+
}
815+
816+
return insn->reloc;
817+
}
818+
800819
/*
801820
* Find the destination instructions for all jumps.
802821
*/
@@ -811,8 +830,7 @@ static int add_jump_destinations(struct objtool_file *file)
811830
if (!is_static_jump(insn))
812831
continue;
813832

814-
reloc = find_reloc_by_dest_range(file->elf, insn->sec,
815-
insn->offset, insn->len);
833+
reloc = insn_reloc(file, insn);
816834
if (!reloc) {
817835
dest_sec = insn->sec;
818836
dest_off = arch_jump_destination(insn);
@@ -944,8 +962,7 @@ static int add_call_destinations(struct objtool_file *file)
944962
if (insn->type != INSN_CALL)
945963
continue;
946964

947-
reloc = find_reloc_by_dest_range(file->elf, insn->sec,
948-
insn->offset, insn->len);
965+
reloc = insn_reloc(file, insn);
949966
if (!reloc) {
950967
dest_off = arch_jump_destination(insn);
951968
insn->call_dest = find_call_destination(insn->sec, dest_off);
@@ -1144,8 +1161,7 @@ static int handle_group_alt(struct objtool_file *file,
11441161
* alternatives code can adjust the relative offsets
11451162
* accordingly.
11461163
*/
1147-
alt_reloc = find_reloc_by_dest_range(file->elf, insn->sec,
1148-
insn->offset, insn->len);
1164+
alt_reloc = insn_reloc(file, insn);
11491165
if (alt_reloc &&
11501166
!arch_support_alt_relocation(special_alt, insn, alt_reloc)) {
11511167

tools/objtool/include/objtool/check.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ struct instruction {
5656
struct instruction *jump_dest;
5757
struct instruction *first_jump_src;
5858
struct reloc *jump_table;
59+
struct reloc *reloc;
5960
struct list_head alts;
6061
struct symbol *func;
6162
struct list_head stack_ops;

0 commit comments

Comments
 (0)