Skip to content

Commit 112765c

Browse files
author
Peter Zijlstra
committed
objtool: Convert ANNOTATE_INTRA_FUNCTION_CALL to ANNOTATE
Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Josh Poimboeuf <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent f0cd57c commit 112765c

File tree

4 files changed

+47
-67
lines changed

4 files changed

+47
-67
lines changed

include/linux/objtool.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,6 @@
6767

6868
#else /* __ASSEMBLY__ */
6969

70-
/*
71-
* This macro indicates that the following intra-function call is valid.
72-
* Any non-annotated intra-function call will cause objtool to issue a warning.
73-
*/
74-
#define ANNOTATE_INTRA_FUNCTION_CALL \
75-
999: \
76-
.pushsection .discard.intra_function_calls; \
77-
.long 999b; \
78-
.popsection;
79-
8070
/*
8171
* In asm, there are two kinds of code: normal C-type callable functions and
8272
* the rest. The normal callable functions can be called by other code, and
@@ -154,6 +144,12 @@
154144

155145
#define ANNOTATE_NOENDBR ANNOTATE type=ANNOTYPE_NOENDBR
156146

147+
/*
148+
* This macro indicates that the following intra-function call is valid.
149+
* Any non-annotated intra-function call will cause objtool to issue a warning.
150+
*/
151+
#define ANNOTATE_INTRA_FUNCTION_CALL ANNOTATE type=ANNOTYPE_INTRA_FUNCTION_CALL
152+
157153
#endif /* __ASSEMBLY__ */
158154

159155
#else /* !CONFIG_OBJTOOL */

include/linux/objtool_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,6 @@ struct unwind_hint {
6363
#define ANNOTYPE_INSTR_END 4
6464
#define ANNOTYPE_UNRET_BEGIN 5
6565
#define ANNOTYPE_IGNORE_ALTS 6
66+
#define ANNOTYPE_INTRA_FUNCTION_CALL 7
6667

6768
#endif /* _LINUX_OBJTOOL_TYPES_H */

tools/include/linux/objtool_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,6 @@ struct unwind_hint {
6363
#define ANNOTYPE_INSTR_END 4
6464
#define ANNOTYPE_UNRET_BEGIN 5
6565
#define ANNOTYPE_IGNORE_ALTS 6
66+
#define ANNOTYPE_INTRA_FUNCTION_CALL 7
6667

6768
#endif /* _LINUX_OBJTOOL_TYPES_H */

tools/objtool/check.c

Lines changed: 39 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,7 +2339,8 @@ static int read_unwind_hints(struct objtool_file *file)
23392339
return 0;
23402340
}
23412341

2342-
static int read_annotate(struct objtool_file *file, int (*func)(int type, struct instruction *insn))
2342+
static int read_annotate(struct objtool_file *file,
2343+
int (*func)(struct objtool_file *file, int type, struct instruction *insn))
23432344
{
23442345
struct section *sec;
23452346
struct instruction *insn;
@@ -2372,15 +2373,15 @@ static int read_annotate(struct objtool_file *file, int (*func)(int type, struct
23722373
return -1;
23732374
}
23742375

2375-
ret = func(type, insn);
2376+
ret = func(file, type, insn);
23762377
if (ret < 0)
23772378
return ret;
23782379
}
23792380

23802381
return 0;
23812382
}
23822383

2383-
static int __annotate_ignore_alts(int type, struct instruction *insn)
2384+
static int __annotate_ignore_alts(struct objtool_file *file, int type, struct instruction *insn)
23842385
{
23852386
if (type != ANNOTYPE_IGNORE_ALTS)
23862387
return 0;
@@ -2389,7 +2390,7 @@ static int __annotate_ignore_alts(int type, struct instruction *insn)
23892390
return 0;
23902391
}
23912392

2392-
static int __annotate_noendbr(int type, struct instruction *insn)
2393+
static int __annotate_noendbr(struct objtool_file *file, int type, struct instruction *insn)
23932394
{
23942395
if (type != ANNOTYPE_NOENDBR)
23952396
return 0;
@@ -2398,7 +2399,37 @@ static int __annotate_noendbr(int type, struct instruction *insn)
23982399
return 0;
23992400
}
24002401

2401-
static int __annotate_retpoline_safe(int type, struct instruction *insn)
2402+
static int __annotate_ifc(struct objtool_file *file, int type, struct instruction *insn)
2403+
{
2404+
unsigned long dest_off;
2405+
2406+
if (type != ANNOTYPE_INTRA_FUNCTION_CALL)
2407+
return 0;
2408+
2409+
if (insn->type != INSN_CALL) {
2410+
WARN_INSN(insn, "intra_function_call not a direct call");
2411+
return -1;
2412+
}
2413+
2414+
/*
2415+
* Treat intra-function CALLs as JMPs, but with a stack_op.
2416+
* See add_call_destinations(), which strips stack_ops from
2417+
* normal CALLs.
2418+
*/
2419+
insn->type = INSN_JUMP_UNCONDITIONAL;
2420+
2421+
dest_off = arch_jump_destination(insn);
2422+
insn->jump_dest = find_insn(file, insn->sec, dest_off);
2423+
if (!insn->jump_dest) {
2424+
WARN_INSN(insn, "can't find call dest at %s+0x%lx",
2425+
insn->sec->name, dest_off);
2426+
return -1;
2427+
}
2428+
2429+
return 0;
2430+
}
2431+
2432+
static int __annotate_retpoline_safe(struct objtool_file *file, int type, struct instruction *insn)
24022433
{
24032434
if (type != ANNOTYPE_RETPOLINE_SAFE)
24042435
return 0;
@@ -2415,7 +2446,7 @@ static int __annotate_retpoline_safe(int type, struct instruction *insn)
24152446
return 0;
24162447
}
24172448

2418-
static int __annotate_instr(int type, struct instruction *insn)
2449+
static int __annotate_instr(struct objtool_file *file, int type, struct instruction *insn)
24192450
{
24202451
switch (type) {
24212452
case ANNOTYPE_INSTR_BEGIN:
@@ -2433,7 +2464,7 @@ static int __annotate_instr(int type, struct instruction *insn)
24332464
return 0;
24342465
}
24352466

2436-
static int __annotate_unret(int type, struct instruction *insn)
2467+
static int __annotate_unret(struct objtool_file *file, int type, struct instruction *insn)
24372468
{
24382469
if (type != ANNOTYPE_UNRET_BEGIN)
24392470
return 0;
@@ -2443,55 +2474,6 @@ static int __annotate_unret(int type, struct instruction *insn)
24432474

24442475
}
24452476

2446-
static int read_intra_function_calls(struct objtool_file *file)
2447-
{
2448-
struct instruction *insn;
2449-
struct section *rsec;
2450-
struct reloc *reloc;
2451-
2452-
rsec = find_section_by_name(file->elf, ".rela.discard.intra_function_calls");
2453-
if (!rsec)
2454-
return 0;
2455-
2456-
for_each_reloc(rsec, reloc) {
2457-
unsigned long dest_off;
2458-
2459-
if (reloc->sym->type != STT_SECTION) {
2460-
WARN("unexpected relocation symbol type in %s",
2461-
rsec->name);
2462-
return -1;
2463-
}
2464-
2465-
insn = find_insn(file, reloc->sym->sec, reloc_addend(reloc));
2466-
if (!insn) {
2467-
WARN("bad .discard.intra_function_call entry");
2468-
return -1;
2469-
}
2470-
2471-
if (insn->type != INSN_CALL) {
2472-
WARN_INSN(insn, "intra_function_call not a direct call");
2473-
return -1;
2474-
}
2475-
2476-
/*
2477-
* Treat intra-function CALLs as JMPs, but with a stack_op.
2478-
* See add_call_destinations(), which strips stack_ops from
2479-
* normal CALLs.
2480-
*/
2481-
insn->type = INSN_JUMP_UNCONDITIONAL;
2482-
2483-
dest_off = arch_jump_destination(insn);
2484-
insn->jump_dest = find_insn(file, insn->sec, dest_off);
2485-
if (!insn->jump_dest) {
2486-
WARN_INSN(insn, "can't find call dest at %s+0x%lx",
2487-
insn->sec->name, dest_off);
2488-
return -1;
2489-
}
2490-
}
2491-
2492-
return 0;
2493-
}
2494-
24952477
/*
24962478
* Return true if name matches an instrumentation function, where calls to that
24972479
* function from noinstr code can safely be removed, but compilers won't do so.
@@ -2630,7 +2612,7 @@ static int decode_sections(struct objtool_file *file)
26302612
* Must be before add_call_destination(); it changes INSN_CALL to
26312613
* INSN_JUMP.
26322614
*/
2633-
ret = read_intra_function_calls(file);
2615+
ret = read_annotate(file, __annotate_ifc);
26342616
if (ret)
26352617
return ret;
26362618

0 commit comments

Comments
 (0)