This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

__assert_fail should not be __attribute__((__noreturn__))


It would be helpful if __assert_fail were not declared as 
__attribute__((__noreturn__)). __assert_fail can be replaced by LD_PRELOADing 
a shared object that implements a version that does not raise(SIGABRT) so 
that any assertions are in fact ignored. However, this fails because gcc 
makes extensive use of __attribute__((__noreturn__)) (and generates no stack 
cleanup code).

In fact, I'm writing a shared object that invokes a debugger. From the 
debugger it is easy to decide whether the assertion can be ignored, or the 
error cause can be removed by changing some program value. After doing so, it 
should be possible to continue the program.

I see no disadvantages if __assert_fail is a plain function. If the program is 
not compiled with NDEBUG, there is already the code size and runtime overhead 
for the condition check; I think that the stack cleanup penalty is 
justifyable. Could this be changed, please? I propose something like in the 
patch below.

-- Hannes
--- /usr/include/assert.h	2003-03-14 00:15:07.000000000 +0100
+++ ./assert.h	2004-04-03 22:04:45.000000000 +0200
@@ -64,16 +64,18 @@
 
 __BEGIN_DECLS
 
-/* This prints an "Assertion failed" message and aborts.  */
+/* This prints an "Assertion failed" message and aborts.
+Note that since this function can be replaced by preloaded shared objects,
+it _is_ possible that it returns.  */
 extern void __assert_fail (__const char *__assertion, __const char *__file,
 			   unsigned int __line, __const char *__function)
-     __THROW __attribute__ ((__noreturn__));
+     __THROW;
 
 /* Likewise, but prints the error text for ERRNUM.  */
 extern void __assert_perror_fail (int __errnum, __const char *__file,
 				  unsigned int __line,
 				  __const char *__function)
-     __THROW __attribute__ ((__noreturn__));
+     __THROW;
 
 
 /* The following is not at all used here but needed for standard

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]