diff mbox series

[v3,06/16] asprintf_chk: Ensure compatibility for both s390x and ppc64le

Message ID 20230628084246.778302-7-fberat@redhat.com
State New
Headers show
Series Allow glibc to be built with _FORTIFY_SOURCE | expand

Commit Message

Frederic Berat June 28, 2023, 8:42 a.m. UTC
If ldbl_* macros are used for asprintf, ABI gets broken on s390x,
if it isn't, ppc64le isn't building due to multiple asm redirections.

This is due to the inclusion of bits/stdio-lbdl.h for ppc64le whereas it
isn't for s390x. This header creates redirections, which are not
compatible with the ones generated using libc_hidden_builtin_def.
Yet, we can't use libc_hidden_ldbl_proto on s390x since it will not
create a simple strong alias (e.g. as done on x86_64), but a versioned
alias, leading to ABI breakage.
---
 debug/asprintf_chk.c | 12 ++++++++++++
 include/stdio.h      |  5 +++++
 2 files changed, 17 insertions(+)

Comments

Siddhesh Poyarekar June 30, 2023, 3:11 p.m. UTC | #1
On 2023-06-28 04:42, Frédéric Bérat wrote:
> If ldbl_* macros are used for asprintf, ABI gets broken on s390x,
> if it isn't, ppc64le isn't building due to multiple asm redirections.
> 
> This is due to the inclusion of bits/stdio-lbdl.h for ppc64le whereas it
> isn't for s390x. This header creates redirections, which are not
> compatible with the ones generated using libc_hidden_builtin_def.
> Yet, we can't use libc_hidden_ldbl_proto on s390x since it will not
> create a simple strong alias (e.g. as done on x86_64), but a versioned
> alias, leading to ABI breakage.
> ---

Looks OK to me, but deferring to the IBM maintainers.  Raji, Stefan, 
does this look right to you?

Thanks,
Sid


>   debug/asprintf_chk.c | 12 ++++++++++++
>   include/stdio.h      |  5 +++++
>   2 files changed, 17 insertions(+)
> 
> diff --git a/debug/asprintf_chk.c b/debug/asprintf_chk.c
> index 06d112de00..7da1cddacb 100644
> --- a/debug/asprintf_chk.c
> +++ b/debug/asprintf_chk.c
> @@ -36,5 +36,17 @@ ___asprintf_chk (char **result_ptr, int flag, const char *format, ...)
>   
>     return ret;
>   }
> +#if defined __LDBL_COMPAT || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
> +/* This is needed since <bits/stdio-lbdl.h> is included in this case, leading to
> + * multiple asm redirection of the same symbol
> + */
>   ldbl_hidden_def (___asprintf_chk, __asprintf_chk)
>   ldbl_strong_alias (___asprintf_chk, __asprintf_chk)
> +#else
> +/* Yet, we can't use ldbl_* macros on some systems, even if they don't fall in
> + * the first case as this leads to ABI breakage due to the long_double_symbol
> + * aliasing, which is versionned.
> + */
> +strong_alias (___asprintf_chk, __asprintf_chk)
> +libc_hidden_builtin_def (__asprintf_chk)
> +#endif
> diff --git a/include/stdio.h b/include/stdio.h
> index 3afb0ff77b..6755877911 100644
> --- a/include/stdio.h
> +++ b/include/stdio.h
> @@ -279,7 +279,12 @@ rtld_hidden_proto (__libc_fatal)
>   
>   libc_hidden_proto (__fgets_unlocked_chk)
>   
> +#if defined __LDBL_COMPAT || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
>   libc_hidden_ldbl_proto (__asprintf_chk)
> +#else
> +libc_hidden_proto (__asprintf_chk)
> +#endif
> +
>   libc_hidden_ldbl_proto (__fprintf_chk)
>   libc_hidden_ldbl_proto (__sprintf_chk)
>   libc_hidden_ldbl_proto (__vsprintf_chk)
Rajalakshmi Srinivasaraghavan June 30, 2023, 4:08 p.m. UTC | #2
On 6/30/23 10:11 AM, Siddhesh Poyarekar wrote:
> Subject:
> Re: [PATCH v3 06/16] asprintf_chk: Ensure compatibility for both s390x 
> and ppc64le
> From:
> Siddhesh Poyarekar <siddhesh@gotplt.org>
> Date:
> 6/30/23, 10:11 AM
>
> To:
> Frédéric Bérat <fberat@redhat.com>, libc-alpha@sourceware.org
> CC:
> Stefan Liebler <stli@linux.ibm.com>, Rajalakshmi Srinivasaraghavan 
> <rajis@linux.vnet.ibm.com>
>
>
>
>
> On 2023-06-28 04:42, Frédéric Bérat wrote:
>> If ldbl_* macros are used for asprintf, ABI gets broken on s390x,
>> if it isn't, ppc64le isn't building due to multiple asm redirections.
>>
>> This is due to the inclusion of bits/stdio-lbdl.h for ppc64le whereas it
>> isn't for s390x. This header creates redirections, which are not
>> compatible with the ones generated using libc_hidden_builtin_def.
>> Yet, we can't use libc_hidden_ldbl_proto on s390x since it will not
>> create a simple strong alias (e.g. as done on x86_64), but a versioned
>> alias, leading to ABI breakage.
>> ---
>
> Looks OK to me, but deferring to the IBM maintainers.  Raji, Stefan, 
> does this look right to you?


Paul Murphy is our expert on this topic.  Paul,  Can you comment on this 
too?  Thanks.

>
> Thanks,
> Sid
>
>
>> debug/asprintf_chk.c | 12 ++++++++++++
>>   include/stdio.h      |  5 +++++
>>   2 files changed, 17 insertions(+)
>>
>> diff --git a/debug/asprintf_chk.c b/debug/asprintf_chk.c
>> index 06d112de00..7da1cddacb 100644
>> --- a/debug/asprintf_chk.c
>> +++ b/debug/asprintf_chk.c
>> @@ -36,5 +36,17 @@ ___asprintf_chk (char **result_ptr, int flag, 
>> const char *format, ...)
>>       return ret;
>>   }
>> +#if defined __LDBL_COMPAT || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
>> +/* This is needed since <bits/stdio-lbdl.h> is included in this 
>> case, leading to
>> + * multiple asm redirection of the same symbol
>> + */
>>   ldbl_hidden_def (___asprintf_chk, __asprintf_chk)
>>   ldbl_strong_alias (___asprintf_chk, __asprintf_chk)
>> +#else
>> +/* Yet, we can't use ldbl_* macros on some systems, even if they 
>> don't fall in
>> + * the first case as this leads to ABI breakage due to the 
>> long_double_symbol
>> + * aliasing, which is versionned.
>> + */
>> +strong_alias (___asprintf_chk, __asprintf_chk)
>> +libc_hidden_builtin_def (__asprintf_chk)
>> +#endif
>> diff --git a/include/stdio.h b/include/stdio.h
>> index 3afb0ff77b..6755877911 100644
>> --- a/include/stdio.h
>> +++ b/include/stdio.h
>> @@ -279,7 +279,12 @@ rtld_hidden_proto (__libc_fatal)
>>     libc_hidden_proto (__fgets_unlocked_chk)
>>   +#if defined __LDBL_COMPAT || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
>>   libc_hidden_ldbl_proto (__asprintf_chk)
>> +#else
>> +libc_hidden_proto (__asprintf_chk)
>> +#endif
>> +
>>   libc_hidden_ldbl_proto (__fprintf_chk)
>>   libc_hidden_ldbl_proto (__sprintf_chk)
>>   libc_hidden_ldbl_proto (__vsprintf_chk)
Paul E. Murphy June 30, 2023, 5:51 p.m. UTC | #3
On 6/28/23 3:42 AM, Frédéric Bérat via Libc-alpha wrote:
> If ldbl_* macros are used for asprintf, ABI gets broken on s390x,
> if it isn't, ppc64le isn't building due to multiple asm redirections.
> 
> This is due to the inclusion of bits/stdio-lbdl.h for ppc64le whereas it
> isn't for s390x. This header creates redirections, which are not
> compatible with the ones generated using libc_hidden_builtin_def.
> Yet, we can't use libc_hidden_ldbl_proto on s390x since it will not
> create a simple strong alias (e.g. as done on x86_64), but a versioned
> alias, leading to ABI breakage.
> ---
>   debug/asprintf_chk.c | 12 ++++++++++++
>   include/stdio.h      |  5 +++++
>   2 files changed, 17 insertions(+)
> 
> diff --git a/debug/asprintf_chk.c b/debug/asprintf_chk.c
> index 06d112de00..7da1cddacb 100644
> --- a/debug/asprintf_chk.c
> +++ b/debug/asprintf_chk.c
> @@ -36,5 +36,17 @@ ___asprintf_chk (char **result_ptr, int flag, const char *format, ...)
> 
>     return ret;
>   }
> +#if defined __LDBL_COMPAT || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1 > +/* This is needed since <bits/stdio-lbdl.h> is included in this 
case, leading to
> + * multiple asm redirection of the same symbol
> + */
>   ldbl_hidden_def (___asprintf_chk, __asprintf_chk)
>   ldbl_strong_alias (___asprintf_chk, __asprintf_chk)
> +#else
> +/* Yet, we can't use ldbl_* macros on some systems, even if they don't fall in
> + * the first case as this leads to ABI breakage due to the long_double_symbol
> + * aliasing, which is versionned.

s/versionned/versioned/

It has been a few years since I really looked at this macros, why only 
asprintf and not the other printf functions?  I find the ABI comment 
hard to follow, could it include more details about how it would be 
broken by using the ldbl_* macros?

Also, does patchset 5 in this series break ppc64le or s390x build 
without this patch?  This seems like it should be squashed with the 
previous patch.

> + */
> +strong_alias (___asprintf_chk, __asprintf_chk)
> +libc_hidden_builtin_def (__asprintf_chk)
> +#endif
> diff --git a/include/stdio.h b/include/stdio.h
> index 3afb0ff77b..6755877911 100644
> --- a/include/stdio.h
> +++ b/include/stdio.h
> @@ -279,7 +279,12 @@ rtld_hidden_proto (__libc_fatal)
> 
>   libc_hidden_proto (__fgets_unlocked_chk)
> 
> +#if defined __LDBL_COMPAT || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
>   libc_hidden_ldbl_proto (__asprintf_chk)
> +#else
> +libc_hidden_proto (__asprintf_chk)
> +#endif
> +
>   libc_hidden_ldbl_proto (__fprintf_chk)
>   libc_hidden_ldbl_proto (__sprintf_chk)
>   libc_hidden_ldbl_proto (__vsprintf_chk)
Frederic Berat July 3, 2023, 5:35 a.m. UTC | #4
On Fri, Jun 30, 2023 at 7:51 PM Paul E Murphy <murphyp@linux.ibm.com> wrote:

>
>
> On 6/28/23 3:42 AM, Frédéric Bérat via Libc-alpha wrote:
> > If ldbl_* macros are used for asprintf, ABI gets broken on s390x,
> > if it isn't, ppc64le isn't building due to multiple asm redirections.
> >
> > This is due to the inclusion of bits/stdio-lbdl.h for ppc64le whereas it
> > isn't for s390x. This header creates redirections, which are not
> > compatible with the ones generated using libc_hidden_builtin_def.
> > Yet, we can't use libc_hidden_ldbl_proto on s390x since it will not
> > create a simple strong alias (e.g. as done on x86_64), but a versioned
> > alias, leading to ABI breakage.
> > ---
> >   debug/asprintf_chk.c | 12 ++++++++++++
> >   include/stdio.h      |  5 +++++
> >   2 files changed, 17 insertions(+)
> >
> > diff --git a/debug/asprintf_chk.c b/debug/asprintf_chk.c
> > index 06d112de00..7da1cddacb 100644
> > --- a/debug/asprintf_chk.c
> > +++ b/debug/asprintf_chk.c
> > @@ -36,5 +36,17 @@ ___asprintf_chk (char **result_ptr, int flag, const
> char *format, ...)
> >
> >     return ret;
> >   }
> > +#if defined __LDBL_COMPAT || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1 >
> +/* This is needed since <bits/stdio-lbdl.h> is included in this
> case, leading to
> > + * multiple asm redirection of the same symbol
> > + */
> >   ldbl_hidden_def (___asprintf_chk, __asprintf_chk)
> >   ldbl_strong_alias (___asprintf_chk, __asprintf_chk)
> > +#else
> > +/* Yet, we can't use ldbl_* macros on some systems, even if they don't
> fall in
> > + * the first case as this leads to ABI breakage due to the
> long_double_symbol
> > + * aliasing, which is versionned.
>
> s/versionned/versioned/
>
> It has been a few years since I really looked at this macros, why only
> asprintf and not the other printf functions?  I find the ABI comment
> hard to follow, could it include more details about how it would be
> broken by using the ldbl_* macros?
>

I didn't do this for other functions as it didn't appear to be necessary.
Yes, I can be more specific about the breakage. Basically, the
__asprintf_chk routine disappears from the ABI list on s390x, which breaks
linkage. That is due to the fact that ldbl_strong_alias may create
*versioned* alias (depending on build options), while strong_alias never
does. I'll expand on the comment, I can reproduce the error to be explicit
about it.


>
> Also, does patchset 5 in this series break ppc64le or s390x build
> without this patch?  This seems like it should be squashed with the
> previous patch.
>

On s390x yes, not ppc. I was afraid to kind of hide this change in the
middle of the other changes, that's why I kept them separated, so that this
gets carefully reviewed.
I can squash this into patch 5 if you are fine with it.


> > + */
> > +strong_alias (___asprintf_chk, __asprintf_chk)
> > +libc_hidden_builtin_def (__asprintf_chk)
> > +#endif
> > diff --git a/include/stdio.h b/include/stdio.h
> > index 3afb0ff77b..6755877911 100644
> > --- a/include/stdio.h
> > +++ b/include/stdio.h
> > @@ -279,7 +279,12 @@ rtld_hidden_proto (__libc_fatal)
> >
> >   libc_hidden_proto (__fgets_unlocked_chk)
> >
> > +#if defined __LDBL_COMPAT || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
> >   libc_hidden_ldbl_proto (__asprintf_chk)
> > +#else
> > +libc_hidden_proto (__asprintf_chk)
> > +#endif
> > +
> >   libc_hidden_ldbl_proto (__fprintf_chk)
> >   libc_hidden_ldbl_proto (__sprintf_chk)
> >   libc_hidden_ldbl_proto (__vsprintf_chk)
>
>
diff mbox series

Patch

diff --git a/debug/asprintf_chk.c b/debug/asprintf_chk.c
index 06d112de00..7da1cddacb 100644
--- a/debug/asprintf_chk.c
+++ b/debug/asprintf_chk.c
@@ -36,5 +36,17 @@  ___asprintf_chk (char **result_ptr, int flag, const char *format, ...)
 
   return ret;
 }
+#if defined __LDBL_COMPAT || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
+/* This is needed since <bits/stdio-lbdl.h> is included in this case, leading to
+ * multiple asm redirection of the same symbol
+ */
 ldbl_hidden_def (___asprintf_chk, __asprintf_chk)
 ldbl_strong_alias (___asprintf_chk, __asprintf_chk)
+#else
+/* Yet, we can't use ldbl_* macros on some systems, even if they don't fall in
+ * the first case as this leads to ABI breakage due to the long_double_symbol
+ * aliasing, which is versionned.
+ */
+strong_alias (___asprintf_chk, __asprintf_chk)
+libc_hidden_builtin_def (__asprintf_chk)
+#endif
diff --git a/include/stdio.h b/include/stdio.h
index 3afb0ff77b..6755877911 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -279,7 +279,12 @@  rtld_hidden_proto (__libc_fatal)
 
 libc_hidden_proto (__fgets_unlocked_chk)
 
+#if defined __LDBL_COMPAT || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
 libc_hidden_ldbl_proto (__asprintf_chk)
+#else
+libc_hidden_proto (__asprintf_chk)
+#endif
+
 libc_hidden_ldbl_proto (__fprintf_chk)
 libc_hidden_ldbl_proto (__sprintf_chk)
 libc_hidden_ldbl_proto (__vsprintf_chk)