2

I have some warning when compiling a piece of code using pthread_cleanup_push/pop with -O2 CFLAGS. Just by removing the O2 cflags in the Makefile make it compile without issue.

Is it forbidden to use gcc optimization with these pthread macros ? I was not able to find anything in man or documentation. By the way, is there any alternative to clean stuff at the end of a thread ? Also it is working perfectly with gcc arm. But not on x86 gcc.

Warning :

x/x.c:1292:2: warning: variable ‘__cancel_routine’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Wclobbered]
  pthread_cleanup_push(x_cleanup, &fd);

My current CFLAGS option :

-W -Wall -Wformat -Wformat-security -Wextra  -Wno-unused-result,
-Wextra -Wno-long-long -Wno-variadic-macros -Wno-missing-field-initializers
-std=gnu99 -O2
yugr
  • 19,769
  • 3
  • 51
  • 96
ArthurLambert
  • 749
  • 1
  • 7
  • 30
  • 2
    I assume you've seen [BZ 61118](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61118)? – yugr Mar 18 '17 at 19:13
  • @yugr Yes I already saw this even if I was not sure if it was the reason. The bug was report on 2014... Its crazy... The only solution is to remove the Werror until a fix ? Roll back on a previous version of gcc on x86 ? It is not a deadlock to my code since the issue is not present with an ARM cross compiler. But I did want to be sure that its was not a bigger issue which can cause unexpected behavior of my code or bugs. – ArthurLambert Mar 18 '17 at 22:25
  • You could add `-Wno-clobbered` to your list of disabled warnings. – caf Mar 19 '17 at 09:07

1 Answers1

2

This issue has been reported several times now in GCC tracker (see here). I believe that this warns about real issue in pthread.h (see my comment). __cancel_routine is not marked as volatile so it's value is indeed undefined after return via longjmp which may cause arbitrary consequences.

The only solution is to remove the Werror until a fix ?

I'd rather go with -Wno-clobbered, to keep other warnings enabled.

Roll back on a previous version of gcc on x86 ?

You'll have to rollback to pre-2014 times which is quite a change... I think that if the code works for you, just disable -Wclobbered (with a descriptive comment).

But I did want to be sure that its was not a bigger issue which can cause unexpected behavior of my code or bugs.

Glibc code looks really suspicious. I'd wait for comments from GCC devs and if there is none, report this to Glibc developers.

yugr
  • 19,769
  • 3
  • 51
  • 96