diff mbox series

[v6,1/2] Add declare_object_symbol_alias for assembly codes [BZ #28128]

Message ID 20210830173844.458727-2-hjl.tools@gmail.com
State Superseded
Headers show
Series Extend struct r_debug to support multiple namespaces | expand

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

H.J. Lu Aug. 30, 2021, 5:38 p.m. UTC
There are 2 problems in:

 #define declare_symbol_alias(symbol, original, type, size) \
  declare_symbol_alias_1 (symbol, original, type, size)
 #ifdef __ASSEMBLER__
 # define declare_symbol_alias_1(symbol, original, type, size) \
   strong_alias (original, symbol); \
   .type C_SYMBOL_NAME (symbol), %##type; \
   .size C_SYMBOL_NAME (symbol), size

1. .type and .size are substituted by arguments.
2. %##type is expanded to "% type" due to the GCC bug:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101613

But assembler doesn't support "% type".

Workaround BZ #28128 by

1. Don't define declare_symbol_alias for assembly codes.
2. Define declare_object_symbol_alias for assembly codes.
---
 include/libc-symbols.h | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

Comments

Florian Weimer Aug. 31, 2021, 12:48 p.m. UTC | #1
* H. J. Lu:

> diff --git a/include/libc-symbols.h b/include/libc-symbols.h
> index d41ecf4384..1678071d77 100644
> --- a/include/libc-symbols.h
> +++ b/include/libc-symbols.h
> @@ -324,14 +324,16 @@ for linking")
>     This is only necessary when defining something in assembly, or playing
>     funny alias games where the size should be other than what the compiler
>     thinks it is.  */
> -#define declare_symbol_alias(symbol, original, type, size) \
> -  declare_symbol_alias_1 (symbol, original, type, size)
>  #ifdef __ASSEMBLER__
> -# define declare_symbol_alias_1(symbol, original, type, size) \
> +# define declare_object_symbol_alias(symbol, original, size) \
> +  declare_object_symbol_alias_1 (symbol, original, size)
> +# define declare_object_symbol_alias_1(symbol, original, s_size) \
>     strong_alias (original, symbol); \
> -   .type C_SYMBOL_NAME (symbol), %##type; \
> -   .size C_SYMBOL_NAME (symbol), size
> +   .type C_SYMBOL_NAME (symbol), %object; \
> +   .size C_SYMBOL_NAME (symbol), s_size
>  #else /* Not __ASSEMBLER__.  */
> +# define declare_symbol_alias(symbol, original, type, size) \
> +  declare_symbol_alias_1 (symbol, original, type, size)
>  # define declare_symbol_alias_1(symbol, original, type, size) \
>     asm (".globl " __SYMBOL_PREFIX #symbol \
>  	"\n\t" declare_symbol_alias_1_alias (symbol, original) \

(trimming Cc: list)

This change needs to use ASM_LINE_SEP, otherwise part of the directives
turn into comments on arc and hppa, leading to ABI breakage.

Something like this:

diff --git a/include/libc-symbols.h b/include/libc-symbols.h
index 1678071d77..2b47144d6f 100644
--- a/include/libc-symbols.h
+++ b/include/libc-symbols.h
@@ -328,8 +328,8 @@ for linking")
 # define declare_object_symbol_alias(symbol, original, size) \
   declare_object_symbol_alias_1 (symbol, original, size)
 # define declare_object_symbol_alias_1(symbol, original, s_size) \
-   strong_alias (original, symbol); \
-   .type C_SYMBOL_NAME (symbol), %object; \
+   strong_alias (original, symbol) ASM_LINE_SEP \
+   .type C_SYMBOL_NAME (symbol), %object ASM_LINE_SEP \
    .size C_SYMBOL_NAME (symbol), s_size
 #else /* Not __ASSEMBLER__.  */
 # define declare_symbol_alias(symbol, original, type, size) \

With this change, the expected ABI is produced.

Thanks,
Florian
H.J. Lu Aug. 31, 2021, 1:26 p.m. UTC | #2
On Tue, Aug 31, 2021 at 5:48 AM Florian Weimer <fweimer@redhat.com> wrote:
>
> * H. J. Lu:
>
> > diff --git a/include/libc-symbols.h b/include/libc-symbols.h
> > index d41ecf4384..1678071d77 100644
> > --- a/include/libc-symbols.h
> > +++ b/include/libc-symbols.h
> > @@ -324,14 +324,16 @@ for linking")
> >     This is only necessary when defining something in assembly, or playing
> >     funny alias games where the size should be other than what the compiler
> >     thinks it is.  */
> > -#define declare_symbol_alias(symbol, original, type, size) \
> > -  declare_symbol_alias_1 (symbol, original, type, size)
> >  #ifdef __ASSEMBLER__
> > -# define declare_symbol_alias_1(symbol, original, type, size) \
> > +# define declare_object_symbol_alias(symbol, original, size) \
> > +  declare_object_symbol_alias_1 (symbol, original, size)
> > +# define declare_object_symbol_alias_1(symbol, original, s_size) \
> >     strong_alias (original, symbol); \
> > -   .type C_SYMBOL_NAME (symbol), %##type; \
> > -   .size C_SYMBOL_NAME (symbol), size
> > +   .type C_SYMBOL_NAME (symbol), %object; \
> > +   .size C_SYMBOL_NAME (symbol), s_size
> >  #else /* Not __ASSEMBLER__.  */
> > +# define declare_symbol_alias(symbol, original, type, size) \
> > +  declare_symbol_alias_1 (symbol, original, type, size)
> >  # define declare_symbol_alias_1(symbol, original, type, size) \
> >     asm (".globl " __SYMBOL_PREFIX #symbol \
> >       "\n\t" declare_symbol_alias_1_alias (symbol, original) \
>
> (trimming Cc: list)
>
> This change needs to use ASM_LINE_SEP, otherwise part of the directives
> turn into comments on arc and hppa, leading to ABI breakage.
>
> Something like this:
>
> diff --git a/include/libc-symbols.h b/include/libc-symbols.h
> index 1678071d77..2b47144d6f 100644
> --- a/include/libc-symbols.h
> +++ b/include/libc-symbols.h
> @@ -328,8 +328,8 @@ for linking")
>  # define declare_object_symbol_alias(symbol, original, size) \
>    declare_object_symbol_alias_1 (symbol, original, size)
>  # define declare_object_symbol_alias_1(symbol, original, s_size) \
> -   strong_alias (original, symbol); \
> -   .type C_SYMBOL_NAME (symbol), %object; \
> +   strong_alias (original, symbol) ASM_LINE_SEP \
> +   .type C_SYMBOL_NAME (symbol), %object ASM_LINE_SEP \
>     .size C_SYMBOL_NAME (symbol), s_size
>  #else /* Not __ASSEMBLER__.  */
>  # define declare_symbol_alias(symbol, original, type, size) \
>
> With this change, the expected ABI is produced.

Fixed in the next version.

Thanks.

> Thanks,
> Florian
>
diff mbox series

Patch

diff --git a/include/libc-symbols.h b/include/libc-symbols.h
index d41ecf4384..1678071d77 100644
--- a/include/libc-symbols.h
+++ b/include/libc-symbols.h
@@ -324,14 +324,16 @@  for linking")
    This is only necessary when defining something in assembly, or playing
    funny alias games where the size should be other than what the compiler
    thinks it is.  */
-#define declare_symbol_alias(symbol, original, type, size) \
-  declare_symbol_alias_1 (symbol, original, type, size)
 #ifdef __ASSEMBLER__
-# define declare_symbol_alias_1(symbol, original, type, size) \
+# define declare_object_symbol_alias(symbol, original, size) \
+  declare_object_symbol_alias_1 (symbol, original, size)
+# define declare_object_symbol_alias_1(symbol, original, s_size) \
    strong_alias (original, symbol); \
-   .type C_SYMBOL_NAME (symbol), %##type; \
-   .size C_SYMBOL_NAME (symbol), size
+   .type C_SYMBOL_NAME (symbol), %object; \
+   .size C_SYMBOL_NAME (symbol), s_size
 #else /* Not __ASSEMBLER__.  */
+# define declare_symbol_alias(symbol, original, type, size) \
+  declare_symbol_alias_1 (symbol, original, type, size)
 # define declare_symbol_alias_1(symbol, original, type, size) \
    asm (".globl " __SYMBOL_PREFIX #symbol \
 	"\n\t" declare_symbol_alias_1_alias (symbol, original) \