Skip to content

Commit

Permalink
depends: Fix issue cross-compiling BDB to Windows with Clang 12
Browse files Browse the repository at this point in the history
  • Loading branch information
str4d committed Jul 30, 2021
1 parent d9bcc2d commit 18e39ff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion depends/packages/bdb.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ $(package)_download_path=https://download.oracle.com/berkeley-db
$(package)_file_name=db-$($(package)_version).tar.gz
$(package)_sha256_hash=47612c8991aa9ac2f6be721267c8d3cdccf5ac83105df8e50809daea24e95dc7
$(package)_build_subdir=build_unix
$(package)_patches=winioctl-and-atomic_init_db.patch
$(package)_patches=clang-12-stpcpy-issue.diff winioctl-and-atomic_init_db.patch

ifneq ($(host_os),darwin)
$(package)_dependencies=libcxx
Expand All @@ -30,6 +30,7 @@ endif
endef

define $(package)_preprocess_cmds
patch -p1 <$($(package)_patch_dir)/clang-12-stpcpy-issue.diff && \
patch -p1 <$($(package)_patch_dir)/winioctl-and-atomic_init_db.patch
endef

Expand Down
25 changes: 25 additions & 0 deletions depends/patches/bdb/clang-12-stpcpy-issue.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
diff -ur db-6.2.23-orig/src/blob/blob_util.c db-6.2.23/src/blob/blob_util.c
--- db-6.2.23-orig/src/blob/blob_util.c 2016-03-28 20:45:53.000000000 +0100
+++ db-6.2.23/src/blob/blob_util.c 2021-07-30 18:07:29.942811600 +0100
@@ -544,7 +544,20 @@
goto err;

memset(path, 0, len);
- name_len += sprintf(path, "%s", blob_sub_dir);
+ // name_len += sprintf(path, "%s", blob_sub_dir);
+ {
+ // Clang 12 introduced an "libcall optimization" that lowers the above
+ // to stpcpy to avoid the machinery involved in parsing format strings.
+ // This causes build problems when cross-compiling to Windows with the
+ // version of mingw-w64 that Zcash supports. We haven't figured out why
+ // but in the meantime we replace this with an inlined stpcpy impl from
+ // https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=5934637641c863cc2c1765a0d01c5b6f53ecc4fc
+ char *dest = path;
+ const char *src = blob_sub_dir;
+ while ((*dest++ = *src++) != '\0')
+ /* nothing */;
+ name_len += (--dest - path);
+ }

__blob_calculate_dirs(blob_id, path, &name_len, &depth);

0 comments on commit 18e39ff

Please sign in to comment.