BUG: threads.h existence test requires GLIBC > 2.12.#18180
BUG: threads.h existence test requires GLIBC > 2.12.#18180mattip merged 5 commits intonumpy:masterfrom
Conversation
|
CC: @mattip @melissawm |
|
CentOS7 has glibc 2.17, Ubuntu 18.04 has 2.27. Is one of our builds on Ubuntu 18.04 so we can test this? |
|
I am on Ubuntu 18.04. |
|
I thought one or more of our CI builds use ubuntu 18.04, so how do tests pass? |
Can you point to a CI build using ubuntu 18.04 that runs f2py tests? |
|
I thought the f2py tests are part of the test suite. We should be running them on at least one of the builds. Since the tests pass without this PR, I guess they are not running. We go through the trouble of installing a gfortran compiler and libraries, so we should run the tests. Maybe as part of this PR you could add whatever is needed to make them run? |
|
The f2py tests are running. There are other differences between local and CI ubuntu boxes that may affect the build/test results:
|
|
@mattip I found the explanation of why the callback tests pass in CI but not locally: when using ubuntu gcc 7.5.0 compiler (CI), |
|
Is the glibc version the standard way to detect This discussion suggests to explicitly |
It is known that
Another approach would be to use |
|
On the second thought, since both The What do you think, @mattip ? |
This sounds like the most reasonable choice, without the glibc version check |
|
@mattip please review. |
mattip
left a comment
There was a problem hiding this comment.
Would be nice to add a comment, it took quite a bit of detective work to figure this one out and my future self will forget why this is here. Otherwise LGTM
|
Don't merge until #18180 (comment) is resolved. |
|
It's not clear from the pr title - but am I right in thinking this is actually just working around a bug in the Intel compiler where the appropriate macro doesn't end up defined? Or are we seeing this problem with gcc alone? |
The problem is with gcc (I don't have icc installed to test this atm). IIUC, gcc 9 is C17 ( |
|
My reading of the Intel thread is that glibc itself is responsible for providing |
|
Consider the following test program glibc-test.c Details#include <stdio.h>
// #include <features.h>
int main() {
printf("__STDC_VERSION__ = %ld\n", __STDC_VERSION__);
#if defined(__STDC_NO_THREADS__)
printf("__STDC_NO_THREADS__ = %d\n", __STDC_NO_THREADS__);
#else
printf("__STDC_NO_THREADS__ not defined\n");
#endif
#if defined(__GLIBC__)
printf("GLIBC version = %d.%d\n", __GLIBC__, __GLIBC_MINOR__);
#else
printf("__GLIBC__ not defined\n");
#endif
#if defined(__GNUC__)
printf("GNUC version %d.%d\n", __GNUC__, __GNUC_MINOR__);
#else
printf("__GNUC__ not defined\n");
#endif
return 0;
}that has the following outputs (including $ which gcc
/usr/bin/gcc
$ gcc --version
gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
$ gcc glibc-test.c
$ ./a.out
__STDC_VERSION__ = 201112
__STDC_NO_THREADS__ = 1
GLIBC version = 2.27
GNUC version 7.5
$ conda activate numpy-dev
$ which gcc
/home/pearu/miniconda3/envs/numpy-dev/bin/gcc
$ gcc --version
gcc (crosstool-NG 1.24.0.133_b0863d8_dirty) 9.3.0
$ gcc glibc-test.c
$ ./a.out
__STDC_VERSION__ = 201710
__STDC_NO_THREADS__ not defined
GLIBC version = 2.12
GNUC version 9.3
$ gcc glibc-test.c -std=c11
$ ./a.out
__STDC_VERSION__ = 201112
__STDC_NO_THREADS__ not defined
GLIBC version = 2.12
GNUC version 9.3Notice that the conda gcc 9.3 does not define A similar issue has been reported in https://stackoverflow.com/questions/61887795/gcc-is-non-conforming for GCC 9.2.0 (Windows 10 x64). Then according to https://gcc.gnu.org/legacy-ml/gcc-help/2019-06/msg00063.html, Digging further... it turns out that So, the problem boils down to using glibc 2.12 (or older) when My suggestion is to use: #elif defined(__STDC_VERSION__) \\
&& (__STDC_VERSION__ >= 201112L) \\
&& !defined(__STDC_NO_THREADS__) \\
&& (!defined(__GLIBC__) || __GLIBC_MINOR__>12)
// see https://github.com/numpy/numpy/pull/18180 discussion for details
#include <threads.h>
#define F2PY_THREAD_LOCAL_DECL thread_local@mattip @eric-wieser what do you think? |
|
Are you certain that 2.12 is the last version before Either way, that looks reasonable - though you should be checking I suppose the other option is to just discover if |
2.12 is the version I have tested. However, according to https://lists.gnu.org/archive/html/commit-hurd/2012-07/msg00180.html,
Makes sense.
For f2py, I am uncertain that this would be worth it. In fact, the sources of f2py generated extension modules must be self-contained (modulo numpy and Python) so that the result of discovering |
|
Huh, that commit is authored by someone ( |
eric-wieser
left a comment
There was a problem hiding this comment.
Thanks for the thorough investigation!
|
Thanks @pearu |
* defined(__STDC_NO_THREADS__) can be trusted only when using glibc > 2.12 * Add __GLIBC__ defined check.
dongkeun-oh
left a comment
There was a problem hiding this comment.
Please update a little more against the same trouble in MINGW32.
The 548th line has to be replaced with
#if defined(_MSC_VER)||defined(__MINGW32__).
|
@dongkeun-oh this was merged a few months ago. Please open a new PR with the requested change. |
| && (__STDC_VERSION__ >= 201112L) \\ | ||
| && !defined(__STDC_NO_THREADS__) | ||
| && !defined(__STDC_NO_THREADS__) \\ | ||
| && (!defined(__GLIBC__) || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 12)) |
There was a problem hiding this comment.
This would fix the #include <threads.h> on Haiku too (ticket has been filed for this upstream: https://dev.haiku-os.org/ticket/16965 )
- && (!defined(__GLIBC__) || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 12))
+ && (!defined(__GLIBC__) || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 12)) \\
+ && !defined(__HAIKU__)
Closes #18179