From: tip-bot for Josh Poimboeuf <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: peterz@infradead.org, ast@kernel.org, kasong@redhat.com,
hpa@zytor.com, jpoimboe@redhat.com, linux-kernel@vger.kernel.org,
tglx@linutronix.de, rostedt@goodmis.org, daniel@iogearbox.net,
mingo@kernel.org, songliubraving@fb.com, bp@alien8.de
Subject: [tip:x86/urgent] objtool: Add support for C jump tables
Date: Fri, 28 Jun 2019 22:58:08 -0700 [thread overview]
Message-ID: <tip-d31acc2cc6ee313cee663ffed89c6a8f807bd87b@git.kernel.org> (raw)
In-Reply-To: <0ba2ca30442b16b97165992381ce643dc27b3d1a.1561685471.git.jpoimboe@redhat.com>
Commit-ID: d31acc2cc6ee313cee663ffed89c6a8f807bd87b
Gitweb: https://git.kernel.org/tip/d31acc2cc6ee313cee663ffed89c6a8f807bd87b
Author: Josh Poimboeuf <jpoimboe@redhat.com>
AuthorDate: Thu, 27 Jun 2019 20:50:46 -0500
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitDate: Sat, 29 Jun 2019 07:55:13 +0200
objtool: Add support for C jump tables
Objtool doesn't know how to read C jump tables, so it has to whitelist
functions which use them, causing missing ORC unwinder data for such
functions, e.g. ___bpf_prog_run().
C jump tables are very similar to GCC switch jump tables, which objtool
already knows how to read. So adding support for C jump tables is easy.
It just needs to be able to find the tables and distinguish them from
other data.
To allow the jump tables to be found, create an __annotate_jump_table
macro which can be used to annotate them.
The annotation is done by placing the jump table in an
.rodata..c_jump_table section. The '.rodata' prefix ensures that the data
will be placed in the rodata section by the vmlinux linker script. The
double periods are part of an existing convention which distinguishes
kernel sections from GCC sections.
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <songliubraving@fb.com>
Cc: Kairui Song <kasong@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lkml.kernel.org/r/0ba2ca30442b16b97165992381ce643dc27b3d1a.1561685471.git.jpoimboe@redhat.com
---
include/linux/compiler.h | 5 +++++
tools/objtool/check.c | 27 ++++++++++++++++++++-------
2 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 8aaf7cd026b0..f0fd5636fddb 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -116,9 +116,14 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
".pushsection .discard.unreachable\n\t" \
".long 999b - .\n\t" \
".popsection\n\t"
+
+/* Annotate a C jump table to allow objtool to follow the code flow */
+#define __annotate_jump_table __section(".rodata..c_jump_table")
+
#else
#define annotate_reachable()
#define annotate_unreachable()
+#define __annotate_jump_table
#endif
#ifndef ASM_UNREACHABLE
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 172f99195726..27818a93f0b1 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -18,6 +18,8 @@
#define FAKE_JUMP_OFFSET -1
+#define C_JUMP_TABLE_SECTION ".rodata..c_jump_table"
+
struct alternative {
struct list_head list;
struct instruction *insn;
@@ -1035,9 +1037,15 @@ static struct rela *find_switch_table(struct objtool_file *file,
/*
* Make sure the .rodata address isn't associated with a
- * symbol. gcc jump tables are anonymous data.
+ * symbol. GCC jump tables are anonymous data.
+ *
+ * Also support C jump tables which are in the same format as
+ * switch jump tables. For objtool to recognize them, they
+ * need to be placed in the C_JUMP_TABLE_SECTION section. They
+ * have symbols associated with them.
*/
- if (find_symbol_containing(rodata_sec, table_offset))
+ if (find_symbol_containing(rodata_sec, table_offset) &&
+ strcmp(rodata_sec->name, C_JUMP_TABLE_SECTION))
continue;
rodata_rela = find_rela_by_dest(rodata_sec, table_offset);
@@ -1277,13 +1285,18 @@ static void mark_rodata(struct objtool_file *file)
bool found = false;
/*
- * This searches for the .rodata section or multiple .rodata.func_name
- * sections if -fdata-sections is being used. The .str.1.1 and .str.1.8
- * rodata sections are ignored as they don't contain jump tables.
+ * Search for the following rodata sections, each of which can
+ * potentially contain jump tables:
+ *
+ * - .rodata: can contain GCC switch tables
+ * - .rodata.<func>: same, if -fdata-sections is being used
+ * - .rodata..c_jump_table: contains C annotated jump tables
+ *
+ * .rodata.str1.* sections are ignored; they don't contain jump tables.
*/
for_each_sec(file, sec) {
- if (!strncmp(sec->name, ".rodata", 7) &&
- !strstr(sec->name, ".str1.")) {
+ if ((!strncmp(sec->name, ".rodata", 7) && !strstr(sec->name, ".str1.")) ||
+ !strcmp(sec->name, C_JUMP_TABLE_SECTION)) {
sec->rodata = true;
found = true;
}
next prev parent reply other threads:[~2019-06-29 5:59 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-28 1:50 [PATCH v4 0/2] x86: bpf unwinder fixes Josh Poimboeuf
2019-06-28 1:50 ` [PATCH v4 1/2] objtool: Add support for C jump tables Josh Poimboeuf
2019-06-29 5:58 ` tip-bot for Josh Poimboeuf [this message]
2019-07-09 12:01 ` [tip:x86/debug] " tip-bot for Josh Poimboeuf
2019-06-28 1:50 ` [PATCH v4 2/2] bpf: Fix ORC unwinding in non-JIT BPF code Josh Poimboeuf
2019-06-28 15:37 ` Alexei Starovoitov
2019-06-29 5:58 ` [tip:x86/urgent] " tip-bot for Josh Poimboeuf
2019-07-06 20:29 ` Ingo Molnar
2019-07-07 1:32 ` Josh Poimboeuf
2019-07-07 5:52 ` Josh Poimboeuf
2019-07-08 22:15 ` Alexei Starovoitov
2019-07-08 22:38 ` Josh Poimboeuf
2019-07-08 22:49 ` Alexei Starovoitov
2019-07-08 22:53 ` Josh Poimboeuf
2019-07-08 23:02 ` Josh Poimboeuf
2019-07-08 23:16 ` Alexei Starovoitov
2019-07-09 17:47 ` Josh Poimboeuf
2019-07-09 18:02 ` Alexei Starovoitov
2019-07-09 19:17 ` Josh Poimboeuf
2019-07-09 19:26 ` Daniel Borkmann
2019-07-09 12:02 ` [tip:x86/debug] " tip-bot for Josh Poimboeuf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tip-d31acc2cc6ee313cee663ffed89c6a8f807bd87b@git.kernel.org \
--to=tipbot@zytor.com \
--cc=ast@kernel.org \
--cc=bp@alien8.de \
--cc=daniel@iogearbox.net \
--cc=hpa@zytor.com \
--cc=jpoimboe@redhat.com \
--cc=kasong@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=songliubraving@fb.com \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox