[10/46] static_call, lto: Mark func_a() as __visible_on_lto

Message ID 20221114114344.18650-11-jirislaby@kernel.org
State New
Headers
Series gcc-LTO support for the kernel |

Commit Message

Jiri Slaby Nov. 14, 2022, 11:43 a.m. UTC
  From: Andi Kleen <andi@firstfloor.org>

Symbols referenced from assembler (either directly or e.f. from
DEFINE_STATIC_KEY()) need to be global and visible in gcc LTO because
they could end up in a different object file than the assembler. This
can lead to linker errors without this patch.

So mark func_a() as __visible_on_lto as it was static.

[js] use __visible_on_lto

Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Josh Poimboeuf <jpoimboe@kernel.org>
Cc: Jason Baron <jbaron@akamai.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Andi Kleen <andi@firstfloor.org>
Signed-off-by: Martin Liska <mliska@suse.cz>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 kernel/static_call_inline.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
  

Comments

Peter Zijlstra Nov. 14, 2022, 3:54 p.m. UTC | #1
On Mon, Nov 14, 2022 at 12:43:08PM +0100, Jiri Slaby (SUSE) wrote:

> -static int func_a(int x)
> +__visible_on_lto int sc_func_a(int x)

>  } static_call_data [] __initdata = {
>        { NULL,   2, 3 },
>        { func_b, 2, 4 },
> -      { func_a, 2, 3 }
> +      { sc_func_a, 2, 3 }
>  };

I must say I really hate this. Also, with address taken, it still
eliminiates it?

This whole GCC-LTO sounds sub-par.
  
Andi Kleen Nov. 14, 2022, 8:29 p.m. UTC | #2
On Mon, Nov 14, 2022 at 04:54:16PM +0100, Peter Zijlstra wrote:
> On Mon, Nov 14, 2022 at 12:43:08PM +0100, Jiri Slaby (SUSE) wrote:
> 
> > -static int func_a(int x)
> > +__visible_on_lto int sc_func_a(int x)
> 
> >  } static_call_data [] __initdata = {
> >        { NULL,   2, 3 },
> >        { func_b, 2, 4 },
> > -      { func_a, 2, 3 }
> > +      { sc_func_a, 2, 3 }
> >  };
> 
> I must say I really hate this. Also, with address taken, it still
> eliminiates it?

It doesn't eliminate it, but makes it static, which causes the label to
change, so the assembler reference breaks.

-Andi
  

Patch

diff --git a/kernel/static_call_inline.c b/kernel/static_call_inline.c
index dc5665b62814..6933b4437597 100644
--- a/kernel/static_call_inline.c
+++ b/kernel/static_call_inline.c
@@ -501,7 +501,7 @@  early_initcall(static_call_init);
 
 #ifdef CONFIG_STATIC_CALL_SELFTEST
 
-static int func_a(int x)
+__visible_on_lto int sc_func_a(int x)
 {
 	return x+1;
 }
@@ -511,7 +511,7 @@  static int func_b(int x)
 	return x+2;
 }
 
-DEFINE_STATIC_CALL(sc_selftest, func_a);
+DEFINE_STATIC_CALL(sc_selftest, sc_func_a);
 
 static struct static_call_data {
       int (*func)(int);
@@ -520,7 +520,7 @@  static struct static_call_data {
 } static_call_data [] __initdata = {
       { NULL,   2, 3 },
       { func_b, 2, 4 },
-      { func_a, 2, 3 }
+      { sc_func_a, 2, 3 }
 };
 
 static int __init test_static_call_init(void)