From patchwork Fri Jan 9 18:16:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 4596 Received: (qmail 4316 invoked by alias); 9 Jan 2015 18:17:38 -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 4168 invoked by uid 89); 9 Jan 2015 18:17:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-qg0-f49.google.com X-Received: by 10.140.108.9 with SMTP id i9mr27254860qgf.73.1420827453940; Fri, 09 Jan 2015 10:17:33 -0800 (PST) From: Richard Henderson To: libc-alpha@sourceware.org Cc: roland@hack.frob.com Subject: [PATCH B1/2] Redefine assert to use its expression Date: Fri, 9 Jan 2015 10:16:58 -0800 Message-Id: <1420827419-18655-2-git-send-email-rth@twiddle.net> In-Reply-To: <1420827419-18655-1-git-send-email-rth@twiddle.net> References: <1420827419-18655-1-git-send-email-rth@twiddle.net> This also fixes the -Werrors from -DNDEBUG on x86_64, but in the opposite direction. We make assert always use its expression. This requires removing some existing ifndefs that were working around this same problem of unused variables. There is exactly one compilation difference from patch A1, in fork.os, where the THREAD_GETMEM read cannot be optimized away, because the asm is marked volatile. (Yet another reason to finish code in gcc to expose segments as address spaces, so that this can be written in C.) r~ * include/assert.h (assert): Redefine to use the argument. (assert_perror): Likewise. * elf/rtld.c (dl_main): Don't check NDEBUG. * locale/programs/ld-collate.c (collate_output): Likewise. * sysdeps/nptl/fork.c (__libc_fork): Likewise. --- elf/rtld.c | 2 -- include/assert.h | 7 +++++++ locale/programs/ld-collate.c | 2 -- sysdeps/nptl/fork.c | 2 -- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/elf/rtld.c b/elf/rtld.c index 69873c2..0772a78 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -1391,9 +1391,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n", /* We cannot use the DSO, it does not have the appropriate interfaces or it expects something more recent. */ -#ifndef NDEBUG Lmid_t ns = dlmargs.map->l_ns; -#endif _dl_close (dlmargs.map); /* Make sure the namespace has been cleared entirely. */ diff --git a/include/assert.h b/include/assert.h index c452667..d7e2759 100644 --- a/include/assert.h +++ b/include/assert.h @@ -25,3 +25,10 @@ hidden_proto (__assert_fail) hidden_proto (__assert_perror_fail) # endif #endif + +#ifdef NDEBUG +# undef assert +# undef assert_perror +# define assert(expr) ((void)(0 && (expr))) +# define assert_perror(errnum) ((void)(0 && (errnum))) +#endif diff --git a/locale/programs/ld-collate.c b/locale/programs/ld-collate.c index dc0fe30..ba620c9 100644 --- a/locale/programs/ld-collate.c +++ b/locale/programs/ld-collate.c @@ -2432,9 +2432,7 @@ collate_output (struct localedef_t *locale, const struct charmap_t *charmap, uint32_t namelen = strlen (runp->name); uint32_t hash = elem_hash (runp->name, namelen); size_t idx = hash % elem_size; -#ifndef NDEBUG size_t start_idx = idx; -#endif if (elem_table[idx * 2] != 0) { diff --git a/sysdeps/nptl/fork.c b/sysdeps/nptl/fork.c index 5cffd82..cf71fe1 100644 --- a/sysdeps/nptl/fork.c +++ b/sysdeps/nptl/fork.c @@ -110,9 +110,7 @@ __libc_fork (void) _IO_list_lock (); -#ifndef NDEBUG pid_t ppid = THREAD_GETMEM (THREAD_SELF, tid); -#endif /* We need to prevent the getpid() code to update the PID field so that, if a signal arrives in the child very early and the signal