[09/21] asprintf_chk: Ensure compatibility for both s390x and ppc64le

Message ID 20230620181910.1506893-10-fberat@redhat.com
State Superseded
Headers
Series Allow glibc to be built with _FORTIFY_SOURCE |

Checks

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

Commit Message

Frederic Berat June 20, 2023, 6:18 p.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(+)
  

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)