Blob Blame History Raw
This test requires a fix for max_align_t which is rolled into the
glibc-rh1418978-max_align_t.patch file.

commit b725132d2b0aeddf970b1ce3e5a24f8637a7b4c2
Author: Florian Weimer <fweimer@redhat.com>
Date:   Tue Jan 16 07:19:28 2018 +0100

    nptl/tst-minstack-throw: Compile in C++11 mode with GNU extensions

commit 860b0240a5645edd6490161de3f8d1d1f2786025
Author: Florian Weimer <fweimer@redhat.com>
Date:   Mon Jan 15 15:30:00 2018 +0100

    nptl: Add PTHREAD_MIN_STACK C++ throw test [BZ #22636]

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