Can't use pthread_cleanup_push with non-GCC compiler

Bug #33140 reported by ake sandgren
Affects Status Importance Assigned to Milestone
Fix Released
glibc (Ubuntu)
Fix Released

Bug Description

When trying to compile a small pthread code with the Portland compiler the pthread.h gives me code that uses gcc builtins.

libc6-dev version 2.3.5-1ubuntu12

#include <pthread.h>
main ()
    pthread_t th=pthread_self();
    pthread_join(th, 0);
    pthread_cleanup_push(0, 0);
    return 0;

When compiled with PGI i get
$ pgcc -o ptest ptest.c -lpthread
ptest.o: In function `main':
ptest.c:(.text+0x46): undefined reference to `__builtin_expect'

This seems to be caused by the following sequence of #if defined in pthread.h

#if defined __GNUC__ && defined __EXCEPTIONS
# ifdef __cplusplus
# define pthread_cleanup_push(routine, arg) \
  do { \
    __pthread_cleanup_class __clframe (routine, arg)
# else
# define pthread_cleanup_push(routine, arg) \
   do { \
    struct __pthread_cleanup_frame __clframe \
      __attribute__ ((__cleanup__ (__pthread_cleanup_routine))) \
      = { .__cancel_routine = (routine), .__cancel_arg = (arg), \
          .__do_it = 1 };
# endif
# define pthread_cleanup_push(routine, arg) \
  do { \
    __pthread_unwind_buf_t __cancel_buf; \
    void (*__cancel_routine) (void *) = (routine); \
    void *__cancel_arg = (arg); \
    int not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) \
                                      __cancel_buf.__cancel_jmp_buf, 0); \
    if (__builtin_expect (not_first_call, 0)) \

I.e. it uses __builtin_expect when __GCC__ is not defined.

All of this seems to be a bit too GCC centric.

Revision history for this message
ake sandgren (ake-sandgren) wrote :

Forgot to mention that this is on a x86_64 machine.

Changed in glibc:
status: Unknown → Unconfirmed
Matthias Klose (doko)
Changed in glibc:
status: Unconfirmed → Confirmed
Changed in glibc:
status: New → Fix Released
Revision history for this message
dino99 (9d9) wrote :

This bug has been fixed in upstream glibc 2.16, which first appeared in
debian as eglibc 2.16-0experimental0.

Changed in glibc (Ubuntu):
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.