This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH B1/2] Redefine assert to use its expression
- From: Richard Henderson <rth at twiddle dot net>
- To: libc-alpha at sourceware dot org
- Cc: roland at hack dot frob dot com
- Date: Fri, 9 Jan 2015 10:16:58 -0800
- Subject: [PATCH B1/2] Redefine assert to use its expression
- Authentication-results: sourceware.org; auth=none
- References: <1420827419-18655-1-git-send-email-rth at twiddle dot 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
--
2.1.0