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

Jiri Slaby (SUSE) posted 46 patches 3 years, 1 month ago
[PATCH 10/46] static_call, lto: Mark func_a() as __visible_on_lto
Posted by Jiri Slaby (SUSE) 3 years, 1 month ago
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(-)

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)
-- 
2.38.1
Re: [PATCH 10/46] static_call, lto: Mark func_a() as __visible_on_lto
Posted by Peter Zijlstra 3 years, 1 month ago
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.
Re: [PATCH 10/46] static_call, lto: Mark func_a() as __visible_on_lto
Posted by Andi Kleen 3 years, 1 month ago
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