Skip to content

Commit c2bdd61

Browse files
jpoimboePeter Zijlstra
authored andcommitted
objtool: Extricate sls from stack validation
Extricate sls functionality from validate_branch() so they can be executed (or ported) independently from each other. Signed-off-by: Josh Poimboeuf <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Miroslav Benes <[email protected]> Link: https://lkml.kernel.org/r/2545c86ffa5f27497f0d0c542540ad4a4be3c5a5.1650300597.git.jpoimboe@redhat.com
1 parent 3c6f9f7 commit c2bdd61

File tree

1 file changed

+43
-13
lines changed

1 file changed

+43
-13
lines changed

tools/objtool/check.c

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3271,11 +3271,6 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,
32713271
switch (insn->type) {
32723272

32733273
case INSN_RETURN:
3274-
if (opts.sls && !insn->retpoline_safe &&
3275-
next_insn && next_insn->type != INSN_TRAP) {
3276-
WARN_FUNC("missing int3 after ret",
3277-
insn->sec, insn->offset);
3278-
}
32793274
return validate_return(func, insn, &state);
32803275

32813276
case INSN_CALL:
@@ -3319,13 +3314,6 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,
33193314
break;
33203315

33213316
case INSN_JUMP_DYNAMIC:
3322-
if (opts.sls && !insn->retpoline_safe &&
3323-
next_insn && next_insn->type != INSN_TRAP) {
3324-
WARN_FUNC("missing int3 after indirect jump",
3325-
insn->sec, insn->offset);
3326-
}
3327-
3328-
/* fallthrough */
33293317
case INSN_JUMP_DYNAMIC_CONDITIONAL:
33303318
if (is_sibling_call(insn)) {
33313319
ret = validate_sibling_call(file, insn, &state);
@@ -3845,6 +3833,41 @@ static int validate_ibt(struct objtool_file *file)
38453833
return warnings;
38463834
}
38473835

3836+
static int validate_sls(struct objtool_file *file)
3837+
{
3838+
struct instruction *insn, *next_insn;
3839+
int warnings = 0;
3840+
3841+
for_each_insn(file, insn) {
3842+
next_insn = next_insn_same_sec(file, insn);
3843+
3844+
if (insn->retpoline_safe)
3845+
continue;
3846+
3847+
switch (insn->type) {
3848+
case INSN_RETURN:
3849+
if (!next_insn || next_insn->type != INSN_TRAP) {
3850+
WARN_FUNC("missing int3 after ret",
3851+
insn->sec, insn->offset);
3852+
warnings++;
3853+
}
3854+
3855+
break;
3856+
case INSN_JUMP_DYNAMIC:
3857+
if (!next_insn || next_insn->type != INSN_TRAP) {
3858+
WARN_FUNC("missing int3 after indirect jump",
3859+
insn->sec, insn->offset);
3860+
warnings++;
3861+
}
3862+
break;
3863+
default:
3864+
break;
3865+
}
3866+
}
3867+
3868+
return warnings;
3869+
}
3870+
38483871
static int validate_reachable_instructions(struct objtool_file *file)
38493872
{
38503873
struct instruction *insn;
@@ -3913,7 +3936,7 @@ int check(struct objtool_file *file)
39133936
warnings += ret;
39143937
}
39153938

3916-
if (opts.stackval || opts.orc || opts.uaccess || opts.sls) {
3939+
if (opts.stackval || opts.orc || opts.uaccess) {
39173940
ret = validate_functions(file);
39183941
if (ret < 0)
39193942
goto out;
@@ -3939,6 +3962,13 @@ int check(struct objtool_file *file)
39393962
warnings += ret;
39403963
}
39413964

3965+
if (opts.sls) {
3966+
ret = validate_sls(file);
3967+
if (ret < 0)
3968+
goto out;
3969+
warnings += ret;
3970+
}
3971+
39423972
ret = create_static_call_sections(file);
39433973
if (ret < 0)
39443974
goto out;

0 commit comments

Comments
 (0)