Message ID | 20220401201916.1487500-3-samitolvanen@google.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | cfi: Use __builtin_function_start | expand |
On Fri, Apr 01, 2022 at 01:19:15PM -0700, Sami Tolvanen wrote: > Use __builtin_function_start() to implement the function_nocfi() macro > when CONFIG_CFI_CLANG is selected. > > Signed-off-by: Sami Tolvanen <samitolvanen@google.com> > --- > include/linux/compiler-clang.h | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h > index babb1347148c..c84fec767445 100644 > --- a/include/linux/compiler-clang.h > +++ b/include/linux/compiler-clang.h > @@ -69,6 +69,16 @@ > #define __nocfi __attribute__((__no_sanitize__("cfi"))) > #define __cficanonical __attribute__((__cfi_canonical_jump_table__)) > > +#if defined(CONFIG_CFI_CLANG) > +/* > + * With CONFIG_CFI_CLANG, the compiler replaces function address > + * references with the address of the function's CFI jump table > + * entry. The function_nocfi macro always returns the address of the > + * actual function instead. > + */ > +#define function_nocfi(x) __builtin_function_start(x) > +#endif As a heads-up, with patches 1 and 2 applied (but not patch 3), we have two definitions of function_nocfi(), which casues the compiler to scream for every object: | In file included from <built-in>:3: | In file included from ././include/linux/compiler_types.h:107: | ./arch/arm64/include/asm/compiler.h:33:9: warning: 'function_nocfi' macro redefined [-Wmacro-redefined] | #define function_nocfi(x) ({ \ | ^ | ./include/linux/compiler-clang.h:79:9: note: previous definition is here | #define function_nocfi(x) __builtin_function_start(x) | ^ | 1 warning generated. ... which would be painful for bisection. I suspect It's probably worth folding patches 2 and 3 together to avoid that? Arguably we could fold the entire series together into one commit at that point. Thanks, Mark.
diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h index babb1347148c..c84fec767445 100644 --- a/include/linux/compiler-clang.h +++ b/include/linux/compiler-clang.h @@ -69,6 +69,16 @@ #define __nocfi __attribute__((__no_sanitize__("cfi"))) #define __cficanonical __attribute__((__cfi_canonical_jump_table__)) +#if defined(CONFIG_CFI_CLANG) +/* + * With CONFIG_CFI_CLANG, the compiler replaces function address + * references with the address of the function's CFI jump table + * entry. The function_nocfi macro always returns the address of the + * actual function instead. + */ +#define function_nocfi(x) __builtin_function_start(x) +#endif + /* * Turn individual warnings and errors on and off locally, depending * on version.
Use __builtin_function_start() to implement the function_nocfi() macro when CONFIG_CFI_CLANG is selected. Signed-off-by: Sami Tolvanen <samitolvanen@google.com> --- include/linux/compiler-clang.h | 10 ++++++++++ 1 file changed, 10 insertions(+)