51f0aa
This test requires a fix for max_align_t which is rolled into the
51f0aa
glibc-rh1418978-max_align_t.patch file.
51f0aa
51f0aa
commit b725132d2b0aeddf970b1ce3e5a24f8637a7b4c2
51f0aa
Author: Florian Weimer <fweimer@redhat.com>
51f0aa
Date:   Tue Jan 16 07:19:28 2018 +0100
51f0aa
51f0aa
    nptl/tst-minstack-throw: Compile in C++11 mode with GNU extensions
51f0aa
51f0aa
commit 860b0240a5645edd6490161de3f8d1d1f2786025
51f0aa
Author: Florian Weimer <fweimer@redhat.com>
51f0aa
Date:   Mon Jan 15 15:30:00 2018 +0100
51f0aa
51f0aa
    nptl: Add PTHREAD_MIN_STACK C++ throw test [BZ #22636]
51f0aa
51f0aa
Index: glibc-2.17-c758a686/nptl/Makefile
51f0aa
===================================================================
51f0aa
--- glibc-2.17-c758a686.orig/nptl/Makefile
51f0aa
+++ glibc-2.17-c758a686/nptl/Makefile
51f0aa
@@ -198,6 +198,7 @@ CFLAGS-send.c = -fexceptions -fasynchron
51f0aa
 
51f0aa
 CFLAGS-pt-system.c = -fexceptions
51f0aa
 
51f0aa
+CFLAGS-tst-minstack-throw.cc = -std=gnu++11
51f0aa
 
51f0aa
 tests = tst-typesizes \
51f0aa
 	tst-attr1 tst-attr2 tst-attr3 tst-default-attr \
51f0aa
@@ -268,7 +269,7 @@ tests = tst-typesizes \
51f0aa
 	tst-getpid1 tst-getpid2 tst-getpid3 \
51f0aa
 	tst-initializers1 $(patsubst %,tst-initializers1-%,c89 gnu89 c99 gnu99) \
51f0aa
 	tst-mutex-errorcheck \
51f0aa
-	tst-minstack-cancel tst-minstack-exit
51f0aa
+	tst-minstack-cancel tst-minstack-exit tst-minstack-throw
51f0aa
 xtests = tst-setuid1 tst-setuid1-static tst-mutexpp1 tst-mutexpp6 tst-mutexpp10
51f0aa
 test-srcs = tst-oddstacklimit
51f0aa
 
51f0aa
@@ -527,6 +528,7 @@ $(objpfx)tst-_res1: $(objpfx)tst-_res1mo
51f0aa
 
51f0aa
 LDLIBS-tst-cancel24 = $(no-as-needed) -lstdc++
51f0aa
 LDLIBS-tst-cancel24-static = $(LDLIBS-tst-cancel24)
51f0aa
+LDLIBS-tst-minstack-throw = -lstdc++
51f0aa
 
51f0aa
 extra-B-pthread.so = -B$(common-objpfx)nptl/
51f0aa
 $(objpfx)libpthread.so: $(addprefix $(objpfx),$(crti-objs) $(crtn-objs))
51f0aa
Index: glibc-2.17-c758a686/nptl/tst-minstack-throw.cc
51f0aa
===================================================================
51f0aa
--- /dev/null
51f0aa
+++ glibc-2.17-c758a686/nptl/tst-minstack-throw.cc
51f0aa
@@ -0,0 +1,87 @@
51f0aa
+/* Test that throwing C++ exceptions works with the minimum stack size.
51f0aa
+   Copyright (C) 2018 Free Software Foundation, Inc.
51f0aa
+   This file is part of the GNU C Library.
51f0aa
+
51f0aa
+   The GNU C Library is free software; you can redistribute it and/or
51f0aa
+   modify it under the terms of the GNU Lesser General Public
51f0aa
+   License as published by the Free Software Foundation; either
51f0aa
+   version 2.1 of the License, or (at your option) any later version.
51f0aa
+
51f0aa
+   The GNU C Library is distributed in the hope that it will be useful,
51f0aa
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
51f0aa
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
51f0aa
+   Lesser General Public License for more details.
51f0aa
+
51f0aa
+   You should have received a copy of the GNU Lesser General Public
51f0aa
+   License along with the GNU C Library; if not, see
51f0aa
+   <http://www.gnu.org/licenses/>.  */
51f0aa
+
51f0aa
+#include <stdexcept>
51f0aa
+
51f0aa
+#include <limits.h>
51f0aa
+#include <string.h>
51f0aa
+#include <support/check.h>
51f0aa
+#include <support/xthread.h>
51f0aa
+
51f0aa
+/* Throw a std::runtime_exception.  */
51f0aa
+__attribute__ ((noinline, noclone, weak))
51f0aa
+void
51f0aa
+do_throw_exception ()
51f0aa
+{
51f0aa
+  throw std::runtime_error ("test exception");
51f0aa
+}
51f0aa
+
51f0aa
+/* Class with a destructor, to trigger unwind handling.  */
51f0aa
+struct class_with_destructor
51f0aa
+{
51f0aa
+  class_with_destructor ();
51f0aa
+  ~class_with_destructor ();
51f0aa
+};
51f0aa
+
51f0aa
+__attribute__ ((noinline, noclone, weak))
51f0aa
+class_with_destructor::class_with_destructor ()
51f0aa
+{
51f0aa
+}
51f0aa
+
51f0aa
+__attribute__ ((noinline, noclone, weak))
51f0aa
+class_with_destructor::~class_with_destructor ()
51f0aa
+{
51f0aa
+}
51f0aa
+
51f0aa
+__attribute__ ((noinline, noclone, weak))
51f0aa
+void
51f0aa
+function_with_destructed_object ()
51f0aa
+{
51f0aa
+  class_with_destructor obj;
51f0aa
+  do_throw_exception ();
51f0aa
+}
51f0aa
+
51f0aa
+static void *
51f0aa
+threadfunc (void *closure)
51f0aa
+{
51f0aa
+  try
51f0aa
+    {
51f0aa
+      function_with_destructed_object ();
51f0aa
+      FAIL_EXIT1 ("no exception thrown");
51f0aa
+    }
51f0aa
+  catch (std::exception &e)
51f0aa
+    {
51f0aa
+      TEST_COMPARE (strcmp (e.what (), "test exception"), 0);
51f0aa
+      return reinterpret_cast<void *> (threadfunc);
51f0aa
+    }
51f0aa
+  FAIL_EXIT1 ("no exception caught");
51f0aa
+}
51f0aa
+
51f0aa
+static int
51f0aa
+do_test (void)
51f0aa
+{
51f0aa
+  pthread_attr_t attr;
51f0aa
+  xpthread_attr_init (&attr);
51f0aa
+  xpthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN);
51f0aa
+  pthread_t thr = xpthread_create (&attr, threadfunc, NULL);
51f0aa
+  TEST_VERIFY (xpthread_join (thr) == threadfunc);
51f0aa
+  xpthread_attr_destroy (&attr);
51f0aa
+  return 0;
51f0aa
+}
51f0aa
+
51f0aa
+#include <support/test-driver.c>