ANDROID: export: cfi: fix ksymtab addresses

With CONFIG_CFI_CLANG, LLVM replaces function references with CFI
jump table addresses to allow type checking with indirect calls. This is
unnecessary in ksymtab, so this change uses inline assembly to emit
ksymtab entries that point to the actual function instead when CFI is
enabled.

Bug: 145210207
Change-Id: I894af2c7df476eb00d656c7692a33b25de31e26d
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
This commit is contained in:
Sami Tolvanen 2019-12-03 11:05:45 -08:00 committed by Alistair Delva
parent 08f67ef189
commit e135c46cdf

View File

@ -63,12 +63,39 @@ struct kernel_symbol {
int namespace_offset;
};
#else
#ifdef CONFIG_CFI_CLANG
#include <linux/compiler.h>
/*
* With -fno-sanitize-cfi-canonical-jump-tables, the compiler replaces
* references to functions with jump table addresses. Use inline assembly
* to emit ksymtab entries that point to the actual function instead.
*/
#define ___KSYMTAB_ENTRY(sym, sec, size) \
__ADDRESSABLE(sym) \
asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \
" .balign " #size " \n" \
"__ksymtab_" #sym ": \n" \
" ." #size "byte " #sym " \n" \
" ." #size "byte __kstrtab_" #sym " \n" \
" ." #size "byte __kstrtabns_" #sym " \n" \
" .previous \n")
#ifdef CONFIG_64BIT
#define __KSYMTAB_ENTRY(sym, sec) ___KSYMTAB_ENTRY(sym, sec, 8)
#else
#define __KSYMTAB_ENTRY(sym, sec) ___KSYMTAB_ENTRY(sym, sec, 4)
#endif
#else /* !CONFIG_CFI_CLANG */
#define __KSYMTAB_ENTRY(sym, sec) \
static const struct kernel_symbol __ksymtab_##sym \
__attribute__((section("___ksymtab" sec "+" #sym), used)) \
__aligned(sizeof(void *)) \
= { (unsigned long)&sym, __kstrtab_##sym, __kstrtabns_##sym }
#endif
struct kernel_symbol {
unsigned long value;
const char *name;