nptl: __libc_cleanup_push/__libc_cleanup_pop require -fexceptions

Message ID 87im69264f.fsf@oldenburg.str.redhat.com
State Committed
Headers
Series nptl: __libc_cleanup_push/__libc_cleanup_pop require -fexceptions |

Commit Message

Florian Weimer March 2, 2021, 10:37 a.m. UTC
  Do not define these macros if they do nothing in a particular
compilation, otherwise they can easily be used accidentally, while
not actually achieving anything.

Built with build-many-glibcs.py after the __dl_iterate_phdr fix.

---
 sysdeps/nptl/libc-lockP.h | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
  

Comments

Andreas Schwab March 2, 2021, 10:43 a.m. UTC | #1
Ok.

Andreas.
  

Patch

diff --git a/sysdeps/nptl/libc-lockP.h b/sysdeps/nptl/libc-lockP.h
index e676eadfd3..7cdf17005f 100644
--- a/sysdeps/nptl/libc-lockP.h
+++ b/sysdeps/nptl/libc-lockP.h
@@ -271,6 +271,9 @@  extern void _pthread_cleanup_pop_restore (struct _pthread_cleanup_buffer *buffer
     } else if (DOIT)							      \
       _buffer.__routine (_buffer.__arg)
 
+/* __libc_cleanup_push and __libc_cleanup_pop depend on exception
+   handling and stack unwinding.  */
+#ifdef __EXCEPTIONS
 
 /* Normal cleanup handling, based on C cleanup attribute.  */
 static __always_inline void
@@ -280,17 +283,17 @@  __libc_cleanup_routine (struct __pthread_cleanup_frame *f)
     f->__cancel_routine (f->__cancel_arg);
 }
 
-#define __libc_cleanup_push(fct, arg) \
+# define __libc_cleanup_push(fct, arg) \
   do {									      \
     struct __pthread_cleanup_frame __clframe				      \
       __attribute__ ((__cleanup__ (__libc_cleanup_routine)))		      \
       = { .__cancel_routine = (fct), .__cancel_arg = (arg),		      \
 	  .__do_it = 1 };
 
-#define __libc_cleanup_pop(execute) \
+# define __libc_cleanup_pop(execute) \
     __clframe.__do_it = (execute);					      \
   } while (0)
-
+#endif /* __EXCEPTIONS */
 
 /* Create thread-specific key.  */
 #define __libc_key_create(KEY, DESTRUCTOR) \