From 215789651ce2451d77dff39d9cdd8c00203443ef Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Tue, 4 Mar 2014 11:49:34 +0000 Subject: [PATCH 1/4] build: check for qsort_r independent of platform Rather than check for specific glibc version on PLATFORM_LINUX, check the existance of qsort_r. This fixes the following compile error with musl libc: CC src/main.o In file included from src/main.c:39:0: src/tvheadend.h:608:20: error: missing binary operator before token "(" #if !__GLIBC_PREREQ(2,8) ^ --- configure | 9 +++++++++ src/tvheadend.h | 6 ++---- src/wrappers.c | 6 ++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/configure b/configure index 07704b09..4446e349 100755 --- a/configure +++ b/configure @@ -103,6 +103,15 @@ int test ( void ) return ok; }' -lpthread +check_cc_snippet qsort_r ' +#include +#define TEST test +int test(void) +{ + qsort_r(NULL, 0, 0, NULL, NULL); + return 0; +} +' # # Python # diff --git a/src/tvheadend.h b/src/tvheadend.h index 0bb2be80..218ac5db 100644 --- a/src/tvheadend.h +++ b/src/tvheadend.h @@ -603,14 +603,12 @@ int rmtree ( const char *path ); char *regexp_escape ( const char *str ); -#ifdef PLATFORM_LINUX /* glibc wrapper */ -#if !__GLIBC_PREREQ(2,8) +#if ! ENABLE_QSORT_R void qsort_r(void *base, size_t nmemb, size_t size, int (*cmp)(const void *, const void *, void *), void *aux); -#endif -#endif /* PLATFORM_LINUX */ +#endif /* ENABLE_QSORT_R */ /* printing */ # if __WORDSIZE == 64 diff --git a/src/wrappers.c b/src/wrappers.c index 4343fc50..f3ed9b1a 100644 --- a/src/wrappers.c +++ b/src/wrappers.c @@ -135,12 +135,11 @@ tvhthread_create0 return r; } -#ifdef PLATFORM_LINUX +#if ! ENABLE_QSORT_R /* * qsort_r wrapper for pre GLIBC 2.8 */ -#if !__GLIBC_PREREQ(2,8) static __thread struct { int (*cmp) ( const void *a, const void *b, void *p ); void *aux; @@ -160,5 +159,4 @@ qsort_r(void *base, size_t nmemb, size_t size, qsort_r_data.aux = aux; qsort(base, nmemb, size, qsort_r_wrap); } -#endif /* GLIBC < 2.8 */ -#endif /* PLATFORM_LINUX */ +#endif /* ENABLE_QSORT_R */ From db29bca26bbc84585b7d5acc4a42d7a1ba92550a Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Tue, 4 Mar 2014 11:56:33 +0000 Subject: [PATCH 2/4] build: check for gcc version independent of platform Use the gcc specific __GNUC__ and __GNUC__ minor to determine gcc version rather than using the GNU libc specific __GNUC_PREREQ. This fixes the following compile error with musl libc: src/descrambler/capmt.c:79:18: error: missing binary operator before token "(" #if __GNUC_PREREQ(4, 3) ^ --- src/descrambler/capmt.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/descrambler/capmt.c b/src/descrambler/capmt.c index 258bc2bd..4793e97d 100644 --- a/src/descrambler/capmt.c +++ b/src/descrambler/capmt.c @@ -74,9 +74,8 @@ #define CW_DUMP(buf, len, format, ...) \ printf(format, __VA_ARGS__); int j; for (j = 0; j < len; ++j) printf("%02X ", buf[j]); printf("\n"); -#if defined(__GNUC__) && defined(PLATFORM_LINUX) -#include -#if __GNUC_PREREQ(4, 3) +#if defined(__GNUC__) && defined(__GNUC_MINOR__) +#if 100*__GNUC__+__GNUC_MINOR >=403 #pragma GCC diagnostic ignored "-Warray-bounds" #endif #endif From edf9edf5a14ae282b8ef1fff514347964714431a Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Tue, 4 Mar 2014 12:32:34 +0000 Subject: [PATCH 3/4] build: detect wordsize in a portable way There are no standard that says that __WORDSIZE should be defined or in what include file. So in case its not defined we fallback to a POSIX compliant way to determine wordsize. This fixes build with 64 bit musl libc. See https://tvheadend.org/issues/1983 --- src/tvheadend.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/tvheadend.h b/src/tvheadend.h index 218ac5db..a5218510 100644 --- a/src/tvheadend.h +++ b/src/tvheadend.h @@ -31,6 +31,7 @@ #include #include #include +#include #if ENABLE_LOCKOWNER #include #endif @@ -611,6 +612,14 @@ qsort_r(void *base, size_t nmemb, size_t size, #endif /* ENABLE_QSORT_R */ /* printing */ +#ifndef __WORDSIZE +# if ULONG_MAX == 0xffffffffffffffff +# define __WORDSIZE 64 +# elif ULONG_MAX == 0xffffffff +# define __WORDSIZE 32 +# endif /* ULONG_MAX */ +#endif /* __WORDSIZE */ + # if __WORDSIZE == 64 #define PRIsword_t PRId64 #define PRIuword_t PRIu64 From 851fcf9ce315314701c19053610934b6a041bf48 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Tue, 4 Mar 2014 15:22:45 +0000 Subject: [PATCH 4/4] build: typecast NGREG to int Fixes the following error with musl libc: src/trap.c: In function 'traphandler': src/trap.c:178:3: error: format '%d' expects argument of type 'int', but argument 4 has type 'long unsigned int' [-Werror=format=] snprintf(tmpbuf, sizeof(tmpbuf), "Register dump [%d]: ", NGREG); ^ --- src/trap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/trap.c b/src/trap.c index 00664724..b0f1c358 100644 --- a/src/trap.c +++ b/src/trap.c @@ -175,7 +175,7 @@ traphandler(int sig, siginfo_t *si, void *UC) tvhlog_spawn(LOG_ALERT, "CRASH", "Loaded libraries: %s ", libs); #ifdef NGREG - snprintf(tmpbuf, sizeof(tmpbuf), "Register dump [%d]: ", NGREG); + snprintf(tmpbuf, sizeof(tmpbuf), "Register dump [%d]: ", (int)NGREG); for(i = 0; i < NGREG; i++) { sappend(tmpbuf, sizeof(tmpbuf), "%016" PRIx64, uc->uc_mcontext.gregs[i]);