From 88ea78745a92a23fe0d8f4098ff5f990c6a7fac2 Mon Sep 17 00:00:00 2001 From: Will Dietz Date: Sat, 24 Mar 2018 12:27:17 -0500 Subject: [PATCH 1/2] libbsd: apply upstream patch to fix w/musl --- pkgs/development/libraries/libbsd/default.nix | 5 +- .../libraries/libbsd/non-glibc.patch | 74 +++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 pkgs/development/libraries/libbsd/non-glibc.patch diff --git a/pkgs/development/libraries/libbsd/default.nix b/pkgs/development/libraries/libbsd/default.nix index 0e232a50e943..52d038e3d6b2 100644 --- a/pkgs/development/libraries/libbsd/default.nix +++ b/pkgs/development/libraries/libbsd/default.nix @@ -13,7 +13,10 @@ stdenv.mkDerivation rec { # the configure scripts nativeBuildInputs = [ autoreconfHook ]; - patches = stdenv.lib.optionals stdenv.isDarwin [ ./darwin.patch ]; + patches = stdenv.lib.optional stdenv.isDarwin ./darwin.patch + # Suitable for all, but limited to musl to avoid rebuilds + # https://cgit.freedesktop.org/libbsd/patch/?id=1f8a3f7bccfc84b195218ad0086ebd57049c3490 + ++ stdenv.lib.optional stdenv.hostPlatform.isMusl ./non-glibc.patch; meta = with stdenv.lib; { description = "Common functions found on BSD systems"; diff --git a/pkgs/development/libraries/libbsd/non-glibc.patch b/pkgs/development/libraries/libbsd/non-glibc.patch new file mode 100644 index 000000000000..f61e0d242943 --- /dev/null +++ b/pkgs/development/libraries/libbsd/non-glibc.patch @@ -0,0 +1,74 @@ +From 1f8a3f7bccfc84b195218ad0086ebd57049c3490 Mon Sep 17 00:00:00 2001 +From: Guillem Jover +Date: Tue, 6 Mar 2018 01:39:45 +0100 +Subject: Fix function declaration protection for glibc already providing them +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +On non-glibc based systems we cannot unconditionally use the +__GLIBC_PREREQ macro as it gets expanded before evaluation. Instead, +if it is undefined, define it to 0. + +We should also always declare these functions on non-glibc based +systems. And on systems with a new enough glibc, which provides these +functions, we should still provide the declarations if _GNU_SOURCE +is *not* defined. + +Reported-by: Jörg Krause +--- + include/bsd/stdlib.h | 3 ++- + include/bsd/string.h | 3 ++- + include/bsd/sys/cdefs.h | 8 ++++++++ + 3 files changed, 12 insertions(+), 2 deletions(-) + +diff --git a/include/bsd/stdlib.h b/include/bsd/stdlib.h +index 8d33d1f..a5b063c 100644 +--- a/include/bsd/stdlib.h ++++ b/include/bsd/stdlib.h +@@ -71,7 +71,8 @@ int sradixsort(const unsigned char **base, int nmemb, + const unsigned char *table, unsigned endbyte); + + void *reallocf(void *ptr, size_t size); +-#if defined(_GNU_SOURCE) && defined(__GLIBC__) && !__GLIBC_PREREQ(2, 26) ++#if !defined(__GLIBC__) || \ ++ (defined(__GLIBC__) && (!__GLIBC_PREREQ(2, 26) || !defined(_GNU_SOURCE))) + void *reallocarray(void *ptr, size_t nmemb, size_t size); + #endif + +diff --git a/include/bsd/string.h b/include/bsd/string.h +index 29097f6..f987fee 100644 +--- a/include/bsd/string.h ++++ b/include/bsd/string.h +@@ -46,7 +46,8 @@ size_t strlcat(char *dst, const char *src, size_t siz); + char *strnstr(const char *str, const char *find, size_t str_len); + void strmode(mode_t mode, char *str); + +-#if defined(_GNU_SOURCE) && defined(__GLIBC__) && !__GLIBC_PREREQ(2, 25) ++#if !defined(__GLIBC__) || \ ++ (defined(__GLIBC__) && (!__GLIBC_PREREQ(2, 25) || !defined(_GNU_SOURCE))) + void explicit_bzero(void *buf, size_t len); + #endif + __END_DECLS +diff --git a/include/bsd/sys/cdefs.h b/include/bsd/sys/cdefs.h +index b4c8f30..d1cc419 100644 +--- a/include/bsd/sys/cdefs.h ++++ b/include/bsd/sys/cdefs.h +@@ -59,6 +59,14 @@ + #endif + + /* ++ * On non-glibc based systems, we cannot unconditionally use the ++ * __GLIBC_PREREQ macro as it gets expanded before evaluation. ++ */ ++#ifndef __GLIBC_PREREQ ++#define __GLIBC_PREREQ(maj, min) 0 ++#endif ++ ++/* + * Some kFreeBSD headers expect those macros to be set for sanity checks. + */ + #ifndef _SYS_CDEFS_H_ +-- +cgit v1.1 + From 969499f3e293ed899f5fdaf39b28537aab913460 Mon Sep 17 00:00:00 2001 From: Will Dietz Date: Sat, 24 Mar 2018 12:34:51 -0500 Subject: [PATCH 2/2] libbsd: more upstream patches --- pkgs/development/libraries/libbsd/cdefs.patch | 222 ++++++++++++++++++ pkgs/development/libraries/libbsd/default.nix | 10 +- .../libraries/libbsd/features.patch | 26 ++ 3 files changed, 256 insertions(+), 2 deletions(-) create mode 100644 pkgs/development/libraries/libbsd/cdefs.patch create mode 100644 pkgs/development/libraries/libbsd/features.patch diff --git a/pkgs/development/libraries/libbsd/cdefs.patch b/pkgs/development/libraries/libbsd/cdefs.patch new file mode 100644 index 000000000000..81822654aeb4 --- /dev/null +++ b/pkgs/development/libraries/libbsd/cdefs.patch @@ -0,0 +1,222 @@ +From 11ec8f1e5dfa1c10e0c9fb94879b6f5b96ba52dd Mon Sep 17 00:00:00 2001 +From: Guillem Jover +Date: Tue, 6 Mar 2018 01:41:35 +0100 +Subject: Handle systems missing + +This is a non-portable header, and we cannot expect it to be provided by +the system libc (e.g. musl). We just need and rely on declaration that +we have defined ourselves in our own . So we switch to +only ever assume that. + +Fixes: https://bugs.freedesktop.org/105281 +--- + include/bsd/libutil.h | 4 ++++ + include/bsd/md5.h | 4 ++++ + include/bsd/nlist.h | 4 ++++ + include/bsd/readpassphrase.h | 4 ++++ + include/bsd/stdlib.h | 4 ++++ + include/bsd/string.h | 4 ++++ + include/bsd/stringlist.h | 5 +++++ + include/bsd/sys/queue.h | 4 ++++ + include/bsd/sys/tree.h | 4 ++++ + include/bsd/timeconv.h | 4 ++++ + include/bsd/vis.h | 4 ++++ + include/bsd/wchar.h | 4 ++++ + 12 files changed, 49 insertions(+) + +diff --git a/include/bsd/libutil.h b/include/bsd/libutil.h +index 45b3b15..ccca29a 100644 +--- a/include/bsd/libutil.h ++++ b/include/bsd/libutil.h +@@ -40,7 +40,11 @@ + #define LIBBSD_LIBUTIL_H + + #include ++#ifdef LIBBSD_OVERLAY + #include ++#else ++#include ++#endif + #include + #include + #include +diff --git a/include/bsd/md5.h b/include/bsd/md5.h +index 5f3ae46..bf36a30 100644 +--- a/include/bsd/md5.h ++++ b/include/bsd/md5.h +@@ -27,7 +27,11 @@ typedef struct MD5Context { + uint8_t buffer[MD5_BLOCK_LENGTH]; /* input buffer */ + } MD5_CTX; + ++#ifdef LIBBSD_OVERLAY + #include ++#else ++#include ++#endif + #include + + __BEGIN_DECLS +diff --git a/include/bsd/nlist.h b/include/bsd/nlist.h +index cb297e8..8767117 100644 +--- a/include/bsd/nlist.h ++++ b/include/bsd/nlist.h +@@ -27,7 +27,11 @@ + #ifndef LIBBSD_NLIST_H + #define LIBBSD_NLIST_H + ++#ifdef LIBBSD_OVERLAY + #include ++#else ++#include ++#endif + + struct nlist { + union { +diff --git a/include/bsd/readpassphrase.h b/include/bsd/readpassphrase.h +index 14744b8..5eb8021 100644 +--- a/include/bsd/readpassphrase.h ++++ b/include/bsd/readpassphrase.h +@@ -31,7 +31,11 @@ + #define RPP_SEVENBIT 0x10 /* Strip the high bit from input. */ + #define RPP_STDIN 0x20 /* Read from stdin, not /dev/tty */ + ++#ifdef LIBBSD_OVERLAY + #include ++#else ++#include ++#endif + #include + + __BEGIN_DECLS +diff --git a/include/bsd/stdlib.h b/include/bsd/stdlib.h +index ebc9638..8d33d1f 100644 +--- a/include/bsd/stdlib.h ++++ b/include/bsd/stdlib.h +@@ -42,7 +42,11 @@ + #ifndef LIBBSD_STDLIB_H + #define LIBBSD_STDLIB_H + ++#ifdef LIBBSD_OVERLAY + #include ++#else ++#include ++#endif + #include + #include + +diff --git a/include/bsd/string.h b/include/bsd/string.h +index 6798bf6..29097f6 100644 +--- a/include/bsd/string.h ++++ b/include/bsd/string.h +@@ -33,7 +33,11 @@ + #ifndef LIBBSD_STRING_H + #define LIBBSD_STRING_H + ++#ifdef LIBBSD_OVERLAY + #include ++#else ++#include ++#endif + #include + + __BEGIN_DECLS +diff --git a/include/bsd/stringlist.h b/include/bsd/stringlist.h +index ff30cac..dd71496 100644 +--- a/include/bsd/stringlist.h ++++ b/include/bsd/stringlist.h +@@ -31,7 +31,12 @@ + + #ifndef LIBBSD_STRINGLIST_H + #define LIBBSD_STRINGLIST_H ++ ++#ifdef LIBBSD_OVERLAY + #include ++#else ++#include ++#endif + #include + + /* +diff --git a/include/bsd/sys/queue.h b/include/bsd/sys/queue.h +index 4a94ea7..ac00026 100644 +--- a/include/bsd/sys/queue.h ++++ b/include/bsd/sys/queue.h +@@ -33,7 +33,11 @@ + #ifndef LIBBSD_SYS_QUEUE_H + #define LIBBSD_SYS_QUEUE_H + ++#ifdef LIBBSD_OVERLAY + #include ++#else ++#include ++#endif + + /* + * This file defines four types of data structures: singly-linked lists, +diff --git a/include/bsd/sys/tree.h b/include/bsd/sys/tree.h +index 628bec0..325b382 100644 +--- a/include/bsd/sys/tree.h ++++ b/include/bsd/sys/tree.h +@@ -30,7 +30,11 @@ + #ifndef LIBBSD_SYS_TREE_H + #define LIBBSD_SYS_TREE_H + ++#ifdef LIBBSD_OVERLAY + #include ++#else ++#include ++#endif + + /* + * This file defines data structures for different types of trees: +diff --git a/include/bsd/timeconv.h b/include/bsd/timeconv.h +index e2a2c55..a426bd3 100644 +--- a/include/bsd/timeconv.h ++++ b/include/bsd/timeconv.h +@@ -41,7 +41,11 @@ + #ifndef LIBBSD_TIMECONV_H + #define LIBBSD_TIMECONV_H + ++#ifdef LIBBSD_OVERLAY + #include ++#else ++#include ++#endif + #include + #include + +diff --git a/include/bsd/vis.h b/include/bsd/vis.h +index 970dfdd..ab5430c 100644 +--- a/include/bsd/vis.h ++++ b/include/bsd/vis.h +@@ -72,7 +72,11 @@ + */ + #define UNVIS_END 1 /* no more characters */ + ++#ifdef LIBBSD_OVERLAY + #include ++#else ++#include ++#endif + + __BEGIN_DECLS + char *vis(char *, int, int, int); +diff --git a/include/bsd/wchar.h b/include/bsd/wchar.h +index 33a500e..7216503 100644 +--- a/include/bsd/wchar.h ++++ b/include/bsd/wchar.h +@@ -40,7 +40,11 @@ + #define LIBBSD_WCHAR_H + + #include ++#ifdef LIBBSD_OVERLAY + #include ++#else ++#include ++#endif + #include + + __BEGIN_DECLS +-- +cgit v1.1 + diff --git a/pkgs/development/libraries/libbsd/default.nix b/pkgs/development/libraries/libbsd/default.nix index 52d038e3d6b2..ff9412ceb580 100644 --- a/pkgs/development/libraries/libbsd/default.nix +++ b/pkgs/development/libraries/libbsd/default.nix @@ -15,8 +15,14 @@ stdenv.mkDerivation rec { patches = stdenv.lib.optional stdenv.isDarwin ./darwin.patch # Suitable for all, but limited to musl to avoid rebuilds - # https://cgit.freedesktop.org/libbsd/patch/?id=1f8a3f7bccfc84b195218ad0086ebd57049c3490 - ++ stdenv.lib.optional stdenv.hostPlatform.isMusl ./non-glibc.patch; + ++ stdenv.lib.optionals stdenv.hostPlatform.isMusl [ + # https://cgit.freedesktop.org/libbsd/commit/?id=1f8a3f7bccfc84b195218ad0086ebd57049c3490 + ./non-glibc.patch + # https://cgit.freedesktop.org/libbsd/commit/?id=11ec8f1e5dfa1c10e0c9fb94879b6f5b96ba52dd + ./cdefs.patch + # https://cgit.freedesktop.org/libbsd/commit/?id=b20272f5a966333b49fdf2bda797e2a9f0227404 + ./features.patch + ]; meta = with stdenv.lib; { description = "Common functions found on BSD systems"; diff --git a/pkgs/development/libraries/libbsd/features.patch b/pkgs/development/libraries/libbsd/features.patch new file mode 100644 index 000000000000..66bd1e9232ba --- /dev/null +++ b/pkgs/development/libraries/libbsd/features.patch @@ -0,0 +1,26 @@ +From b20272f5a966333b49fdf2bda797e2a9f0227404 Mon Sep 17 00:00:00 2001 +From: Guillem Jover +Date: Tue, 6 Mar 2018 01:42:52 +0100 +Subject: Remove inclusion from + +This is a non-portable header, and we should not assume it is present. +Let the first system header pull it in if needed. +--- + include/bsd/libutil.h | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/include/bsd/libutil.h b/include/bsd/libutil.h +index ccca29a..e5f148a 100644 +--- a/include/bsd/libutil.h ++++ b/include/bsd/libutil.h +@@ -39,7 +39,6 @@ + #ifndef LIBBSD_LIBUTIL_H + #define LIBBSD_LIBUTIL_H + +-#include + #ifdef LIBBSD_OVERLAY + #include + #else +-- +cgit v1.1 +