Skip to content

Commit 2116b34

Browse files
author
Peter Zijlstra
committed
objtool: Generic annotation infrastructure
Avoid endless .discard.foo sections for each annotation, create a single .discard.annotate_insn section that takes an annotation type along with the instruction. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Josh Poimboeuf <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 40384c8 commit 2116b34

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

include/linux/objtool.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@
5757
".long 998b\n\t" \
5858
".popsection\n\t"
5959

60+
#define ASM_ANNOTATE(type) \
61+
"911:\n\t" \
62+
".pushsection .discard.annotate_insn,\"M\",@progbits,8\n\t" \
63+
".long 911b - .\n\t" \
64+
".long " __stringify(type) "\n\t" \
65+
".popsection\n\t"
66+
6067
#else /* __ASSEMBLY__ */
6168

6269
/*
@@ -146,6 +153,14 @@
146153
.popsection
147154
.endm
148155

156+
.macro ANNOTATE type:req
157+
.Lhere_\@:
158+
.pushsection .discard.annotate_insn,"M",@progbits,8
159+
.long .Lhere_\@ - .
160+
.long \type
161+
.popsection
162+
.endm
163+
149164
#endif /* __ASSEMBLY__ */
150165

151166
#else /* !CONFIG_OBJTOOL */
@@ -155,6 +170,7 @@
155170
#define UNWIND_HINT(type, sp_reg, sp_offset, signal) "\n\t"
156171
#define STACK_FRAME_NON_STANDARD(func)
157172
#define STACK_FRAME_NON_STANDARD_FP(func)
173+
#define ASM_ANNOTATE(type)
158174
#define ANNOTATE_NOENDBR
159175
#define ASM_REACHABLE
160176
#else
@@ -167,6 +183,8 @@
167183
.endm
168184
.macro REACHABLE
169185
.endm
186+
.macro ANNOTATE type:req
187+
.endm
170188
#endif
171189

172190
#endif /* CONFIG_OBJTOOL */

tools/objtool/check.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,6 +2373,49 @@ static int read_unwind_hints(struct objtool_file *file)
23732373
return 0;
23742374
}
23752375

2376+
static int read_annotate(struct objtool_file *file, void (*func)(int type, struct instruction *insn))
2377+
{
2378+
struct section *sec;
2379+
struct instruction *insn;
2380+
struct reloc *reloc;
2381+
int type;
2382+
2383+
sec = find_section_by_name(file->elf, ".discard.annotate_insn");
2384+
if (!sec)
2385+
return 0;
2386+
2387+
if (!sec->rsec)
2388+
return 0;
2389+
2390+
if (sec->sh.sh_entsize != 8) {
2391+
static bool warned = false;
2392+
if (!warned) {
2393+
WARN("%s: dodgy linker, sh_entsize != 8", sec->name);
2394+
warned = true;
2395+
}
2396+
sec->sh.sh_entsize = 8;
2397+
}
2398+
2399+
for_each_reloc(sec->rsec, reloc) {
2400+
type = *(u32 *)(sec->data->d_buf + (reloc_idx(reloc) * sec->sh.sh_entsize) + 4);
2401+
2402+
insn = find_insn(file, reloc->sym->sec,
2403+
reloc->sym->offset + reloc_addend(reloc));
2404+
if (!insn) {
2405+
WARN("bad .discard.annotate_insn entry: %d of type %d", reloc_idx(reloc), type);
2406+
return -1;
2407+
}
2408+
2409+
func(type, insn);
2410+
}
2411+
2412+
return 0;
2413+
}
2414+
2415+
static void __annotate_nop(int type, struct instruction *insn)
2416+
{
2417+
}
2418+
23762419
static int read_noendbr_hints(struct objtool_file *file)
23772420
{
23782421
struct instruction *insn;
@@ -2670,6 +2713,8 @@ static int decode_sections(struct objtool_file *file)
26702713
if (ret)
26712714
return ret;
26722715

2716+
read_annotate(file, __annotate_nop);
2717+
26732718
/*
26742719
* Must be before read_unwind_hints() since that needs insn->noendbr.
26752720
*/

0 commit comments

Comments
 (0)