-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
db: fix build on Darwin and clang 16 #241178
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
diff -ur a/dist/aclocal/mutex.m4 b/dist/aclocal/mutex.m4 | ||
--- a/dist/aclocal/mutex.m4 1969-12-31 19:00:01.000000000 -0500 | ||
+++ b/dist/aclocal/mutex.m4 2023-06-05 19:14:47.214158196 -0400 | ||
@@ -372,10 +376,11 @@ | ||
|
||
# _spin_lock_try/_spin_unlock: Apple/Darwin | ||
if test "$db_cv_mutex" = no; then | ||
-AC_TRY_LINK(,[ | ||
- int x; | ||
- _spin_lock_try(&x); | ||
- _spin_unlock(&x); | ||
+AC_TRY_LINK([ | ||
+#include <os/lock.h>],[ | ||
+ os_unfair_lock x = OS_UNFAIR_LOCK_INIT; | ||
+ bool _ = os_unfair_lock_trylock(&x); | ||
+ os_unfair_lock_unlock(&x); | ||
], [db_cv_mutex=Darwin/_spin_lock_try]) | ||
fi | ||
|
||
diff -ur a/dbinc/mutex_int.h b/dbinc/mutex_int.h | ||
--- a/dbinc/mutex_int.h 1969-12-31 19:00:01.000000000 -0500 | ||
+++ b/dbinc/mutex_int.h 2023-06-05 19:15:37.510514745 -0400 | ||
@@ -154,14 +154,13 @@ | ||
* Apple/Darwin library functions. | ||
*********************************************************************/ | ||
#ifdef HAVE_MUTEX_DARWIN_SPIN_LOCK_TRY | ||
-typedef u_int32_t tsl_t; | ||
+#include <os/lock.h> | ||
+typedef os_unfair_lock tsl_t; | ||
|
||
#ifdef LOAD_ACTUAL_MUTEX_CODE | ||
-extern int _spin_lock_try(tsl_t *); | ||
-extern void _spin_unlock(tsl_t *); | ||
-#define MUTEX_SET(tsl) _spin_lock_try(tsl) | ||
-#define MUTEX_UNSET(tsl) _spin_unlock(tsl) | ||
-#define MUTEX_INIT(tsl) (MUTEX_UNSET(tsl), 0) | ||
+#define MUTEX_SET(tsl) os_unfair_lock_trylock(tsl) | ||
+#define MUTEX_UNSET(tsl) os_unfair_lock_unlock(tsl) | ||
+#define MUTEX_INIT(tsl) ({ *(tsl) = OS_UNFAIR_LOCK_INIT; tsl; }) | ||
#endif | ||
#endif | ||
|
||
diff -ur a/dbinc/mutex_int.h b/dbinc/mutex_int.h | ||
--- a/dbinc_auto/mutex_ext.h 1969-12-31 19:00:01.000000000 -0500 | ||
+++ b/dbinc_auto/mutex_ext.h 2023-07-01 22:38:20.749201366 -0400 | ||
@@ -34,6 +34,9 @@ | ||
#if !defined(HAVE_ATOMIC_SUPPORT) && defined(HAVE_MUTEX_SUPPORT) | ||
atomic_value_t __atomic_dec __P((ENV *, db_atomic_t *)); | ||
#endif | ||
+#if !defined(HAVE_ATOMIC_SUPPORT) && defined(HAVE_MUTEX_SUPPORT) | ||
+int atomic_compare_exchange __P((ENV *, db_atomic_t *, atomic_value_t, atomic_value_t)); | ||
+#endif | ||
int __db_pthread_mutex_init __P((ENV *, db_mutex_t, u_int32_t)); | ||
int __db_pthread_mutex_lock __P((ENV *, db_mutex_t)); | ||
#if defined(HAVE_SHARED_LATCHES) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
diff -ur a/dist/aclocal/mutex.m4 b/dist/aclocal/mutex.m4 | ||
--- a/dist/aclocal/mutex.m4 1969-12-31 19:00:01.000000000 -0500 | ||
+++ b/dist/aclocal/mutex.m4 2023-06-05 19:14:47.214158196 -0400 | ||
@@ -441,10 +445,11 @@ | ||
|
||
# _spin_lock_try/_spin_unlock: Apple/Darwin | ||
if test "$db_cv_mutex" = no; then | ||
-AC_TRY_LINK(,[ | ||
- int x; | ||
- _spin_lock_try(&x); | ||
- _spin_unlock(&x); | ||
+AC_TRY_LINK([ | ||
+#include <os/lock.h>],[ | ||
+ os_unfair_lock x = OS_UNFAIR_LOCK_INIT; | ||
+ bool _ = os_unfair_lock_trylock(&x); | ||
+ os_unfair_lock_unlock(&x); | ||
], [db_cv_mutex=Darwin/_spin_lock_try]) | ||
fi | ||
|
||
diff -ur a/src/dbinc/mutex_int.h b/src/dbinc/mutex_int.h | ||
--- a/src/dbinc/mutex_int.h 1969-12-31 19:00:01.000000000 -0500 | ||
+++ b/src/dbinc/mutex_int.h 2023-06-05 19:15:37.510514745 -0400 | ||
@@ -154,14 +154,13 @@ | ||
* Apple/Darwin library functions. | ||
*********************************************************************/ | ||
#ifdef HAVE_MUTEX_DARWIN_SPIN_LOCK_TRY | ||
-typedef u_int32_t tsl_t; | ||
+#include <os/lock.h> | ||
+typedef os_unfair_lock tsl_t; | ||
|
||
#ifdef LOAD_ACTUAL_MUTEX_CODE | ||
-extern int _spin_lock_try(tsl_t *); | ||
-extern void _spin_unlock(tsl_t *); | ||
-#define MUTEX_SET(tsl) _spin_lock_try(tsl) | ||
-#define MUTEX_UNSET(tsl) _spin_unlock(tsl) | ||
-#define MUTEX_INIT(tsl) (MUTEX_UNSET(tsl), 0) | ||
+#define MUTEX_SET(tsl) os_unfair_lock_trylock(tsl) | ||
+#define MUTEX_UNSET(tsl) os_unfair_lock_unlock(tsl) | ||
+#define MUTEX_INIT(tsl) ({ *(tsl) = OS_UNFAIR_LOCK_INIT; tsl; }) | ||
#endif | ||
#endif | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
{ lib, stdenv, fetchurl, ... } @ args: | ||
{ lib, stdenv, fetchurl, autoreconfHook, ... } @ args: | ||
|
||
import ./generic.nix (args // { | ||
version = "5.3.28"; | ||
sha256 = "0a1n5hbl7027fbz5lm0vp0zzfp1hmxnz14wx3zl9563h83br5ag0"; | ||
extraPatches = [ ./clang-5.3.patch ./CVE-2017-10140-cwd-db_config.patch ]; | ||
extraPatches = [ ./clang-5.3.patch ./CVE-2017-10140-cwd-db_config.patch ] | ||
++ lib.optionals stdenv.isDarwin [ ./darwin-mutexes.patch ]; | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
{ lib, stdenv, fetchurl, ... } @ args: | ||
{ lib, stdenv, fetchurl, autoreconfHook, ... } @ args: | ||
|
||
import ./generic.nix (args // { | ||
version = "6.0.20"; | ||
sha256 = "00r2aaglq625y8r9xd5vw2y070plp88f1mb2gbq3kqsl7128lsl0"; | ||
license = lib.licenses.agpl3; | ||
extraPatches = [ ./clang-6.0.patch ./CVE-2017-10140-cwd-db_config.patch ]; | ||
extraPatches = [ ./clang-6.0.patch ./CVE-2017-10140-cwd-db_config.patch ] | ||
++ lib.optionals stdenv.isDarwin [ ./darwin-mutexes.patch ]; | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
{ lib, stdenv, fetchurl, ... } @ args: | ||
{ lib, stdenv, fetchurl, autoreconfHook, ... } @ args: | ||
|
||
import ./generic.nix (args // { | ||
version = "6.2.23"; | ||
sha256 = "1isxx4jfmnh913jzhp8hhfngbk6dsg46f4kjpvvc56maj64jqqa7"; | ||
license = lib.licenses.agpl3; | ||
extraPatches = [ ./clang-6.0.patch ./CVE-2017-10140-cwd-db_config.patch ]; | ||
extraPatches = [ ./clang-6.0.patch ./CVE-2017-10140-cwd-db_config.patch ] | ||
++ lib.optionals stdenv.isDarwin [ ./darwin-mutexes.patch ]; | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ lib, stdenv, fetchurl | ||
{ lib, stdenv, fetchurl, autoreconfHook | ||
, cxxSupport ? true | ||
, compat185 ? true | ||
, dbmSupport ? false | ||
|
@@ -10,6 +10,9 @@ | |
, drvArgs ? {} | ||
}: | ||
|
||
let | ||
shouldReconfigure = stdenv.cc.isClang; | ||
in | ||
stdenv.mkDerivation (rec { | ||
pname = "db"; | ||
inherit version; | ||
|
@@ -19,10 +22,48 @@ stdenv.mkDerivation (rec { | |
sha256 = sha256; | ||
}; | ||
|
||
# The provided configure script features `main` returning implicit `int`, which causes | ||
# configure checks to work incorrectly with clang 16. | ||
nativeBuildInputs = lib.optionals stdenv.cc.isClang [ autoreconfHook ]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't we just reconfigure on all platforms? It would make things more uniform and bugs would be easier to spot on linux. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can see if it works on Linux and open a PR to make it unconditional if there are no issues. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would be awesome! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I opened #242060 to make them unconditional. |
||
|
||
patches = extraPatches; | ||
|
||
outputs = [ "bin" "out" "dev" ]; | ||
|
||
# Required when regenerated the configure script to make sure the vendored macros are found. | ||
autoreconfFlags = lib.optionalString shouldReconfigure [ "-fi" "-Iaclocal" "-Iaclocal_java" ]; | ||
|
||
preAutoreconf = lib.optionalString shouldReconfigure '' | ||
pushd dist | ||
# Upstream’s `dist/s_config` cats everything into `aclocal.m4`, but that doesn’t work with | ||
# autoreconfHook, so cat `config.m4` to another file. Otherwise, it won’t be found by `aclocal`. | ||
cat aclocal/config.m4 >> aclocal/options.m4 | ||
''; | ||
|
||
# This isn’t pretty. The version information is kept separate from the configure script. | ||
# After the configure script is regenerated, the version information has to be replaced with the | ||
# contents of `dist/RELEASE`. | ||
postAutoreconf = lib.optionalString shouldReconfigure '' | ||
( | ||
declare -a vars=( | ||
"DB_VERSION_FAMILY" | ||
"DB_VERSION_RELEASE" | ||
"DB_VERSION_MAJOR" | ||
"DB_VERSION_MINOR" | ||
"DB_VERSION_PATCH" | ||
"DB_VERSION_STRING" | ||
"DB_VERSION_FULL_STRING" | ||
"DB_VERSION_UNIQUE_NAME" | ||
"DB_VERSION" | ||
) | ||
source RELEASE | ||
for var in "''${vars[@]}"; do | ||
sed -e "s/__EDIT_''${var}__/''${!var}/g" -i configure | ||
done | ||
) | ||
popd | ||
''; | ||
|
||
configureFlags = | ||
[ | ||
(if cxxSupport then "--enable-cxx" else "--disable-cxx") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't make the patch unconditional?