public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "Siddhesh Poyarekar" <siddhesh@redhat.com>
To: libc-alpha@sourceware.org
Cc: roland@hack.frob.com
Subject: [PATCH v2] Remove Linuxism from tst-tls-atexit
Date: Wed, 15 Jul 2015 00:58:00 -0000	[thread overview]
Message-ID: <1436921918-3008-1-git-send-email-siddhesh@redhat.com> (raw)
In-Reply-To: <1436883383-6903-1-git-send-email-siddhesh@redhat.com>

The tst-tls-atexit test case searches for its module in /proc/PID/maps
to verify that it is unloaded, which is a Linux-specific test.  This
patch makes the test generic by trying to call foo (the symbol
obtained from dlsym) and traps SIGSEGV momentarily to see if the crash
occurred.

Verified that the test continues to succeed on x86_64.  There is a bug
in the test case where it calls dlclose once again, which is actually
incorrect but still manages to unload the DSO thanks to an existing
bug in __tls_call_dtors.  This will be fixed in a later patch which
also fixes up the __cxa_thread_atexit_impl implementation.

v2: Replaced setjmp/longjmp with a simple _exit.

	* stdlib/tst-tls-atexit.c: Include setjmp.h
	(foo): Move out from LOAD.
	(env): New variable.
	(segv_handler): New function.
	(load): Make static.
	(do_test): Install SIGSEGV handler and test for call to FOO.
---
 stdlib/tst-tls-atexit.c | 46 ++++++++++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 22 deletions(-)

diff --git a/stdlib/tst-tls-atexit.c b/stdlib/tst-tls-atexit.c
index 0c6c499..cd3e2b3 100644
--- a/stdlib/tst-tls-atexit.c
+++ b/stdlib/tst-tls-atexit.c
@@ -28,9 +28,17 @@
 #include <string.h>
 #include <errno.h>
 
-void *handle;
+static void *handle;
+static void (*foo) (void);
 
-void *
+static void
+segv_handler (int sig)
+{
+  /* All good. */
+  _exit (0);
+}
+
+static void *
 load (void *u)
 {
   handle = dlopen ("$ORIGIN/tst-tls-atexit-lib.so", RTLD_LAZY);
@@ -40,7 +48,7 @@ load (void *u)
       return (void *) (uintptr_t) 1;
     }
 
-  void (*foo) (void) = (void (*) (void)) dlsym (handle, "do_foo");
+  foo = (void (*) (void)) dlsym (handle, "do_foo");
 
   if (foo == NULL)
     {
@@ -82,29 +90,23 @@ do_test (void)
   /* Now this should unload the DSO.  */
   dlclose (handle);
 
-  /* Run through our maps and ensure that the DSO is unloaded.  */
-  FILE *f = fopen ("/proc/self/maps", "r");
-
-  if (f == NULL)
+  /* Handle SIGSEGV.  We don't use the EXPECTED_SIGNAL macro because we want to
+     detect any other SIGSEGVs as failures.  */
+  struct sigaction sa, old_sa;
+  sa.sa_handler = segv_handler;
+  sigemptyset (&sa.sa_mask);
+  sa.sa_flags = 0;
+  if (sigaction (SIGSEGV, &sa, &old_sa) < 0)
     {
-      perror ("Failed to open /proc/self/maps");
-      fprintf (stderr, "Skipping verification of DSO unload\n");
-      return 0;
+      printf ("Failed to set SIGSEGV handler: %m\n");
+      return 1;
     }
 
-  char *line = NULL;
-  size_t s = 0;
-  while (getline (&line, &s, f) > 0)
-    {
-      if (strstr (line, "tst-tls-atexit-lib.so"))
-        {
-	  printf ("DSO not unloaded yet:\n%s", line);
-	  return 1;
-	}
-    }
-  free (line);
+  /* This should crash...  */
+  foo ();
 
-  return 0;
+  /* ... or else we fail.  */
+  return 1;
 }
 
 #define TEST_FUNCTION do_test ()
-- 
2.4.3

  parent reply	other threads:[~2015-07-15  0:58 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-14 14:16 [PATCH] " Siddhesh Poyarekar
2015-07-14 17:39 ` Andreas Schwab
2015-07-14 17:55   ` Zack Weinberg
2015-07-15  0:14     ` Siddhesh Poyarekar
2015-07-14 19:40 ` Roland McGrath
2015-07-15  0:18   ` Siddhesh Poyarekar
2015-07-15  1:00     ` Roland McGrath
2015-07-15  3:43       ` Siddhesh Poyarekar
2015-07-15 11:31       ` Szabolcs Nagy
2015-07-15  0:58 ` Siddhesh Poyarekar [this message]
2015-07-15  6:23 ` [PATCH v3] " Siddhesh Poyarekar
2015-07-20  9:57   ` [ping][PATCH " Siddhesh Poyarekar
2015-07-20 13:05   ` [PATCH " Carlos O'Donell
2015-07-20 16:36     ` [PATCH v6] " Siddhesh Poyarekar
2015-07-20 17:05       ` Andreas Schwab
2015-07-20 17:12         ` Siddhesh Poyarekar
2015-07-20 17:23     ` [PATCH v7] " Siddhesh Poyarekar
2015-07-20 17:34       ` Carlos O'Donell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1436921918-3008-1-git-send-email-siddhesh@redhat.com \
    --to=siddhesh@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=roland@hack.frob.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).