Bug#725383: FTBFS on kfreebsd-*: SYS_gettid is Linux-specific
Source: osgearth
Version: 2.4.0+dfsg-5
Tags: patch
User: debian-bsd@lists.debian.org
Usertags: kfreebsd
X-Debbugs-Cc: debian-bsd@lists.debian.org
Severity: serious
Justification: fails to build from source (but built successfully in the
past)
Hi,
osgearth fails to build on kfreebsd-* because it tries to directly use a
Linux-specific syscall:
https://buildd.debian.org/status/package.php?p=osgearth&suite=sid
> cd /«BUILDDIR»/osgearth-2.4.0+dfsg/build/src/osgEarth && /usr/bin/c++ -DOSGEARTH_LIBRARY -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DTIXML_USE_STL -DosgEarth_EXPORTS -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -O3 -DNDEBUG -fPIC -isystem /usr/include/qt4 -isystem /usr/include/qt4/QtGui -isystem /usr/include/qt4/QtCore -I/«BUILDDIR»/osgearth-2.4.0+dfsg/src -I/usr/include/gdal -I/usr/include/curl -o CMakeFiles/osgEarth.dir/ThreadingUtils.cpp.o -c /«BUILDDIR»/osgearth-2.4.0+dfsg/src/osgEarth/ThreadingUtils.cpp
> /«BUILDDIR»/osgearth-2.4.0+dfsg/src/osgEarth/ThreadingUtils.cpp: In function 'unsigned int osgEarth::Threading::getCurrentThreadId()':
> /«BUILDDIR»/osgearth-2.4.0+dfsg/src/osgEarth/ThreadingUtils.cpp:42:30: error: 'SYS_gettid' was not declared in this scope
> return (unsigned)::syscall(SYS_gettid);
> ^
osgearth also knows how to use Windows and Mac OS X--specific syscalls
to get a thread ID. This is not portable and there is nothing directly
equivalent on FreeBSD, see:
http://lists.freebsd.org/pipermail/freebsd-hackers/2010-June/031992.html
A workaround may be to use pthread_self(), except that the exported
getCurrentThreadId function has to return 'unsigned int'. On
kfreebsd-amd64 a 64-bit pointer to a pthread_t is not absolutely
guaranteed to be unique if truncated to 32 bits, but it is extremely
likely, and certainly better than nothing...
Please refer to attached patch which fixes package build at least. Thanks!
-- System Information:
Debian Release: jessie/sid
APT prefers unstable
APT policy: (500, 'unstable'), (1, 'experimental')
Architecture: kfreebsd-amd64 (x86_64)
Kernel: kFreeBSD 9.0-2-amd64-xenhvm
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Index: osgearth-2.4.0+dfsg/src/osgEarth/ThreadingUtils.cpp
===================================================================
--- osgearth-2.4.0+dfsg.orig/src/osgEarth/ThreadingUtils.cpp 2013-04-11 19:07:39.000000000 +0100
+++ osgearth-2.4.0+dfsg/src/osgEarth/ThreadingUtils.cpp 2013-10-04 22:04:38.898332000 +0100
@@ -20,9 +20,11 @@
#ifdef _WIN32
extern "C" unsigned long __stdcall GetCurrentThreadId();
-#else
+#elif defined(__APPLE__) || defined(__LINUX__)
# include <unistd.h>
# include <sys/syscall.h>
+#else
+# include <pthread.h>
#endif
using namespace osgEarth::Threading;
@@ -38,7 +40,10 @@
return (unsigned)::GetCurrentThreadId();
#elif __APPLE__
return ::syscall(SYS_thread_selfid);
-#else
+#elif __LINUX__
return (unsigned)::syscall(SYS_gettid);
+#else
+ /* :XXX: this truncates to 32 bits, but better than nothing */
+ return (unsigned)pthread_self();
#endif
}
Reply to: