contrib: embed C++11 patch in install_db4.sh #20665

pull gruve-p wants to merge 1 commits into bitcoin:master from gruve-p:master changing 1 files +149 −4
  1. gruve-p commented at 7:44 PM on December 15, 2020: contributor

    Move away from gist patch to an embedded patch in the script with a heredoc.

  2. in contrib/install_db4.sh:71 in f16db9c24f outdated
      67 | @@ -68,8 +68,8 @@ tar -xzvf ${BDB_VERSION}.tar.gz -C "$BDB_PREFIX"
      68 |  cd "${BDB_PREFIX}/${BDB_VERSION}/"
      69 |  
      70 |  # Apply a patch necessary when building with clang and c++11 (see https://community.oracle.com/thread/3952592)
      71 | -CLANG_CXX11_PATCH_URL='https://gist.githubusercontent.com/LnL7/5153b251fd525fe15de69b67e63a6075/raw/7778e9364679093a32dec2908656738e16b6bdcb/clang.patch'
      72 | -CLANG_CXX11_PATCH_HASH='7a9a47b03fd5fb93a16ef42235fa9512db9b0829cfc3bdf90edd3ec1f44d637c'
      73 | +CLANG_CXX11_PATCH_URL='https://raw.githubusercontent.com/bitcoin/bitcoin/master/depends/patches/bdb/clang_cxx_11.patch'
    


    laanwj commented at 7:59 PM on December 15, 2020:

    if it's in the same repository, does it need a download at all?


    gruve-p commented at 10:54 AM on December 16, 2020:

    I see this script as a standalone script which installs libdb4.8 (Berkeley DB) without the need to be in the root of the bitcoin repository. One can just grab this script and run it anywhere on the machine, export BDB_PREFIX and then use the right parameters (BDB_LIBS= and BDB_CFLAGS) on configure


    laanwj commented at 3:52 PM on December 16, 2020:

    Yes, good point. Well I guess it could at least try finding the local patch, and resort to download if it doesn't exist.


    alevchuk commented at 6:21 PM on December 19, 2020:

    There is convenience for running curl from anywhere, yet are there other tradeoffs in depending on githubusercontent.com?


    laanwj commented at 11:46 AM on December 20, 2020:

    Possibly an even better solution: embed the patch in the script, with a heredoc.

    It's more maintenance work when the patch needs to change (say, for compatibility with new compilers), but it is a small patch after all and it keeps the script more self-contained.


    MarcoFalke commented at 12:03 PM on December 20, 2020:

    Good idea. Also, this script will probably go in one or two major releases when we no longer require bdb


    gruve-p commented at 12:11 PM on January 6, 2021:

    Implemented your idea @laanwj I used my mobile to make the changes so the changes are untested.

  3. laanwj added the label Build system on Dec 15, 2020
  4. laanwj commented at 3:59 PM on December 16, 2020: member

    <details> <summary>Diff between old and new patch</summary>

    --- clang.patch	2020-12-16 16:55:03.987104506 +0100
    +++ clang_cxx_11.patch	2020-12-16 16:54:47.747154861 +0100
    @@ -1,7 +1,13 @@
    -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
    +commit 3311d68f11d1697565401eee6efc85c34f022ea7
    +Author: fanquake <fanquake@gmail.com>
    +Date:   Mon Aug 17 20:03:56 2020 +0800
    +
    +    Fix C++11 compatibility
    +
    +diff --git a/dbinc/atomic.h b/dbinc/atomic.h
    +index 0034dcc..7c11d4a 100644
    +--- a/dbinc/atomic.h
    ++++ b/dbinc/atomic.h
     @@ -70,7 +70,7 @@ typedef struct {
       * These have no memory barriers; the caller must include them when necessary.
       */
    @@ -38,11 +44,11 @@
      #else
      #define atomic_inc(env, p)	__atomic_inc(env, p)
      #define atomic_dec(env, p)	__atomic_dec(env, p)
    -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. */
    +diff --git a/mp/mp_fget.c b/mp/mp_fget.c
    +index 5fdee5a..0b75f57 100644
    +--- a/mp/mp_fget.c
    ++++ b/mp/mp_fget.c
    +@@ -617,7 +617,7 @@ alloc:		/* Allocate a new buffer header and data space. */
      
      		/* Initialize enough so we can call __memp_bhfree. */
      		alloc_bhp->flags = 0;
    @@ -50,9 +56,9 @@
     +		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,
    + 			__db_errx(env,
    +@@ -911,7 +911,7 @@ alloc:		/* Allocate a new buffer header and data space. */
    + 			MVCC_MPROTECT(bhp->buf, mfp->stat.st_pagesize,
      			    PROT_READ);
      
     -		atomic_init(&alloc_bhp->ref, 1);
    @@ -60,10 +66,10 @@
      		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
    +diff --git a/mp/mp_mvcc.c b/mp/mp_mvcc.c
    +index 34467d2..f05aa0c 100644
    +--- a/mp/mp_mvcc.c
    ++++ b/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));
    @@ -82,11 +88,11 @@
      		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)
    +diff --git a/mp/mp_region.c b/mp/mp_region.c
    +index e6cece9..ddbe906 100644
    +--- a/mp/mp_region.c
    ++++ b/mp/mp_region.c
    +@@ -224,7 +224,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);
    @@ -95,20 +101,20 @@
      		}
      
      		/*
    -@@ -302,7 +302,7 @@ no_prealloc:
    - 		} else
    - 			hp->mtx_hash = mtx_base + (i % dbenv->mp_mtxcount);
    +@@ -269,7 +269,7 @@ __memp_init(env, dbmp, reginfo_off, htab_buckets, max_nreg)
    + 		hp->mtx_hash = (mtx_base == MUTEX_INVALID) ? MUTEX_INVALID :
    + 		    mtx_base + i;
      		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)
    +diff --git a/mutex/mut_method.c b/mutex/mut_method.c
    +index 2588763..5c6d516 100644
    +--- a/mutex/mut_method.c
    ++++ b/mutex/mut_method.c
    +@@ -426,7 +426,7 @@ atomic_compare_exchange(env, v, oldval, newval)
      	MUTEX_LOCK(env, mtx);
      	ret = atomic_read(v) == oldval;
      	if (ret)
    @@ -117,11 +123,11 @@
      	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)
    +diff --git a/mutex/mut_tas.c b/mutex/mut_tas.c
    +index f3922e0..e40fcdf 100644
    +--- a/mutex/mut_tas.c
    ++++ b/mutex/mut_tas.c
    +@@ -46,7 +46,7 @@ __db_tas_mutex_init(env, mutex, flags)
      
      #ifdef HAVE_SHARED_LATCHES
      	if (F_ISSET(mutexp, DB_MUTEX_SHARED))
    @@ -130,7 +136,7 @@
      	else
      #endif
      	if (MUTEX_INIT(&mutexp->tas)) {
    -@@ -536,7 +536,7 @@ __db_tas_mutex_unlock(env, mutex)
    +@@ -486,7 +486,7 @@ __db_tas_mutex_unlock(env, mutex)
      			F_CLR(mutexp, DB_MUTEX_LOCKED);
      			/* Flush flag update before zeroing count */
      			MEMBAR_EXIT();
    @@ -138,4 +144,4 @@
     +			atomic_init_db(&mutexp->sharecount, 0);
      		} else {
      			DB_ASSERT(env, sharecount > 0);
    - 			MEMBAR_EXIT();
    \ No newline at end of file
    + 			MEMBAR_EXIT();
    

    </details>

  5. gruve-p renamed this:
    Build: update clang patch url and hash
    Build: update clang patch to use heredoc
    on Jan 6, 2021
  6. felipsoarez commented at 5:02 PM on January 6, 2021: none

    Concept ACK

  7. richardsonmark316 changes_requested
  8. richardsonmark316 commented at 8:55 PM on January 7, 2021: none

  9. fanquake commented at 7:38 AM on January 10, 2021: member

    @gruve-p can you squash your commits.

  10. gruve-p closed this on Jan 10, 2021

  11. gruve-p commented at 11:15 AM on January 10, 2021: contributor

    @fanquake Squashed

  12. Build: update clang patch to use heredoc c490dbc0f2
  13. gruve-p reopened this on Jan 10, 2021

  14. gruve-p commented at 11:33 AM on January 10, 2021: contributor

    Ready for rereview @laanwj

  15. fanquake commented at 5:58 AM on January 11, 2021: member

    When I asked you to squash I'd assumed you'd actually tested that this works. I've checked that this produces the same libdb_cxx-4.8.a & libdb-4.8.a, however, as is, the patch wont apply:

    CFLAGS="-Wno-error=implicit-function-declaration" ./contrib/install_db4.sh $(pwd)
    ...
    x db-4.8.30.NC/txn/txn_stat.c
    x db-4.8.30.NC/txn/txn_util.c
    can't find file to patch at input line 11
    Perhaps you used the wrong -p or --strip option?
    The text leading up to this was:
    --------------------------
    |commit 3311d68f11d1697565401eee6efc85c34f022ea7
    |Author: fanquake <fanquake@gmail.com>
    |Date:   Mon Aug 17 20:03:56 2020 +0800
    |
    |    Fix C++11 compatibility
    |
    |diff --git a/dbinc/atomic.h b/dbinc/atomic.h
    |index 0034dcc..7c11d4a 100644
    |--- a/dbinc/atomic.h
    |+++ b/dbinc/atomic.h
    --------------------------
    File to patch:
    

    You'll need to fix the paths, something like:

    diff --git a/contrib/install_db4.sh b/contrib/install_db4.sh
    index 0a022229e..3c88de16e 100755
    --- a/contrib/install_db4.sh
    +++ b/contrib/install_db4.sh
    @@ -75,10 +75,10 @@ Date:   Mon Aug 17 20:03:56 2020 +0800
     
         Fix C++11 compatibility
     
    -diff --git a/dbinc/atomic.h b/dbinc/atomic.h
    +diff --git a/src/dbinc/atomic.h b/src/dbinc/atomic.h
     index 0034dcc..7c11d4a 100644
    ---- a/dbinc/atomic.h
    -+++ b/dbinc/atomic.h
    +--- 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.
       */
    @@ -115,10 +115,10 @@ index 0034dcc..7c11d4a 100644
      #else
      #define atomic_inc(env, p)	__atomic_inc(env, p)
      #define atomic_dec(env, p)	__atomic_dec(env, p)
    -diff --git a/mp/mp_fget.c b/mp/mp_fget.c
    +diff --git a/src/mp/mp_fget.c b/src/mp/mp_fget.c
     index 5fdee5a..0b75f57 100644
    ---- a/mp/mp_fget.c
    -+++ b/mp/mp_fget.c
    +--- a/src/mp/mp_fget.c
    ++++ b/src/mp/mp_fget.c
     @@ -617,7 +617,7 @@ alloc:		/* Allocate a new buffer header and data space. */
     
      		/* Initialize enough so we can call __memp_bhfree. */
    @@ -137,10 +137,10 @@ index 5fdee5a..0b75f57 100644
      		MUTEX_LOCK(env, alloc_bhp->mtx_buf);
      		alloc_bhp->priority = bhp->priority;
      		alloc_bhp->pgno = bhp->pgno;
    -diff --git a/mp/mp_mvcc.c b/mp/mp_mvcc.c
    +diff --git a/src/mp/mp_mvcc.c b/src/mp/mp_mvcc.c
     index 34467d2..f05aa0c 100644
    ---- a/mp/mp_mvcc.c
    -+++ b/mp/mp_mvcc.c
    +--- 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));
    @@ -159,10 +159,10 @@ index 34467d2..f05aa0c 100644
      		F_CLR(alloc_bhp, BH_FROZEN);
      	}
     
    -diff --git a/mp/mp_region.c b/mp/mp_region.c
    +diff --git a/src/mp/mp_region.c b/src/mp/mp_region.c
     index e6cece9..ddbe906 100644
    ---- a/mp/mp_region.c
    -+++ b/mp/mp_region.c
    +--- a/src/mp/mp_region.c
    ++++ b/src/mp/mp_region.c
     @@ -224,7 +224,7 @@ __memp_init(env, dbmp, reginfo_off, htab_buckets, max_nreg)
      			     MTX_MPOOL_FILE_BUCKET, 0, &htab[i].mtx_hash)) != 0)
      				return (ret);
    @@ -181,10 +181,10 @@ index e6cece9..ddbe906 100644
      #ifdef HAVE_STATISTICS
      		hp->hash_io_wait = 0;
      		hp->hash_frozen = hp->hash_thawed = hp->hash_frozen_freed = 0;
    -diff --git a/mutex/mut_method.c b/mutex/mut_method.c
    +diff --git a/src/mutex/mut_method.c b/src/mutex/mut_method.c
     index 2588763..5c6d516 100644
    ---- a/mutex/mut_method.c
    -+++ b/mutex/mut_method.c
    +--- a/src/mutex/mut_method.c
    ++++ b/src/mutex/mut_method.c
     @@ -426,7 +426,7 @@ atomic_compare_exchange(env, v, oldval, newval)
      	MUTEX_LOCK(env, mtx);
      	ret = atomic_read(v) == oldval;
    @@ -194,10 +194,10 @@ index 2588763..5c6d516 100644
      	MUTEX_UNLOCK(env, mtx);
     
      	return (ret);
    -diff --git a/mutex/mut_tas.c b/mutex/mut_tas.c
    +diff --git a/src/mutex/mut_tas.c b/src/mutex/mut_tas.c
     index f3922e0..e40fcdf 100644
    ---- a/mutex/mut_tas.c
    -+++ b/mutex/mut_tas.c
    +--- a/src/mutex/mut_tas.c
    ++++ b/src/mutex/mut_tas.c
     @@ -46,7 +46,7 @@ __db_tas_mutex_init(env, mutex, flags)
     
      #ifdef HAVE_SHARED_LATCHES
    

    Once you're done fixing the changes, make sure you've squashed to a single commit, and write a more meaningful commit message, i.e: "contrib: embed C++11 patch in install_db4.sh" & explain why it's being done.

    Also, in future, please don't open new PRs for the same change.

  16. gruve-p closed this on Jan 11, 2021

  17. gruve-p renamed this:
    Build: update clang patch to use heredoc
    contrib: embed C++11 patch in install_db4.sh
    on Jan 11, 2021
  18. gruve-p commented at 9:41 AM on January 11, 2021: contributor

    @fanquake Fixed, squashed, changed commit message, force pushed then the PR closed again. Can you reopen it?

  19. fanquake commented at 1:15 PM on January 11, 2021: member

    It's no longer possible to reopen this PR, probably because you force pushed to the branch while the PR was closed, so you will actually have to open another now.

  20. gruve-p commented at 5:56 PM on January 11, 2021: contributor

    New one opened

  21. laanwj referenced this in commit dd545c53a5 on Jan 19, 2021
  22. sidhujag referenced this in commit 599774e599 on Jan 20, 2021
  23. DrahtBot locked this on Aug 16, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-23 00:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me