public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/google/grte/v5-2.27/master] Add workaround for segfaults in __longjmp when compiled with ppc clang
@ 2021-08-28  0:39 Fangrui Song
  0 siblings, 0 replies; only message in thread
From: Fangrui Song @ 2021-08-28  0:39 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=9b6c937b0041de8b65a6f11db9c5a05efd3fd7c6

commit 9b6c937b0041de8b65a6f11db9c5a05efd3fd7c6
Author: Stan Shebs <stanshebs@google.com>
Date:   Tue Sep 25 07:20:18 2018 -0700

    Add workaround for segfaults in __longjmp when compiled with ppc clang

Diff:
---
 elf/dl-error-skeleton.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/elf/dl-error-skeleton.c b/elf/dl-error-skeleton.c
index d5f418ab18..01870c578d 100644
--- a/elf/dl-error-skeleton.c
+++ b/elf/dl-error-skeleton.c
@@ -85,6 +85,21 @@ fatal_error (int errcode, const char *objname, const char *occasion,
 		     : ""));
 }
 
+/* Due to a complicated set of interactions with different symbol
+   versions, presumably including a VMX-specific __vmx__longjmp, PPC
+   clang ends calling __longjump with ld.so through the global entry
+   point (+0x0) instead of via the local entry point (+0x8) which
+   results in ld.so exceptions crashing because the TOC is not set up.
+   The hack here simply calls the function through a pointer, which
+   guarantees that the global entry point has the TOC set up.  (This
+   may or may not be a clang bug, the symbol aliasing is tricky and
+   literally affects only __longjmp out of all the symbols in
+   libc.)  */
+#if defined __clang__ && defined __powerpc64__
+volatile void (*longjmpptr) (struct __jmp_buf_tag __env[1], int __val)
+__attribute__ ((__nothrow__)) __attribute__ ((__noreturn__)) = __longjmp;
+#endif
+
 void
 _dl_signal_exception (int errcode, struct dl_exception *exception,
 		      const char *occasion)
@@ -96,7 +111,11 @@ _dl_signal_exception (int errcode, struct dl_exception *exception,
       *lcatch->errcode = errcode;
 
       /* We do not restore the signal mask because none was saved.  */
+#if defined __clang__ && defined __powerpc64__
+      (*longjmpptr) (lcatch->env[0].__jmpbuf, 1);
+#else
       __longjmp (lcatch->env[0].__jmpbuf, 1);
+#endif
     }
   else
     fatal_error (errcode, exception->objname, occasion, exception->errstring);
@@ -118,7 +137,11 @@ _dl_signal_error (int errcode, const char *objname, const char *occation,
       *lcatch->errcode = errcode;
 
       /* We do not restore the signal mask because none was saved.  */
+#if defined __clang__ && defined __powerpc64__
+      (*longjmpptr) (lcatch->env[0].__jmpbuf, 1);
+#else
       __longjmp (lcatch->env[0].__jmpbuf, 1);
+#endif
     }
   else
     fatal_error (errcode, objname, occation, errstring);


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-08-28  0:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-28  0:39 [glibc/google/grte/v5-2.27/master] Add workaround for segfaults in __longjmp when compiled with ppc clang Fangrui Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).