On 19/03/17 18:58, Francesco Lattanzio wrote:
First be known that I'm building on FreeBSD 11.0.
When I wrote this e-mail I thought there was no pthread_setname_np() at
all, but searching more carefully I found out that there is indeed a
pthread_setname_np() function but its name is pthread_set_name_np() (see
https://www.freebsd.org/cgi/man.cgi?query=pthread_set_name_np&apropos=0&sektion=0&manpath=FreeBSD+11.0-RELEASE+and+Ports&arch=default&format=html).

Using Clang (version 3.8.0) or a recent gcc (version 6.3.0), both tests
fail and none of the two versions of pthread_setname_np() is included,
which allows for a clean link.

Using gcc 4.9.4 (the default gcc in FreeBSD) what happen is that both
checks succeed and I get both versions of pthread_setname_np() included
in rumpuser_pth.c, but neither is defined in libpthread and the
compilation terminates with the following error:

Ah, the pthread_setname_np() variant is tested only with AC_COMPILE_IFELSE, which just depends on compiler warnings/errors, not the link result. So, your initial analysis was correct.

--- rumpuser_pth.pico ---
#   compile  librumpuser/rumpuser_pth.pico
/usr/home/fltt/tmp/rump/buildrump.sh/obj/tooldir/bin/i486--netbsdelf-clang -O2 
-g   -std=gnu99     -Wno-sign-compare -Wno-pointer-sign  -Wall 
-Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wno-sign-compare  
-Wa,--fatal-warnings -Wreturn-type -Wswitch -Wshadow -Wcast-qual 
-Wwrite-strings -Wextra -Wno-unused-parameter -Wno-sign-compare 
-Wold-style-definition -Wsign-compare -Wformat=2   -Wpointer-sign 
-Wmissing-noreturn  -Werror -Wno-format     -DRUMPUSER_CONFIG=yes 
-I/usr/home/fltt/tmp/rump/buildrump.sh/obj/tooldir/autoconf 
-I/usr/home/fltt/tmp/rump/buildrump.sh/obj/tooldir/compat/include 
-I/usr/home/fltt/tmp/rump/buildrump.sh/obj/dest.stage/usr/include  
-DLIBRUMPUSER -D_KERNTYPES -D_REENTRANT  -c    -fPIC -g 
/usr/home/fltt/tmp/rump/buildrump.sh/src/lib/librumpuser/rumpuser_pth.c -o 
rumpuser_pth.pico
--- rumpuser_pth.pico ---
/usr/home/fltt/tmp/rump/buildrump.sh/src/lib/librumpuser/rumpuser_pth.c:85:3: 
error: implicit declaration of function 'pthread_setname_np' is invalid in C99 
[-Werror,-Wimplicit-function-declaration]
                pthread_setname_np(*ptidp, thrname, NULL);

Note that gcc is used to check for the presence of pthread_setname_np()
but Clang was used to compile the code. I don't know if this may be of
some relevance.

Yes and no. Yes in that it's a bug, but no in that configure.ac is also wrong. exporting CC in buildrump.sh in the snippet that runs configure should fix it, at least assuming you're running buildrump.sh with "CC=clang ./buildrump.sh". Want to try it (and submit a pull req if so)?

It looks like the correct solution would be to check for
pthread_set_name_np() too. And to avoid using the
-Wimplicit-function-declaration option you may try to actually link
against the pthread_setname_np() functions by means of the AC_TRY_LINK
macro.

Yes. Well, easier to change to AC_LINK_IFELSE, but generally yes. Want to prepare a patch for that, especially the pthread_set_name_np() part which I can't easily test?

Reply via email to