Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked fromtorvalds/linux

Commit258c760

Browse files
jpoimboeKAGA-KOKO
authored andcommitted
objtool: Allow alternatives to be ignored
Getting objtool to understand retpolines is going to be a bit of achallenge. For now, take advantage of the fact that retpolines arepatched in with alternatives. Just read the original (sane)non-alternative instruction, and ignore the patched-in retpoline.This allows objtool to understand the control flow *around* theretpoline, even if it can't yet follow what's inside. This means theORC unwinder will fail to unwind from inside a retpoline, but will workfine otherwise.Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>Signed-off-by: Thomas Gleixner <tglx@linutronix.de>Cc: gnomes@lxorguk.ukuu.org.ukCc: Rik van Riel <riel@redhat.com>Cc: Andi Kleen <ak@linux.intel.com>Cc: thomas.lendacky@amd.comCc: Peter Zijlstra <peterz@infradead.org>Cc: Linus Torvalds <torvalds@linux-foundation.org>Cc: Jiri Kosina <jikos@kernel.org>Cc: Andy Lutomirski <luto@amacapital.net>Cc: Dave Hansen <dave.hansen@intel.com>Cc: Kees Cook <keescook@google.com>Cc: Tim Chen <tim.c.chen@linux.intel.com>Cc: Greg Kroah-Hartman <gregkh@linux-foundation.org>Cc: Paul Turner <pjt@google.com>Link:https://lkml.kernel.org/r/1515707194-20531-3-git-send-email-dwmw@amazon.co.uk
1 parent39b7353 commit258c760

File tree

2 files changed

+57
-7
lines changed

2 files changed

+57
-7
lines changed

‎tools/objtool/check.c‎

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,40 @@ static void add_ignores(struct objtool_file *file)
427427
}
428428
}
429429

430+
/*
431+
* FIXME: For now, just ignore any alternatives which add retpolines. This is
432+
* a temporary hack, as it doesn't allow ORC to unwind from inside a retpoline.
433+
* But it at least allows objtool to understand the control flow *around* the
434+
* retpoline.
435+
*/
436+
staticintadd_nospec_ignores(structobjtool_file*file)
437+
{
438+
structsection*sec;
439+
structrela*rela;
440+
structinstruction*insn;
441+
442+
sec=find_section_by_name(file->elf,".rela.discard.nospec");
443+
if (!sec)
444+
return0;
445+
446+
list_for_each_entry(rela,&sec->rela_list,list) {
447+
if (rela->sym->type!=STT_SECTION) {
448+
WARN("unexpected relocation symbol type in %s",sec->name);
449+
return-1;
450+
}
451+
452+
insn=find_insn(file,rela->sym->sec,rela->addend);
453+
if (!insn) {
454+
WARN("bad .discard.nospec entry");
455+
return-1;
456+
}
457+
458+
insn->ignore_alts= true;
459+
}
460+
461+
return0;
462+
}
463+
430464
/*
431465
* Find the destination instructions for all jumps.
432466
*/
@@ -509,11 +543,18 @@ static int add_call_destinations(struct objtool_file *file)
509543
dest_off=insn->offset+insn->len+insn->immediate;
510544
insn->call_dest=find_symbol_by_offset(insn->sec,
511545
dest_off);
546+
/*
547+
* FIXME: Thanks to retpolines, it's now considered
548+
* normal for a function to call within itself. So
549+
* disable this warning for now.
550+
*/
551+
#if0
512552
if (!insn->call_dest) {
513553
WARN_FUNC("can't find call dest symbol at offset 0x%lx",
514554
insn->sec,insn->offset,dest_off);
515555
return-1;
516556
}
557+
#endif
517558
}elseif (rela->sym->type==STT_SECTION) {
518559
insn->call_dest=find_symbol_by_offset(rela->sym->sec,
519560
rela->addend+4);
@@ -678,12 +719,6 @@ static int add_special_section_alts(struct objtool_file *file)
678719
returnret;
679720

680721
list_for_each_entry_safe(special_alt,tmp,&special_alts,list) {
681-
alt=malloc(sizeof(*alt));
682-
if (!alt) {
683-
WARN("malloc failed");
684-
ret=-1;
685-
gotoout;
686-
}
687722

688723
orig_insn=find_insn(file,special_alt->orig_sec,
689724
special_alt->orig_off);
@@ -694,6 +729,10 @@ static int add_special_section_alts(struct objtool_file *file)
694729
gotoout;
695730
}
696731

732+
/* Ignore retpoline alternatives. */
733+
if (orig_insn->ignore_alts)
734+
continue;
735+
697736
new_insn=NULL;
698737
if (!special_alt->group||special_alt->new_len) {
699738
new_insn=find_insn(file,special_alt->new_sec,
@@ -719,6 +758,13 @@ static int add_special_section_alts(struct objtool_file *file)
719758
gotoout;
720759
}
721760

761+
alt=malloc(sizeof(*alt));
762+
if (!alt) {
763+
WARN("malloc failed");
764+
ret=-1;
765+
gotoout;
766+
}
767+
722768
alt->insn=new_insn;
723769
list_add_tail(&alt->list,&orig_insn->alts);
724770

@@ -1035,6 +1081,10 @@ static int decode_sections(struct objtool_file *file)
10351081

10361082
add_ignores(file);
10371083

1084+
ret=add_nospec_ignores(file);
1085+
if (ret)
1086+
returnret;
1087+
10381088
ret=add_jump_destinations(file);
10391089
if (ret)
10401090
returnret;

‎tools/objtool/check.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct instruction {
4444
unsignedintlen;
4545
unsignedchartype;
4646
unsigned longimmediate;
47-
boolalt_group,visited,dead_end,ignore,hint,save,restore;
47+
boolalt_group,visited,dead_end,ignore,hint,save,restore,ignore_alts;
4848
structsymbol*call_dest;
4949
structinstruction*jump_dest;
5050
structlist_headalts;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp