Source: libselinux
Version: 3.1-3
Tags: ftbfs patch upstream
User: helm...@debian.org
Usertags: rebootstrap

libselinux fails to build from source on musl, because its "detection"
for gettid is broken. Essentially it says that bionic and sufficiently
recent glibc has glibc and everything else does not. Unfortunately, that
guess is wrong on musl.

I propose ending the guesswork and just checking for the presence of
gettid. Doing so makes matters rather simple and eliminate future
porting to other C libraries. Please consider applying the attached
patch.

Also note that debian/patches/drop-gettid.patch looks like it can be
deleted.

Helmut
--- libselinux-3.1.orig/src/Makefile
+++ libselinux-3.1/src/Makefile
@@ -98,6 +98,10 @@ override LDFLAGS += -L/opt/local/lib -un
 LD_SONAME_FLAGS=-install_name,$(LIBSO)
 endif
 
+ifeq (yes,$(shell printf '#define _GNU_SOURCE\n#include <unistd.h>\n#include <sys/types.h>\nint main(void){pid_t n=gettid();return n;}' | $(CC) -x c -o /dev/null - >/dev/null 2>&1 && echo yes))
+CFLAGS += -DHAVE_GETTID
+endif
+
 PCRE_LDLIBS ?= -lpcre
 # override with -lfts when building on Musl libc to use fts-standalone
 FTS_LDLIBS ?=
--- libselinux-3.1.orig/src/procattr.c
+++ libselinux-3.1/src/procattr.c
@@ -22,19 +22,7 @@ static pthread_key_t destructor_key;
 static int destructor_key_initialized = 0;
 static __thread char destructor_initialized;
 
-/* Bionic and glibc >= 2.30 declare gettid() system call wrapper in unistd.h and
- * has a definition for it */
-#ifdef __BIONIC__
-  #define OVERRIDE_GETTID 0
-#elif !defined(__GLIBC_PREREQ)
-  #define OVERRIDE_GETTID 1
-#elif !__GLIBC_PREREQ(2,30)
-  #define OVERRIDE_GETTID 1
-#else
-  #define OVERRIDE_GETTID 0
-#endif
-
-#if OVERRIDE_GETTID
+#ifndef HAVE_GETTID
 static pid_t gettid(void)
 {
 	return syscall(__NR_gettid);

Reply via email to