[PATCH v3 2/4] objtool: Add support for C jump tables

From: Josh Poimboeuf
Date: Wed Jun 26 2019 - 20:36:28 EST


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 a standard: objtool will
automatically recognize any static local jump table named "jump_table".

Signed-off-by: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
Acked-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
---
tools/objtool/check.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 172f99195726..8341c2fff14f 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -18,6 +18,8 @@

#define FAKE_JUMP_OFFSET -1

+#define JUMP_TABLE_SYM_PREFIX "jump_table."
+
struct alternative {
struct list_head list;
struct instruction *insn;
@@ -997,6 +999,7 @@ static struct rela *find_switch_table(struct objtool_file *file,
struct instruction *orig_insn = insn;
struct section *rodata_sec;
unsigned long table_offset;
+ struct symbol *sym;

/*
* Backward search using the @first_jump_src links, these help avoid
@@ -1035,9 +1038,18 @@ 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. Each jump table should be a static
+ * local const array named "jump_table" for objtool to
+ * recognize it. Note: GCC will add a numbered suffix to the
+ * ELF symbol name, like "jump_table.12345", which it does for
+ * all static local variables.
*/
- if (find_symbol_containing(rodata_sec, table_offset))
+ sym = find_symbol_containing(rodata_sec, table_offset);
+ if (sym && strncmp(sym->name, JUMP_TABLE_SYM_PREFIX,
+ strlen(JUMP_TABLE_SYM_PREFIX)))
continue;

rodata_rela = find_rela_by_dest(rodata_sec, table_offset);
--
2.20.1