2022-04-29 11:47:53

by Peter Zijlstra

[permalink] [raw]
Subject: [PATCH] linkage: Fix issue with missing symbol size


Occasionally, typically when a function doesn't end with 'ret', an
alias on that function will have 0 size.

The difference between what GCC generates and our linkage magic, is
that GCC doesn't appear to provide .size for the alias'ed symbol at
all. And indeed, removing this directive cures the issue.

Additionally, GCC also doesn't emit .type for alias symbols either, so
also omit that.

Fixes: e0891269a8c2 ("linkage: add SYM_FUNC_ALIAS{,_LOCAL,_WEAK}()")
Suggested-by: Mark Rutland <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
---
include/linux/linkage.h | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)

--- a/include/linux/linkage.h
+++ b/include/linux/linkage.h
@@ -171,12 +171,9 @@

/* SYM_ALIAS -- use only if you have to */
#ifndef SYM_ALIAS
-#define SYM_ALIAS(alias, name, sym_type, linkage) \
- linkage(alias) ASM_NL \
- .set alias, name ASM_NL \
- .type alias sym_type ASM_NL \
- .set .L__sym_size_##alias, .L__sym_size_##name ASM_NL \
- .size alias, .L__sym_size_##alias
+#define SYM_ALIAS(alias, name, linkage) \
+ linkage(alias) ASM_NL \
+ .set alias, name ASM_NL
#endif

/* === code annotations === */
@@ -261,7 +258,7 @@
*/
#ifndef SYM_FUNC_ALIAS
#define SYM_FUNC_ALIAS(alias, name) \
- SYM_ALIAS(alias, name, SYM_T_FUNC, SYM_L_GLOBAL)
+ SYM_ALIAS(alias, name, SYM_L_GLOBAL)
#endif

/*
@@ -269,7 +266,7 @@
*/
#ifndef SYM_FUNC_ALIAS_LOCAL
#define SYM_FUNC_ALIAS_LOCAL(alias, name) \
- SYM_ALIAS(alias, name, SYM_T_FUNC, SYM_L_LOCAL)
+ SYM_ALIAS(alias, name, SYM_L_LOCAL)
#endif

/*
@@ -277,7 +274,7 @@
*/
#ifndef SYM_FUNC_ALIAS_WEAK
#define SYM_FUNC_ALIAS_WEAK(alias, name) \
- SYM_ALIAS(alias, name, SYM_T_FUNC, SYM_L_WEAK)
+ SYM_ALIAS(alias, name, SYM_L_WEAK)
#endif

/* SYM_CODE_START -- use for non-C (special) functions */


2022-04-30 11:39:20

by Josh Poimboeuf

[permalink] [raw]
Subject: Re: [PATCH] linkage: Fix issue with missing symbol size

On Fri, Apr 29, 2022 at 11:18:59AM +0200, Peter Zijlstra wrote:
>
> Occasionally, typically when a function doesn't end with 'ret', an
> alias on that function will have 0 size.
>
> The difference between what GCC generates and our linkage magic, is
> that GCC doesn't appear to provide .size for the alias'ed symbol at
> all. And indeed, removing this directive cures the issue.
>
> Additionally, GCC also doesn't emit .type for alias symbols either, so
> also omit that.
>
> Fixes: e0891269a8c2 ("linkage: add SYM_FUNC_ALIAS{,_LOCAL,_WEAK}()")
> Suggested-by: Mark Rutland <[email protected]>
> Signed-off-by: Peter Zijlstra (Intel) <[email protected]>

Acked-by: Josh Poimboeuf <[email protected]>

--
Josh

2022-05-03 00:06:29

by Fangrui Song

[permalink] [raw]
Subject: Re: [PATCH] linkage: Fix issue with missing symbol size

On Fri, Apr 29, 2022 at 1:13 PM Josh Poimboeuf <[email protected]> wrote:
>
> On Fri, Apr 29, 2022 at 11:18:59AM +0200, Peter Zijlstra wrote:
> >
> > Occasionally, typically when a function doesn't end with 'ret', an
> > alias on that function will have 0 size.
> >
> > The difference between what GCC generates and our linkage magic, is
> > that GCC doesn't appear to provide .size for the alias'ed symbol at
> > all. And indeed, removing this directive cures the issue.
> >
> > Additionally, GCC also doesn't emit .type for alias symbols either, so
> > also omit that.
> >
> > Fixes: e0891269a8c2 ("linkage: add SYM_FUNC_ALIAS{,_LOCAL,_WEAK}()")
> > Suggested-by: Mark Rutland <[email protected]>
> > Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
>
> Acked-by: Josh Poimboeuf <[email protected]>
>
> --
> Josh
>

Yeah, an alias inherits the original symbol's st_size.
In case you are interested in the internals, see
https://sourceware.org/bugzilla/show_bug.cgi?id=29012 ("gas: .set
should copy st_size only if src's st_size is unset")

2022-05-03 22:40:48

by Mark Rutland

[permalink] [raw]
Subject: Re: [PATCH] linkage: Fix issue with missing symbol size

On Fri, Apr 29, 2022 at 11:18:59AM +0200, Peter Zijlstra wrote:
>
> Occasionally, typically when a function doesn't end with 'ret', an
> alias on that function will have 0 size.
>
> The difference between what GCC generates and our linkage magic, is
> that GCC doesn't appear to provide .size for the alias'ed symbol at
> all. And indeed, removing this directive cures the issue.
>
> Additionally, GCC also doesn't emit .type for alias symbols either, so
> also omit that.
>
> Fixes: e0891269a8c2 ("linkage: add SYM_FUNC_ALIAS{,_LOCAL,_WEAK}()")
> Suggested-by: Mark Rutland <[email protected]>
> Signed-off-by: Peter Zijlstra (Intel) <[email protected]>

Sorry about this!

FWIW:

Reviewed-by: Mark Rutland <[email protected]>

Thanks,
Mark.

> ---
> include/linux/linkage.h | 15 ++++++---------
> 1 file changed, 6 insertions(+), 9 deletions(-)
>
> --- a/include/linux/linkage.h
> +++ b/include/linux/linkage.h
> @@ -171,12 +171,9 @@
>
> /* SYM_ALIAS -- use only if you have to */
> #ifndef SYM_ALIAS
> -#define SYM_ALIAS(alias, name, sym_type, linkage) \
> - linkage(alias) ASM_NL \
> - .set alias, name ASM_NL \
> - .type alias sym_type ASM_NL \
> - .set .L__sym_size_##alias, .L__sym_size_##name ASM_NL \
> - .size alias, .L__sym_size_##alias
> +#define SYM_ALIAS(alias, name, linkage) \
> + linkage(alias) ASM_NL \
> + .set alias, name ASM_NL
> #endif
>
> /* === code annotations === */
> @@ -261,7 +258,7 @@
> */
> #ifndef SYM_FUNC_ALIAS
> #define SYM_FUNC_ALIAS(alias, name) \
> - SYM_ALIAS(alias, name, SYM_T_FUNC, SYM_L_GLOBAL)
> + SYM_ALIAS(alias, name, SYM_L_GLOBAL)
> #endif
>
> /*
> @@ -269,7 +266,7 @@
> */
> #ifndef SYM_FUNC_ALIAS_LOCAL
> #define SYM_FUNC_ALIAS_LOCAL(alias, name) \
> - SYM_ALIAS(alias, name, SYM_T_FUNC, SYM_L_LOCAL)
> + SYM_ALIAS(alias, name, SYM_L_LOCAL)
> #endif
>
> /*
> @@ -277,7 +274,7 @@
> */
> #ifndef SYM_FUNC_ALIAS_WEAK
> #define SYM_FUNC_ALIAS_WEAK(alias, name) \
> - SYM_ALIAS(alias, name, SYM_T_FUNC, SYM_L_WEAK)
> + SYM_ALIAS(alias, name, SYM_L_WEAK)
> #endif
>
> /* SYM_CODE_START -- use for non-C (special) functions */
>