Skip to content

Commit 280981d

Browse files
sathvika-vmpe
authored andcommitted
objtool: Add --mnop as an option to --mcount
Some architectures (powerpc) may not support ftrace locations being nop'ed out at build time. Introduce CONFIG_HAVE_OBJTOOL_NOP_MCOUNT for objtool, as a means for architectures to enable nop'ing of ftrace locations. Add --mnop as an option to objtool --mcount, to indicate support for the same. Also, make sure that --mnop can be passed as an option to objtool only when --mcount is passed. Tested-by: Naveen N. Rao <[email protected]> Reviewed-by: Naveen N. Rao <[email protected]> Acked-by: Josh Poimboeuf <[email protected]> Reviewed-by: Christophe Leroy <[email protected]> Signed-off-by: Sathvika Vasireddy <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 86ea7f3 commit 280981d

File tree

7 files changed

+39
-10
lines changed

7 files changed

+39
-10
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,9 @@ ifdef CONFIG_FTRACE_MCOUNT_USE_CC
933933
endif
934934
endif
935935
ifdef CONFIG_FTRACE_MCOUNT_USE_OBJTOOL
936-
CC_FLAGS_USING += -DCC_USING_NOP_MCOUNT
936+
ifdef CONFIG_HAVE_OBJTOOL_NOP_MCOUNT
937+
CC_FLAGS_USING += -DCC_USING_NOP_MCOUNT
938+
endif
937939
endif
938940
ifdef CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT
939941
ifdef CONFIG_HAVE_C_RECORDMCOUNT

arch/x86/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ config X86
195195
select HAVE_CONTEXT_TRACKING_USER_OFFSTACK if HAVE_CONTEXT_TRACKING_USER
196196
select HAVE_C_RECORDMCOUNT
197197
select HAVE_OBJTOOL_MCOUNT if HAVE_OBJTOOL
198+
select HAVE_OBJTOOL_NOP_MCOUNT if HAVE_OBJTOOL_MCOUNT
198199
select HAVE_BUILDTIME_MCOUNT_SORT
199200
select HAVE_DEBUG_KMEMLEAK
200201
select HAVE_DMA_CONTIGUOUS

kernel/trace/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ config HAVE_OBJTOOL_MCOUNT
8282
help
8383
Arch supports objtool --mcount
8484

85+
config HAVE_OBJTOOL_NOP_MCOUNT
86+
bool
87+
help
88+
Arch supports the objtool options --mcount with --mnop.
89+
An architecture can select this if it wants to enable nop'ing
90+
of ftrace locations.
91+
8592
config HAVE_C_RECORDMCOUNT
8693
bool
8794
help

scripts/Makefile.lib

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ objtool-args-$(CONFIG_HAVE_JUMP_LABEL_HACK) += --hacks=jump_label
256256
objtool-args-$(CONFIG_HAVE_NOINSTR_HACK) += --hacks=noinstr
257257
objtool-args-$(CONFIG_X86_KERNEL_IBT) += --ibt
258258
objtool-args-$(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL) += --mcount
259+
ifdef CONFIG_FTRACE_MCOUNT_USE_OBJTOOL
260+
objtool-args-$(CONFIG_HAVE_OBJTOOL_NOP_MCOUNT) += --mnop
261+
endif
259262
objtool-args-$(CONFIG_UNWINDER_ORC) += --orc
260263
objtool-args-$(CONFIG_RETPOLINE) += --retpoline
261264
objtool-args-$(CONFIG_RETHUNK) += --rethunk

tools/objtool/builtin-check.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ const struct option check_options[] = {
8282
OPT_BOOLEAN(0, "dry-run", &opts.dryrun, "don't write modifications"),
8383
OPT_BOOLEAN(0, "link", &opts.link, "object is a linked object"),
8484
OPT_BOOLEAN(0, "module", &opts.module, "object is part of a kernel module"),
85+
OPT_BOOLEAN(0, "mnop", &opts.mnop, "nop out mcount call sites"),
8586
OPT_BOOLEAN(0, "no-unreachable", &opts.no_unreachable, "skip 'unreachable instruction' warnings"),
8687
OPT_BOOLEAN(0, "sec-address", &opts.sec_address, "print section addresses in warnings"),
8788
OPT_BOOLEAN(0, "stats", &opts.stats, "print statistics"),
@@ -150,6 +151,16 @@ static bool opts_valid(void)
150151
return false;
151152
}
152153

154+
static bool mnop_opts_valid(void)
155+
{
156+
if (opts.mnop && !opts.mcount) {
157+
ERROR("--mnop requires --mcount");
158+
return false;
159+
}
160+
161+
return true;
162+
}
163+
153164
static bool link_opts_valid(struct objtool_file *file)
154165
{
155166
if (opts.link)
@@ -198,6 +209,9 @@ int objtool_run(int argc, const char **argv)
198209
if (!file)
199210
return 1;
200211

212+
if (!mnop_opts_valid())
213+
return 1;
214+
201215
if (!link_opts_valid(file))
202216
return 1;
203217

tools/objtool/check.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,17 +1256,18 @@ static void annotate_call_site(struct objtool_file *file,
12561256
if (opts.mcount && sym->fentry) {
12571257
if (sibling)
12581258
WARN_FUNC("Tail call to __fentry__ !?!?", insn->sec, insn->offset);
1259+
if (opts.mnop) {
1260+
if (reloc) {
1261+
reloc->type = R_NONE;
1262+
elf_write_reloc(file->elf, reloc);
1263+
}
12591264

1260-
if (reloc) {
1261-
reloc->type = R_NONE;
1262-
elf_write_reloc(file->elf, reloc);
1263-
}
1264-
1265-
elf_write_insn(file->elf, insn->sec,
1266-
insn->offset, insn->len,
1267-
arch_nop_insn(insn->len));
1265+
elf_write_insn(file->elf, insn->sec,
1266+
insn->offset, insn->len,
1267+
arch_nop_insn(insn->len));
12681268

1269-
insn->type = INSN_NOP;
1269+
insn->type = INSN_NOP;
1270+
}
12701271

12711272
list_add_tail(&insn->call_node, &file->mcount_loc_list);
12721273
return;

tools/objtool/include/objtool/builtin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct opts {
3131
bool backup;
3232
bool dryrun;
3333
bool link;
34+
bool mnop;
3435
bool module;
3536
bool no_unreachable;
3637
bool sec_address;

0 commit comments

Comments
 (0)