After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 785955 - pthread_setname_np misdetected with meson
pthread_setname_np misdetected with meson
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: build
2.53.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2017-08-07 17:07 UTC by Armin K.
Modified: 2017-08-10 13:36 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
meson: Define _GNU_SOURCE as a project argument (883 bytes, patch)
2017-08-09 20:37 UTC, Emmanuele Bassi (:ebassi)
committed Details | Review
meson: Update the pthread feature checks (1.96 KB, patch)
2017-08-09 20:38 UTC, Emmanuele Bassi (:ebassi)
committed Details | Review

Description Armin K. 2017-08-07 17:07:58 UTC
When using meson to build glib git master, pthread_setname_np prototype is misdetected and build fails with the following (ignore the version, it is git master from today):

clang  -Iglib/glib-2.0@sha -Iglib -I../glib-2.53.4/glib -I. -I../glib-2.53.4/ -Xclang -fcolor-diagnostics -pipe -D_FILE_OFFSET_BITS=64 -std=gnu89 -march=skylake -fomit-frame-pointer -fstack-protector-strong -O2 -fPIC -pthread '-DG_LOG_DOMAIN="GLib"' -DGLIB_COMPILATION -DPCRE_STATIC -fvisibility=hidden -MMD -MQ 'glib/glib-2.0@sha/gthread-posix.c.o' -MF 'glib/glib-2.0@sha/gthread-posix.c.o.d' -o 'glib/glib-2.0@sha/gthread-posix.c.o' -c ../glib-2.53.4/glib/gthread-posix.c
../glib-2.53.4/glib/gthread-posix.c:1231:27: error: too few arguments to function call, expected 2, have 1
  pthread_setname_np (name); /* on OS X and iOS */
  ~~~~~~~~~~~~~~~~~~      ^
/usr/include/pthread.h:452:1: note: 'pthread_setname_np' declared here
extern int pthread_setname_np (pthread_t __target_thread, const char *__name)


Inside meson-log.txt, there's the following:

Running compile:
Working directory:  /tmp/tmppgses23b
Command line:  clang /tmp/tmppgses23b/testfile.c -march=skylake -fomit-frame-pointer -fstack-protector-strong -O2 -pipe -O0 -std=gnu89 -D_FILE_OFFSET_BITS=64 -o /tmp/tmppgses23b/output.exe 

Code:
 #include <pthread.h>
                 int main() {
                   pthread_setname_np("example");
                 }
Compiler stdout:
 
Compiler stderr:
 
Checking if "pthread_setname_np(const char*)" links: YES


Now, if I manually compile that program with clang, I get the following

$ cat test.c
 #include <pthread.h>
                 int main() {
                   pthread_setname_np("example");
                 }

$ gcc test.c -pthread
test.c: In function ‘main’:
test.c:3:20: warning: implicit declaration of function ‘pthread_setname_np’; did you mean ‘pthread_setcanceltype’? [-Wimplicit-function-declaration]
                    pthread_setname_np("example");
                    ^~~~~~~~~~~~~~~~~~
                    pthread_setcanceltype
$ gcc -std=c89 test.c -pthread

$ clang test.c -pthread

test.c:3:20: warning: implicit declaration of function 'pthread_setname_np' is invalid in C99 [-Wimplicit-function-declaration]
                   pthread_setname_np("example");
                   ^
1 warning generated.

$ clang -std=c89 test.c -pthread

As you can see, in c89 mode (which meson forces), no warning or error will be generated with either clang or gcc.

This is gcc 7.1.1 20170727, clang 4.0.1, glibc 2.26, binutils 2.29

PKGBUILD and meson flags can be found at

https://github.com/elkrejzi/pacman/blob/master/pkgbuild/glib/PKGBUILD.meson
Comment 1 Emmanuele Bassi (:ebassi) 2017-08-09 20:28:42 UTC
The proximal cause is that we need to define _GNU_SOURCE in order to get the pthread_setname_np() with the thread name argument.

On top of that, we have a bug in our feature detection test in GLib's meson.build, where we don't pass the thread dependency when checking for pthread features.

On top of that, Meson has a bug when it comes to resolving the thread library dependency inside compiler checks; see: https://github.com/mesonbuild/meson/issues/2165
Comment 2 Emmanuele Bassi (:ebassi) 2017-08-09 20:37:48 UTC
Created attachment 357303 [details] [review]
meson: Define _GNU_SOURCE as a project argument

We use it pretty much everywhere in order to get feature detection, and
that's also what the AC_USE_SYSTEM_EXTENSIONS m4 macro defines in the
Autotools build.
Comment 3 Emmanuele Bassi (:ebassi) 2017-08-09 20:38:15 UTC
Created attachment 357305 [details] [review]
meson: Update the pthread feature checks

For GNU extensions, we need to define _GNU_SOURCE; but, more
importantly, we need to tell Meson to use the threadlib dependency when
compiling and linking the feature check.

This currently exposes a bug in Meson; see:

https://github.com/mesonbuild/meson/issues/2165

But once that's fixed, the check will work as intended.
Comment 4 Emmanuele Bassi (:ebassi) 2017-08-10 09:17:46 UTC
Good news is that the Meson bug has already been fixed in Git, so we should merge those those attachments, and then wait until the next stable release.
Comment 5 Philip Withnall 2017-08-10 10:23:52 UTC
Review of attachment 357303 [details] [review]:

++
Comment 6 Philip Withnall 2017-08-10 10:24:53 UTC
Review of attachment 357305 [details] [review]:

This looks good from the GLib point of view. I don’t know enough Meson to say if it’s good from that PoV.
Comment 7 Emmanuele Bassi (:ebassi) 2017-08-10 13:36:39 UTC
Attachment 357303 [details] pushed as 1a755a6 - meson: Define _GNU_SOURCE as a project argument
Attachment 357305 [details] pushed as 50eeb24 - meson: Update the pthread feature checks