From patchwork Wed Jul 15 00:58:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 495353 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 224351402C9 for ; Wed, 15 Jul 2015 10:58:54 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b=KUlNAL+P; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=eeqPAA0xZG5qyKDxpysfwLsV8YCwlP5 qaOFg7L0T71rSVsMp9wiefLnY9EUjtceSB3Q7V+NO/SvBgcQMIvocR8Iqn/9W+sM y7VRStP67KCyUxAy2zGOzzhYPi1B1k9kc9HgshlrF5AyT0uPccIHTIHe8SIy7y9N wpoUH/biLExY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; s=default; bh=vt5pUuEMCqIkTP7OEsvCtd2jCA8=; b=KUlNA L+PTD6wrgSZJ68xG+2Y8JWk2481s9Kzaed6Lnes0V/qbK5yJ4M/gu4bfwgrs/UNM x0o/BkdxE1YDlfh8tA4fgSGAGjlWZBXETRV4xhrRtYK6YYQ9+HULRLUqGdDHcUGY eAi0KoKhUUcXnOCMTdHkUDD8EwDWfm/xx+YsKQ= Received: (qmail 5283 invoked by alias); 15 Jul 2015 00:58:48 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 5265 invoked by uid 89); 15 Jul 2015 00:58:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com From: "Siddhesh Poyarekar" To: libc-alpha@sourceware.org Cc: roland@hack.frob.com Subject: [PATCH v2] Remove Linuxism from tst-tls-atexit Date: Wed, 15 Jul 2015 06:28:38 +0530 Message-Id: <1436921918-3008-1-git-send-email-siddhesh@redhat.com> In-Reply-To: <1436883383-6903-1-git-send-email-siddhesh@redhat.com> References: <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 #include -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 ()