From 7e933af17344c049cdb13bffeafdb82f0927f3bc Mon Sep 17 00:00:00 2001 From: Daiderd Jordan Date: Sat, 12 Nov 2016 17:14:20 +0100 Subject: [PATCH] db: fix build with libc++-3.8 --- pkgs/development/libraries/db/clang-4.8.patch | 22 --- pkgs/development/libraries/db/clang-5.3.patch | 154 ------------------ .../development/libraries/db/cygwin-4.4.patch | 21 --- .../development/libraries/db/cygwin-4.5.patch | 22 --- pkgs/development/libraries/db/db-4.8.nix | 20 ++- pkgs/development/libraries/db/db-5.3.nix | 4 - pkgs/development/libraries/db/generic.nix | 18 ++ .../libraries/db/register-race-fix.patch | 47 ------ 8 files changed, 37 insertions(+), 271 deletions(-) delete mode 100644 pkgs/development/libraries/db/clang-4.8.patch delete mode 100644 pkgs/development/libraries/db/clang-5.3.patch delete mode 100644 pkgs/development/libraries/db/cygwin-4.4.patch delete mode 100644 pkgs/development/libraries/db/cygwin-4.5.patch delete mode 100644 pkgs/development/libraries/db/register-race-fix.patch diff --git a/pkgs/development/libraries/db/clang-4.8.patch b/pkgs/development/libraries/db/clang-4.8.patch deleted file mode 100644 index c53160a82970..000000000000 --- a/pkgs/development/libraries/db/clang-4.8.patch +++ /dev/null @@ -1,22 +0,0 @@ -diff --git a/dbinc/atomic.h b/dbinc/atomic.h -index 0034dcc..fa7ba93 100644 ---- a/dbinc/atomic.h -+++ b/dbinc/atomic.h -@@ -144,7 +144,7 @@ typedef LONG volatile *interlocked_val; - #define atomic_inc(env, p) __atomic_inc(p) - #define atomic_dec(env, p) __atomic_dec(p) - #define atomic_compare_exchange(env, p, o, n) \ -- __atomic_compare_exchange((p), (o), (n)) -+ __db_atomic_compare_exchange((p), (o), (n)) - static inline int __atomic_inc(db_atomic_t *p) - { - int temp; -@@ -176,7 +176,7 @@ static inline int __atomic_dec(db_atomic_t *p) - * http://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Atomic-Builtins.html - * which configure could be changed to use. - */ --static inline int __atomic_compare_exchange( -+static inline int __db_atomic_compare_exchange( - db_atomic_t *p, atomic_value_t oldval, atomic_value_t newval) - { - atomic_value_t was; diff --git a/pkgs/development/libraries/db/clang-5.3.patch b/pkgs/development/libraries/db/clang-5.3.patch deleted file mode 100644 index 0a0993da13e1..000000000000 --- a/pkgs/development/libraries/db/clang-5.3.patch +++ /dev/null @@ -1,154 +0,0 @@ -diff --git a/src/dbinc/atomic.h b/src/dbinc/atomic.h -index 6a858f7..9f338dc 100644 ---- a/src/dbinc/atomic.h -+++ b/src/dbinc/atomic.h -@@ -70,7 +70,7 @@ typedef struct { - * These have no memory barriers; the caller must include them when necessary. - */ - #define atomic_read(p) ((p)->value) --#define atomic_init(p, val) ((p)->value = (val)) -+#define atomic_init_db(p, val) ((p)->value = (val)) - - #ifdef HAVE_ATOMIC_SUPPORT - -@@ -144,7 +144,7 @@ typedef LONG volatile *interlocked_val; - #define atomic_inc(env, p) __atomic_inc(p) - #define atomic_dec(env, p) __atomic_dec(p) - #define atomic_compare_exchange(env, p, o, n) \ -- __atomic_compare_exchange((p), (o), (n)) -+ __atomic_compare_exchange_db((p), (o), (n)) - static inline int __atomic_inc(db_atomic_t *p) - { - int temp; -@@ -176,7 +176,7 @@ static inline int __atomic_dec(db_atomic_t *p) - * http://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Atomic-Builtins.html - * which configure could be changed to use. - */ --static inline int __atomic_compare_exchange( -+static inline int __atomic_compare_exchange_db( - db_atomic_t *p, atomic_value_t oldval, atomic_value_t newval) - { - atomic_value_t was; -@@ -206,7 +206,7 @@ static inline int __atomic_compare_exchange( - #define atomic_dec(env, p) (--(p)->value) - #define atomic_compare_exchange(env, p, oldval, newval) \ - (DB_ASSERT(env, atomic_read(p) == (oldval)), \ -- atomic_init(p, (newval)), 1) -+ atomic_init_db(p, (newval)), 1) - #else - #define atomic_inc(env, p) __atomic_inc(env, p) - #define atomic_dec(env, p) __atomic_dec(env, p) -diff --git a/src/dbinc/db.in b/src/dbinc/db.in -index 92ac822..f80428e 100644 ---- a/src/dbinc/db.in -+++ b/src/dbinc/db.in -@@ -2782,7 +2782,7 @@ typedef struct { - #define fetch(a) __db_dbm_fetch@DB_VERSION_UNIQUE_NAME@(a) - #define firstkey __db_dbm_firstkey@DB_VERSION_UNIQUE_NAME@ - #define nextkey(a) __db_dbm_nextkey@DB_VERSION_UNIQUE_NAME@(a) --#define store(a, b) __db_dbm_store@DB_VERSION_UNIQUE_NAME@(a, b) -+#define store_db(a, b) __db_dbm_store@DB_VERSION_UNIQUE_NAME@(a, b) - - /******************************************************* - * Hsearch historic interface. -diff --git a/src/mp/mp_fget.c b/src/mp/mp_fget.c -index 16de695..d0dcc29 100644 ---- a/src/mp/mp_fget.c -+++ b/src/mp/mp_fget.c -@@ -649,7 +649,7 @@ alloc: /* Allocate a new buffer header and data space. */ - - /* Initialize enough so we can call __memp_bhfree. */ - alloc_bhp->flags = 0; -- atomic_init(&alloc_bhp->ref, 1); -+ atomic_init_db(&alloc_bhp->ref, 1); - #ifdef DIAGNOSTIC - if ((uintptr_t)alloc_bhp->buf & (sizeof(size_t) - 1)) { - __db_errx(env, DB_STR("3025", -@@ -955,7 +955,7 @@ alloc: /* Allocate a new buffer header and data space. */ - MVCC_MPROTECT(bhp->buf, mfp->pagesize, - PROT_READ); - -- atomic_init(&alloc_bhp->ref, 1); -+ atomic_init_db(&alloc_bhp->ref, 1); - MUTEX_LOCK(env, alloc_bhp->mtx_buf); - alloc_bhp->priority = bhp->priority; - alloc_bhp->pgno = bhp->pgno; -diff --git a/src/mp/mp_mvcc.c b/src/mp/mp_mvcc.c -index 770bad8..e28cce0 100644 ---- a/src/mp/mp_mvcc.c -+++ b/src/mp/mp_mvcc.c -@@ -276,7 +276,7 @@ __memp_bh_freeze(dbmp, infop, hp, bhp, need_frozenp) - #else - memcpy(frozen_bhp, bhp, SSZA(BH, buf)); - #endif -- atomic_init(&frozen_bhp->ref, 0); -+ atomic_init_db(&frozen_bhp->ref, 0); - if (mutex != MUTEX_INVALID) - frozen_bhp->mtx_buf = mutex; - else if ((ret = __mutex_alloc(env, MTX_MPOOL_BH, -@@ -428,7 +428,7 @@ __memp_bh_thaw(dbmp, infop, hp, frozen_bhp, alloc_bhp) - #endif - alloc_bhp->mtx_buf = mutex; - MUTEX_LOCK(env, alloc_bhp->mtx_buf); -- atomic_init(&alloc_bhp->ref, 1); -+ atomic_init_db(&alloc_bhp->ref, 1); - F_CLR(alloc_bhp, BH_FROZEN); - } - -diff --git a/src/mp/mp_region.c b/src/mp/mp_region.c -index 4952030..47645f8 100644 ---- a/src/mp/mp_region.c -+++ b/src/mp/mp_region.c -@@ -245,7 +245,7 @@ __memp_init(env, dbmp, reginfo_off, htab_buckets, max_nreg) - MTX_MPOOL_FILE_BUCKET, 0, &htab[i].mtx_hash)) != 0) - return (ret); - SH_TAILQ_INIT(&htab[i].hash_bucket); -- atomic_init(&htab[i].hash_page_dirty, 0); -+ atomic_init_db(&htab[i].hash_page_dirty, 0); - } - - /* -@@ -302,7 +302,7 @@ no_prealloc: - } else - hp->mtx_hash = mtx_base + (i % dbenv->mp_mtxcount); - SH_TAILQ_INIT(&hp->hash_bucket); -- atomic_init(&hp->hash_page_dirty, 0); -+ atomic_init_db(&hp->hash_page_dirty, 0); - #ifdef HAVE_STATISTICS - hp->hash_io_wait = 0; - hp->hash_frozen = hp->hash_thawed = hp->hash_frozen_freed = 0; -diff --git a/src/mutex/mut_method.c b/src/mutex/mut_method.c -index 09353b0..177353c 100644 ---- a/src/mutex/mut_method.c -+++ b/src/mutex/mut_method.c -@@ -474,7 +474,7 @@ atomic_compare_exchange(env, v, oldval, newval) - MUTEX_LOCK(env, mtx); - ret = atomic_read(v) == oldval; - if (ret) -- atomic_init(v, newval); -+ atomic_init_db(v, newval); - MUTEX_UNLOCK(env, mtx); - - return (ret); -diff --git a/src/mutex/mut_tas.c b/src/mutex/mut_tas.c -index 106b161..fc4de9d 100644 ---- a/src/mutex/mut_tas.c -+++ b/src/mutex/mut_tas.c -@@ -47,7 +47,7 @@ __db_tas_mutex_init(env, mutex, flags) - - #ifdef HAVE_SHARED_LATCHES - if (F_ISSET(mutexp, DB_MUTEX_SHARED)) -- atomic_init(&mutexp->sharecount, 0); -+ atomic_init_db(&mutexp->sharecount, 0); - else - #endif - if (MUTEX_INIT(&mutexp->tas)) { -@@ -536,7 +536,7 @@ __db_tas_mutex_unlock(env, mutex) - F_CLR(mutexp, DB_MUTEX_LOCKED); - /* Flush flag update before zeroing count */ - MEMBAR_EXIT(); -- atomic_init(&mutexp->sharecount, 0); -+ atomic_init_db(&mutexp->sharecount, 0); - } else { - DB_ASSERT(env, sharecount > 0); - MEMBAR_EXIT(); diff --git a/pkgs/development/libraries/db/cygwin-4.4.patch b/pkgs/development/libraries/db/cygwin-4.4.patch deleted file mode 100644 index 3f9d658b5dac..000000000000 --- a/pkgs/development/libraries/db/cygwin-4.4.patch +++ /dev/null @@ -1,21 +0,0 @@ -diff -rc db-4.4.20.NC-old/os/os_flock.c db-4.4.20.NC/os/os_flock.c -*** db-4.4.20.NC-old/os/os_flock.c Mon Jun 20 16:59:01 2005 ---- db-4.4.20.NC/os/os_flock.c Wed Jun 7 17:01:49 2006 -*************** -*** 36,41 **** ---- 36,50 ---- - - DB_ASSERT(F_ISSET(fhp, DB_FH_OPENED) && fhp->fd != -1); - -+ #ifdef __CYGWIN__ -+ /* -+ * Windows file locking interferes with read/write operations, so we -+ * map the ranges to an area past the end of the file. -+ */ -+ DB_ASSERT(offset < (off_t) 1 << 62); -+ offset += (off_t) 1 << 62; -+ #endif -+ - #ifdef HAVE_FCNTL - fl.l_start = offset; - fl.l_len = 1; diff --git a/pkgs/development/libraries/db/cygwin-4.5.patch b/pkgs/development/libraries/db/cygwin-4.5.patch deleted file mode 100644 index 3f0ee78a7085..000000000000 --- a/pkgs/development/libraries/db/cygwin-4.5.patch +++ /dev/null @@ -1,22 +0,0 @@ -diff -rc db-4.5.20-orig/os/os_flock.c db-4.5.20/os/os_flock.c -*** db-4.5.20-orig/os/os_flock.c 2006-10-13 12:36:12.000000000 +0200 ---- db-4.5.20/os/os_flock.c 2006-10-13 12:40:11.000000000 +0200 -*************** -*** 30,35 **** ---- 30,44 ---- - - DB_ASSERT(dbenv, F_ISSET(fhp, DB_FH_OPENED) && fhp->fd != -1); - -+ #ifdef __CYGWIN__ -+ /* -+ * Windows file locking interferes with read/write operations, so we -+ * map the ranges to an area past the end of the file. -+ */ -+ DB_ASSERT(dbenv, offset < (off_t) 1 << 62); -+ offset += (off_t) 1 << 62; -+ #endif -+ - fl.l_start = offset; - fl.l_len = 1; - fl.l_type = acquire ? F_WRLCK : F_UNLCK; -Only in db-4.5.20/os: os_flock.c~ diff --git a/pkgs/development/libraries/db/db-4.8.nix b/pkgs/development/libraries/db/db-4.8.nix index 40869a865ae5..f631a032102e 100644 --- a/pkgs/development/libraries/db/db-4.8.nix +++ b/pkgs/development/libraries/db/db-4.8.nix @@ -5,5 +5,23 @@ import ./generic.nix (args // rec { extraPatches = [ ./clang-4.8.patch ]; sha256 = "0ampbl2f0hb1nix195kz1syrqqxpmvnvnfvphambj7xjrl3iljg0"; branch = "4.8"; - drvArgs = { hardeningDisable = [ "format" ]; }; + drvArgs.hardeningDisable = [ "format" ]; + + # https://community.oracle.com/thread/3952592 + # this patch renames some sybols that conflict with libc++-3.8 + # symbols: atomic_compare_exchange, atomic_init, store + drvArgs.prePatch = '' + substituteInPlace dbinc/db.in \ + --replace '#define store' '#define store_db' + + substituteInPlace dbinc/atomic.h \ + --replace atomic_compare_exchange atomic_compare_exchange_db \ + --replace atomic_init atomic_init_db + substituteInPlace mp/*.c \ + --replace atomic_compare_exchange atomic_compare_exchange_db \ + --replace atomic_init atomic_init_db + substituteInPlace mutex/*.c \ + --replace atomic_compare_exchange atomic_compare_exchange_db \ + --replace atomic_init atomic_init_db + ''; }) diff --git a/pkgs/development/libraries/db/db-5.3.nix b/pkgs/development/libraries/db/db-5.3.nix index 91adfa24b58d..e22532594438 100644 --- a/pkgs/development/libraries/db/db-5.3.nix +++ b/pkgs/development/libraries/db/db-5.3.nix @@ -4,8 +4,4 @@ import ./generic.nix (args // rec { version = "5.3.28"; sha256 = "0a1n5hbl7027fbz5lm0vp0zzfp1hmxnz14wx3zl9563h83br5ag0"; branch = "5.3"; - # https://community.oracle.com/thread/3952592 - # this patch renames some sybols that conflict with libc++-3.8 - # symbols: atomic_compare_exchange, atomic_init, store - extraPatches = [ ./clang-5.3.patch ]; }) diff --git a/pkgs/development/libraries/db/generic.nix b/pkgs/development/libraries/db/generic.nix index fdc828effdfb..8e3eb5248e9e 100644 --- a/pkgs/development/libraries/db/generic.nix +++ b/pkgs/development/libraries/db/generic.nix @@ -20,6 +20,24 @@ stdenv.mkDerivation (rec { patches = extraPatches; + # https://community.oracle.com/thread/3952592 + # this patch renames some sybols that conflict with libc++-3.8 + # symbols: atomic_compare_exchange, atomic_init, store + prePatch = '' + substituteInPlace src/dbinc/db.in \ + --replace '#define store' '#define store_db' + + substituteInPlace src/dbinc/atomic.h \ + --replace atomic_compare_exchange atomic_compare_exchange_db \ + --replace atomic_init atomic_init_db + substituteInPlace src/mp/*.c \ + --replace atomic_compare_exchange atomic_compare_exchange_db \ + --replace atomic_init atomic_init_db + substituteInPlace src/mutex/*.c \ + --replace atomic_compare_exchange atomic_compare_exchange_db \ + --replace atomic_init atomic_init_db + ''; + configureFlags = [ (if cxxSupport then "--enable-cxx" else "--disable-cxx") (if compat185 then "--enable-compat185" else "--disable-compat185") diff --git a/pkgs/development/libraries/db/register-race-fix.patch b/pkgs/development/libraries/db/register-race-fix.patch deleted file mode 100644 index bb05c966e5bd..000000000000 --- a/pkgs/development/libraries/db/register-race-fix.patch +++ /dev/null @@ -1,47 +0,0 @@ -diff -rc db-4.5.20-orig/env/env_register.c db-4.5.20/env/env_register.c -*** db-4.5.20-orig/env/env_register.c 2006-09-09 16:29:04.000000000 +0200 ---- db-4.5.20/env/env_register.c 2007-05-16 21:13:27.000000000 +0200 -*************** -*** 255,260 **** ---- 255,262 ---- - buf[nr - 1] = '\0'; - } - -+ //sleep(3); -+ - pos = (off_t)lcnt * PID_LEN; - if (REGISTRY_LOCK(dbenv, pos, 1) == 0) { - if ((ret = REGISTRY_UNLOCK(dbenv, pos)) != 0) -*************** -*** 361,366 **** ---- 363,392 ---- - if (recovery_failed) - goto err; - -+ //sleep(5); -+ -+ /* -+ * Acquire an exclusive lock to prevent a race like this: -+ * -+ * 1) Process X is about to exit and process Y is just -+ * starting. -+ * 2) Process Y reads X's slot. -+ * 3) Process X clears its slot. -+ * 4) Process Y sees that X's slot isn't cleared yet (since it -+ * just read the old value). -+ * 5) Process X closes the registry, releases the lock on its -+ * slot. -+ * 6) Process Y tries to acquire X's slot and succeeds, so it -+ * concludes that X died and recovery is needed. -+ * -+ * A more efficient solution to this problem would be to let -+ * __envreg_add acquire the lock on a slot first, and *then* -+ * read the slot (instead of the other way around). Then we -+ * wouldn't need the exclusive lock here. -+ */ -+ if ((ret = REGISTRY_EXCL_LOCK(dbenv, 0)) != 0) -+ goto err; -+ - /* - * Why isn't an exclusive lock necessary to discard a DB_ENV handle? - *