08c3a6
commit e7ca2a475cf2e7ffc987b8d08e1a40337840b500
08c3a6
Author: Florian Weimer <fweimer@redhat.com>
08c3a6
Date:   Mon May 9 18:15:16 2022 +0200
08c3a6
08c3a6
    Linux: Implement a useful version of _startup_fatal
08c3a6
    
08c3a6
    On i386 and ia64, the TCB is not available at this point.
08c3a6
    
08c3a6
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
08c3a6
    (cherry picked from commit a2a6bce7d7e52c1c34369a7da62c501cc350bc31)
08c3a6
08c3a6
diff --git a/sysdeps/unix/sysv/linux/i386/startup.h b/sysdeps/unix/sysv/linux/i386/startup.h
08c3a6
index 192c765361c17ed1..213805d7d2d459be 100644
08c3a6
--- a/sysdeps/unix/sysv/linux/i386/startup.h
08c3a6
+++ b/sysdeps/unix/sysv/linux/i386/startup.h
08c3a6
@@ -1,5 +1,5 @@
08c3a6
 /* Linux/i386 definitions of functions used by static libc main startup.
08c3a6
-   Copyright (C) 2017-2021 Free Software Foundation, Inc.
08c3a6
+   Copyright (C) 2022 Free Software Foundation, Inc.
08c3a6
    This file is part of the GNU C Library.
08c3a6
 
08c3a6
    The GNU C Library is free software; you can redistribute it and/or
08c3a6
@@ -16,22 +16,7 @@
08c3a6
    License along with the GNU C Library; if not, see
08c3a6
    <https://www.gnu.org/licenses/>.  */
08c3a6
 
08c3a6
-#if BUILD_PIE_DEFAULT
08c3a6
-/* Can't use "call *%gs:SYSINFO_OFFSET" during statup in static PIE.  */
08c3a6
-# define I386_USE_SYSENTER 0
08c3a6
+/* Can't use "call *%gs:SYSINFO_OFFSET" during startup.  */
08c3a6
+#define I386_USE_SYSENTER 0
08c3a6
 
08c3a6
-# include <sysdep.h>
08c3a6
-# include <abort-instr.h>
08c3a6
-
08c3a6
-__attribute__ ((__noreturn__))
08c3a6
-static inline void
08c3a6
-_startup_fatal (const char *message __attribute__ ((unused)))
08c3a6
-{
08c3a6
-  /* This is only called very early during startup in static PIE.
08c3a6
-     FIXME: How can it be improved?  */
08c3a6
-  ABORT_INSTRUCTION;
08c3a6
-  __builtin_unreachable ();
08c3a6
-}
08c3a6
-#else
08c3a6
-# include_next <startup.h>
08c3a6
-#endif
08c3a6
+#include_next <startup.h>
08c3a6
diff --git a/sysdeps/unix/sysv/linux/ia64/startup.h b/sysdeps/unix/sysv/linux/ia64/startup.h
08c3a6
new file mode 100644
08c3a6
index 0000000000000000..77f29f15a2103ed5
08c3a6
--- /dev/null
08c3a6
+++ b/sysdeps/unix/sysv/linux/ia64/startup.h
08c3a6
@@ -0,0 +1,22 @@
08c3a6
+/* Linux/ia64 definitions of functions used by static libc main startup.
08c3a6
+   Copyright (C) 2022 Free Software Foundation, Inc.
08c3a6
+   This file is part of the GNU C Library.
08c3a6
+
08c3a6
+   The GNU C Library is free software; you can redistribute it and/or
08c3a6
+   modify it under the terms of the GNU Lesser General Public
08c3a6
+   License as published by the Free Software Foundation; either
08c3a6
+   version 2.1 of the License, or (at your option) any later version.
08c3a6
+
08c3a6
+   The GNU C Library is distributed in the hope that it will be useful,
08c3a6
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
08c3a6
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
08c3a6
+   Lesser General Public License for more details.
08c3a6
+
08c3a6
+   You should have received a copy of the GNU Lesser General Public
08c3a6
+   License along with the GNU C Library; if not, see
08c3a6
+   <https://www.gnu.org/licenses/>.  */
08c3a6
+
08c3a6
+/* This code is used before the TCB is set up.  */
08c3a6
+#define IA64_USE_NEW_STUB 0
08c3a6
+
08c3a6
+#include_next <startup.h>
08c3a6
diff --git a/sysdeps/unix/sysv/linux/startup.h b/sysdeps/unix/sysv/linux/startup.h
08c3a6
new file mode 100644
08c3a6
index 0000000000000000..39859b404a84798b
08c3a6
--- /dev/null
08c3a6
+++ b/sysdeps/unix/sysv/linux/startup.h
08c3a6
@@ -0,0 +1,39 @@
08c3a6
+/* Linux definitions of functions used by static libc main startup.
08c3a6
+   Copyright (C) 2017-2022 Free Software Foundation, Inc.
08c3a6
+   This file is part of the GNU C Library.
08c3a6
+
08c3a6
+   The GNU C Library is free software; you can redistribute it and/or
08c3a6
+   modify it under the terms of the GNU Lesser General Public
08c3a6
+   License as published by the Free Software Foundation; either
08c3a6
+   version 2.1 of the License, or (at your option) any later version.
08c3a6
+
08c3a6
+   The GNU C Library is distributed in the hope that it will be useful,
08c3a6
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
08c3a6
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
08c3a6
+   Lesser General Public License for more details.
08c3a6
+
08c3a6
+   You should have received a copy of the GNU Lesser General Public
08c3a6
+   License along with the GNU C Library; if not, see
08c3a6
+   <https://www.gnu.org/licenses/>.  */
08c3a6
+
08c3a6
+#ifdef SHARED
08c3a6
+# include_next <startup.h>
08c3a6
+#else
08c3a6
+# include <sysdep.h>
08c3a6
+
08c3a6
+/* Avoid a run-time invocation of strlen.  */
08c3a6
+#define _startup_fatal(message)                                         \
08c3a6
+  do                                                                    \
08c3a6
+    {                                                                   \
08c3a6
+      size_t __message_length = __builtin_strlen (message);             \
08c3a6
+      if (! __builtin_constant_p (__message_length))                    \
08c3a6
+        {                                                               \
08c3a6
+          extern void _startup_fatal_not_constant (void);               \
08c3a6
+          _startup_fatal_not_constant ();                               \
08c3a6
+        }                                                               \
08c3a6
+      INTERNAL_SYSCALL_CALL (write, STDERR_FILENO, (message),           \
08c3a6
+                             __message_length);                         \
08c3a6
+      INTERNAL_SYSCALL_CALL (exit_group, 127);                          \
08c3a6
+    }                                                                   \
08c3a6
+  while (0)
08c3a6
+#endif  /* !SHARED */