C++ standard library is compiled with nanosleep and yield switched OFF

Bug #1269803 reported by Denys Rtveliashvili on 2014-01-16
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gcc-4.6 (Ubuntu)
Undecided
Unassigned

Bug Description

INTRODUCTION
--------------------------

The C++ library has internal macros called _GLIBCXX_USE_NANOSLEEP and _GLIBCXX_USE_SCHED_YIELD.

Normally the macros are defined in x86_64-linux-gnu/32/bits/c++config.h and x86_64-linux-gnu/bits/c++config.h.

When _GLIBCXX_USE_NANOSLEEP is defined, the standard library has support for crucial components related to time.

Specifically, in "thread" there is a section which begins with "#ifdef _GLIBCXX_USE_NANOSLEEP" and declares "sleep_until", "sleep_for", "nanosleep", "chrono::seconds", "chrono::nanoseconds", etc. There functions / types are an important part of C++ standard.

The _GLIBCXX_USE_SCHED_YIELD macro enables "yield()" method.

PROBLEM
--------------------------

C++ code which depends on the relevant parts of the C++ standard simply cannot be compiled.
There is no known and reliable workaround for this problem.

WHY IT HAPPENED
--------------------------
I am not 100% sure, but there seem to be a bug in a test program which check for the presence of nanosleep. It is a part of "configure", which is in turn generated from acinclude.m4.

In order to test for nanosleep the following program is used:

#include <unistd.h>
   #include <time.h>

int
main ()
{
#if _POSIX_TIMERS > 0 && defined(_POSIX_MONOTONIC_CLOCK)
    timespec tp;
   #endif
    clock_gettime(CLOCK_MONOTONIC, &tp);

  ;
  return 0;
}

The program is missing "struct" before "timespec tp;". In fact, there are three places in the file where the "struct" is missing.

As for "yield", I am not sure yet why it is missing but the reason is probably similar.

SCOPE
--------------------------
Both macros are NOT enabled in Ubuntu releases after 12.04 LTS, including the to-be-released Ubuntu 14.04 LTS.

For example, on Ubuntu 13.10:

 rtvd@localhost $ pwd

 /usr/include/c++

 rtvd@localhost $ grep -r _GLIBCXX_USE_NANOSLEEP *

 4.6/thread:#ifdef _GLIBCXX_USE_NANOSLEEP
 4.6/x86_64-linux-gnu/32/bits/c++config.h:/* #undef _GLIBCXX_USE_NANOSLEEP */
 4.6/x86_64-linux-gnu/bits/c++config.h:/* #undef _GLIBCXX_USE_NANOSLEEP */
 4.6.4/thread:#ifdef _GLIBCXX_USE_NANOSLEEP
 4.6.4/x86_64-linux-gnu/32/bits/c++config.h:/* #undef _GLIBCXX_USE_NANOSLEEP */
 4.6.4/x86_64-linux-gnu/bits/c++config.h:/* #undef _GLIBCXX_USE_NANOSLEEP */
 4.7/thread:#ifdef _GLIBCXX_USE_NANOSLEEP
 4.7.3/thread:#ifdef _GLIBCXX_USE_NANOSLEEP
 4.8/thread:#ifdef _GLIBCXX_USE_NANOSLEEP
 4.8.1/thread:#ifdef _GLIBCXX_USE_NANOSLEEP

On Ubuntu 12.04 LTS (notice #define ...) everything is good:

 rtvd@localhost $ pwd

 /usr/include/c++

 rtvd@localhost $ grep -r _GLIBCXX_USE_NANOSLEEP *

 4.6/x86_64-linux-gnu/bits/c++config.h:#define _GLIBCXX_USE_NANOSLEEP 1
 4.6/x86_64-linux-gnu/32/bits/c++config.h:#define _GLIBCXX_USE_NANOSLEEP 1
 4.6/thread:#ifdef _GLIBCXX_USE_NANOSLEEP
 4.6.3/x86_64-linux-gnu/bits/c++config.h:#define _GLIBCXX_USE_NANOSLEEP 1
 4.6.3/x86_64-linux-gnu/32/bits/c++config.h:#define _GLIBCXX_USE_NANOSLEEP 1
 4.6.3/thread:#ifdef _GLIBCXX_USE_NANOSLEEP

On Debian 7.3 the macros are defined (notice #define ... in each version of the library), so C++ library is good there too:

 rtvd@debiantest:/usr/include/c++$ pwd

 /usr/include/c++

 rtvd@debiantest:/usr/include/c++$ grep -r _GLIBCXX_USE_NANOSLEEP *

 4.6/x86_64-linux-gnu/bits/c++config.h:#define _GLIBCXX_USE_NANOSLEEP 1
 4.6/x86_64-linux-gnu/32/bits/c++config.h:#define _GLIBCXX_USE_NANOSLEEP 1
 4.6/thread:#ifdef _GLIBCXX_USE_NANOSLEEP
 4.6.3/x86_64-linux-gnu/bits/c++config.h:#define _GLIBCXX_USE_NANOSLEEP 1
 4.6.3/x86_64-linux-gnu/32/bits/c++config.h:#define _GLIBCXX_USE_NANOSLEEP 1
 4.6.3/thread:#ifdef _GLIBCXX_USE_NANOSLEEP
 4.7/x86_64-linux-gnu/bits/c++config.h:#define _GLIBCXX_USE_NANOSLEEP 1
 4.7/x86_64-linux-gnu/32/bits/c++config.h:#define _GLIBCXX_USE_NANOSLEEP 1
 4.7/thread:#ifdef _GLIBCXX_USE_NANOSLEEP
 4.7.2/x86_64-linux-gnu/bits/c++config.h:#define _GLIBCXX_USE_NANOSLEEP 1
 4.7.2/x86_64-linux-gnu/32/bits/c++config.h:#define _GLIBCXX_USE_NANOSLEEP 1
 4.7.2/thread:#ifdef _GLIBCXX_USE_NANOSLEEP

Denys Rtveliashvili (rtvd) wrote :

To be clear, gcc-4.6 is affected starting from gcc-4.6.4. gcc-4.6.3 which comes with Ubuntu 12.04 LTS is still good.
Also, gcc-4.7 and gcc-4.8 are affected.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers