ncbi/ncbi-vdb

Static declaration of gettid follows non-static declaration

MatthewRalston opened this issue · 4 comments

I have trouble installing ncbi-vdb through my package manager and from source, same error.

I've tried passing in CFLAGS that are recognized by the configure script, but dont pass through konfigure.pl properly.

The issue seems to center around libs/kproc/linux/sysmgr.c.

/home/matt/pckges/ncbi-vdb/libs/kproc/linux/sysmgr.c:36:7: error: static declaration of ‘gettid’ follows non-static declaration
   36 | pid_t gettid ( void )
      |       ^~~~~~
In file included from /usr/include/unistd.h:1170,
                 from /home/matt/pckges/ncbi-vdb/libs/kproc/linux/sysmgr.c:30:
/usr/include/bits/unistd_ext.h:34:16: note: previous declaration of ‘gettid’ was here
   34 | extern __pid_t gettid (void) __THROW;
      |                ^~~~~~
cc1: warning: unrecognized command line option ‘-Wno-c++11-extensions’
cc1: warning: unrecognized command line option ‘-Wno-c++98-compat-pedantic’
cc1: warning: unrecognized command line option ‘-Wno-c++98-compat’
make[3]: *** [/home/matt/pckges/ncbi-vdb/build/Makefile.rules:46: sysmgr.pic.o] Error 1
make[2]: *** [/home/matt/pckges/ncbi-vdb/build/Makefile.env:141: stdcompile] Error 2
make[1]: *** [Makefile:84: kproc] Error 2
make: *** [Makefile:47: libs] Error 2

Thank you for the report. We have no ability to directly support arch-linux, although we strive to be portable. The system under which the offending code was developed did not properly define gettid() which is why we introduced it as a static function. If you have any pre-processor defines we could use to know when this function is available, please include them here!

This is a glibc>=2.30 specific wrapper. From the man page:

The gettid() system call first appeared on Linux in kernel 2.4.11. Library support was added in glibc 2.30. (Earlier glibc versions did not provide a wrapper for this system call, necessitating the use of syscall(2).)

glibc 2.30 was released recently (2019-08-01), that's may explain why this problem was only encountered recently.

A preprocessor check could written be like this:

[...]
#include <unistd.h>

#if !defined(_GNU_SOURCE) || !defined(__GLIBC__) || __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 30)
#include <sys/syscall.h>
static
pid_t gettid ( void )
{
    return syscall ( SYS_gettid );
}
#endif

static __thread bool have_tid, on_main_thread;
[...]

Thanks! We'll make the update.

The fix will be available in the master branch on our next release.