Skip to content

Commit 317f2a6

Browse files
author
Peter Zijlstra
committed
objtool: Convert instrumentation_{begin,end}() 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 bf5febe commit 317f2a6

File tree

5 files changed

+28
-48
lines changed

5 files changed

+28
-48
lines changed

include/linux/instrumentation.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
#ifdef CONFIG_NOINSTR_VALIDATION
66

7+
#include <linux/objtool.h>
78
#include <linux/stringify.h>
89

910
/* Begin/end of an instrumentation safe region */
1011
#define __instrumentation_begin(c) ({ \
1112
asm volatile(__stringify(c) ": nop\n\t" \
12-
".pushsection .discard.instr_begin\n\t" \
13-
".long " __stringify(c) "b - .\n\t" \
14-
".popsection\n\t" : : "i" (c)); \
13+
__ASM_ANNOTATE(__ASM_BREF(c), ANNOTYPE_INSTR_BEGIN)\
14+
: : "i" (c)); \
1515
})
1616
#define instrumentation_begin() __instrumentation_begin(__COUNTER__)
1717

@@ -48,9 +48,8 @@
4848
*/
4949
#define __instrumentation_end(c) ({ \
5050
asm volatile(__stringify(c) ": nop\n\t" \
51-
".pushsection .discard.instr_end\n\t" \
52-
".long " __stringify(c) "b - .\n\t" \
53-
".popsection\n\t" : : "i" (c)); \
51+
__ASM_ANNOTATE(__ASM_BREF(c), ANNOTYPE_INSTR_END) \
52+
: : "i" (c)); \
5453
})
5554
#define instrumentation_end() __instrumentation_end(__COUNTER__)
5655
#else /* !CONFIG_NOINSTR_VALIDATION */

include/linux/objtool.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,18 @@
5151
".long 998b\n\t" \
5252
".popsection\n\t"
5353

54-
#define ASM_ANNOTATE(type) \
55-
"911:\n\t" \
54+
#define __ASM_BREF(label) label ## b
55+
56+
#define __ASM_ANNOTATE(label, type) \
5657
".pushsection .discard.annotate_insn,\"M\",@progbits,8\n\t" \
57-
".long 911b - .\n\t" \
58+
".long " __stringify(label) " - .\n\t" \
5859
".long " __stringify(type) "\n\t" \
5960
".popsection\n\t"
6061

62+
#define ASM_ANNOTATE(type) \
63+
"911:\n\t" \
64+
__ASM_ANNOTATE(911b, type)
65+
6166
#define ANNOTATE_NOENDBR ASM_ANNOTATE(ANNOTYPE_NOENDBR)
6267

6368
#else /* __ASSEMBLY__ */
@@ -161,6 +166,7 @@
161166
#define UNWIND_HINT(type, sp_reg, sp_offset, signal) "\n\t"
162167
#define STACK_FRAME_NON_STANDARD(func)
163168
#define STACK_FRAME_NON_STANDARD_FP(func)
169+
#define __ASM_ANNOTATE(label, type)
164170
#define ASM_ANNOTATE(type)
165171
#define ANNOTATE_NOENDBR
166172
#define ASM_REACHABLE

include/linux/objtool_types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,7 @@ struct unwind_hint {
5959
*/
6060
#define ANNOTYPE_NOENDBR 1
6161
#define ANNOTYPE_RETPOLINE_SAFE 2
62+
#define ANNOTYPE_INSTR_BEGIN 3
63+
#define ANNOTYPE_INSTR_END 4
6264

6365
#endif /* _LINUX_OBJTOOL_TYPES_H */

tools/include/linux/objtool_types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,7 @@ struct unwind_hint {
5959
*/
6060
#define ANNOTYPE_NOENDBR 1
6161
#define ANNOTYPE_RETPOLINE_SAFE 2
62+
#define ANNOTYPE_INSTR_BEGIN 3
63+
#define ANNOTYPE_INSTR_END 4
6264

6365
#endif /* _LINUX_OBJTOOL_TYPES_H */

tools/objtool/check.c

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2440,48 +2440,19 @@ static int __annotate_retpoline_safe(int type, struct instruction *insn)
24402440
return 0;
24412441
}
24422442

2443-
static int read_instr_hints(struct objtool_file *file)
2443+
static int __annotate_instr(int type, struct instruction *insn)
24442444
{
2445-
struct section *rsec;
2446-
struct instruction *insn;
2447-
struct reloc *reloc;
2448-
2449-
rsec = find_section_by_name(file->elf, ".rela.discard.instr_end");
2450-
if (!rsec)
2451-
return 0;
2452-
2453-
for_each_reloc(rsec, reloc) {
2454-
if (reloc->sym->type != STT_SECTION) {
2455-
WARN("unexpected relocation symbol type in %s", rsec->name);
2456-
return -1;
2457-
}
2458-
2459-
insn = find_insn(file, reloc->sym->sec, reloc_addend(reloc));
2460-
if (!insn) {
2461-
WARN("bad .discard.instr_end entry");
2462-
return -1;
2463-
}
2445+
switch (type) {
2446+
case ANNOTYPE_INSTR_BEGIN:
2447+
insn->instr++;
2448+
break;
24642449

2450+
case ANNOTYPE_INSTR_END:
24652451
insn->instr--;
2466-
}
2467-
2468-
rsec = find_section_by_name(file->elf, ".rela.discard.instr_begin");
2469-
if (!rsec)
2470-
return 0;
2471-
2472-
for_each_reloc(rsec, reloc) {
2473-
if (reloc->sym->type != STT_SECTION) {
2474-
WARN("unexpected relocation symbol type in %s", rsec->name);
2475-
return -1;
2476-
}
2477-
2478-
insn = find_insn(file, reloc->sym->sec, reloc_addend(reloc));
2479-
if (!insn) {
2480-
WARN("bad .discard.instr_begin entry");
2481-
return -1;
2482-
}
2452+
break;
24832453

2484-
insn->instr++;
2454+
default:
2455+
break;
24852456
}
24862457

24872458
return 0;
@@ -2730,7 +2701,7 @@ static int decode_sections(struct objtool_file *file)
27302701
if (ret)
27312702
return ret;
27322703

2733-
ret = read_instr_hints(file);
2704+
ret = read_annotate(file, __annotate_instr);
27342705
if (ret)
27352706
return ret;
27362707

0 commit comments

Comments
 (0)