Skip to content

test: Add case for libstdc++ bug on Windows - #36620

Closed
hebasto wants to merge 1 commit into
bitcoin:masterfrom
hebasto:261023-win-libstdcxx
Closed

hebasto wants to merge 1 commit into
bitcoin:masterfrom
hebasto:261023-win-libstdcxx

Conversation

@hebasto

@hebasto hebasto commented Oct 23, 2026

Copy link
Copy Markdown
Member

The code in BerkeleyRODatabase::Backup() relies on copy_file() with overwrite_existing working.

Upstream fixes:

Suggested in #36271 (comment).

Here is an example of the failure when cross-compiling for Windows using GCC 14.2.0:

./test/fs_tests.cpp(145): Entering test case "copy_file_overwrite_existing"
unknown location(0): fatal error: in "fs_tests/copy_file_overwrite_existing": std::filesystem::__cxx11::filesystem_error: filesystem error: cannot copy file: File exists [C:\Users\RUNNER~1\AppData\Local\Temp\test_common bitcoin\fs_tests\copy_file_overwrite_existing\c72b38273c1f6fce4336\a] [C:\Users\RUNNER~1\AppData\Local\Temp\test_common bitcoin\fs_tests\copy_file_overwrite_existing\c72b38273c1f6fce4336\b]
./test/fs_tests.cpp(155): last checkpoint

@hebasto hebasto added the Tests label Oct 23, 2026
@DrahtBot

DrahtBot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36677 (util: Make files opened with fdbridge::fopen noninheritable by SirECMG)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@hebasto

hebasto commented Oct 23, 2026

Copy link
Copy Markdown
Member Author

Here is an example of the failure when cross-compiling for Windows using GCC 14.2.0...

This can be done, for instance, with the following patch:

--- a/contrib/devtools/shell-win64-cross.nix
+++ b/contrib/devtools/shell-win64-cross.nix
@@ -16,9 +16,18 @@ let
   });
   toolchain = crossPkgs.stdenv.cc.targetPrefix;
   pthreads = crossPkgs.windows.pthreads;
+  gccVersion = "14.2.0";
   crossGcc = crossPkgs.buildPackages.gcc14;
-  gcc = crossGcc.override {
+  gcc = (crossGcc.override {
     cc = crossGcc.cc.overrideAttrs (old: {
+      version = gccVersion;
+      name = builtins.replaceStrings [ old.version ] [ gccVersion ] old.name;
+      postPatch = builtins.replaceStrings [ old.version ] [ gccVersion ] old.postPatch;
+      configureFlags = map (builtins.replaceStrings [ old.version ] [ gccVersion ]) old.configureFlags;
+      src = pkgs.fetchurl {
+        url = "mirror://gcc/releases/gcc-${gccVersion}/gcc-${gccVersion}.tar.xz";
+        sha256 = "a7b39bc69cbf9e25826c5a60ab26477001f7c08d85cec04bc0e29cabed6f3cc9";
+      };
       # Keep target pthread headers out of GCC's native build tools.
       env = old.env // {
         EXTRA_FLAGS_FOR_TARGET =
@@ -28,7 +37,9 @@ let
       };
     });
     extraPackages = [ pthreads ];
-  };
+  }).overrideAttrs (_: {
+    version = gccVersion;
+  });
 in
 
 pkgs.mkShellNoCC {

@maflcko

maflcko commented Oct 23, 2026

Copy link
Copy Markdown
Member

Could address the Ralph comment?

@fanquake

Copy link
Copy Markdown
Member

Can you elaborate on the motivation here? Why this bug specifically? Which users (compiling in what currently used environments) do we expect to hit this?

@hebasto

hebasto commented Oct 23, 2026

Copy link
Copy Markdown
Member Author

Can you elaborate on the motivation here? Why this bug specifically? Which users (compiling in what currently used environments) do we expect to hit this?

Even after #36042, users can hit this bug in a build environment we don’t control (e.g. a distro’s g++-mingw-w64-ucrt64 package) that formally meets our minimum requirements but ships an affected libstdc++.

@maflcko

maflcko commented Oct 23, 2026

Copy link
Copy Markdown
Member

Seems harmless to add the test. An alternative could be to reject g++-mingw less than 14.3 during configure?

The code in `BerkeleyRODatabase::Backup()` relies on `copy_file()` with
`overwrite_existing` working.

Upstream fixes:
- gcc-mirror/gcc@017e3f8
- gcc-mirror/gcc@35c9814
- gcc-mirror/gcc@8b3e47b
@hebasto

hebasto commented Oct 23, 2026

Copy link
Copy Markdown
Member Author

Could address the Ralph comment?

Done.

@fanquake

fanquake commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Even after #36042, users can hit this bug in a build environment we don’t control

Thanks:

Why this bug specifically?"
"Which users (compiling in what currently used environments) do we expect to hit this?" ?

It's not clear that adding a test here is that useful, unless you expect cross-compiling end-users are running the unit test binary on their systems before running bitcoind? Otherwise, as mentioned above, maybe it'd be better to reject the compiler outright.

It's also not clear what runtime failure / bug the user would be prevented from hitting (by seeing this test failure) if they happened to be using a broken compiler. If I understand correctly, does this mean that migration has likely never worked on windows with GCC-based cross-compiled binaries, but also nobody has ever reported it?

There are lots of compiler bugs, and we don't add tests for many of them, and the PR description / commit messages here don't really justify the changes, or explain how a user would be affected by this at runtime, if they used a broken compiler.

Comment thread src/test/fs_tests.cpp
fs::remove(path2);
}

// Catches a libstdc++ bug on Windows (fixed in GCC 13.4/14.3/15.1, never

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(fixed in GCC 13.4 ... never in 12.x)

One other point here is that we have been shipping Windows release binaries (28.0 with 12.4.0 & 29.0/30.0 with 13.3.0), which should have this bug. 30.0 is still supported, so if this is serious enough to warrant a unit test now, shouldn't we be patching the compiler/libstdc++ in Guix and doing a point release with the fix?

@hebasto

hebasto commented Oct 23, 2026

Copy link
Copy Markdown
Member Author

I have to admit that I can’t see a real-life scenario in which the bug affects users.

The code is reachable only when migrating a legacy BDB wallet, either via the migratewallet RPC command or via the GUI.

The dest argument of BerkeleyRODatabase::Backup() is constructed in MigrateLegacyToDescriptor() and includes a timestamp. If a migration attempt fails for any reason, the next attempt is very likely to write a differently named file. However, the bug can only be hit if the backup file has the same name.

@theuni

theuni commented Oct 23, 2026

Copy link
Copy Markdown
Member

It seems to me this is either:

  • A compiler config not worth worrying about
  • A compiler config worth explicitly blocking as suggested by @maflcko
  • A compiler config we're worried about, in which case we could just remove the copy_options param from copy_file so that we can't hit this anywhere else.

Either way, adding a test that fails where we expect it to fail doesn't seem very helpful to me.

@hebasto

hebasto commented Oct 24, 2026

Copy link
Copy Markdown
Member Author

... we could just remove the copy_options param from copy_file so that we can't hit this anywhere else.

@achow101

Could we?

@maflcko

maflcko commented Oct 26, 2026

Copy link
Copy Markdown
Member

Could we?

It seems like a bugfix, because migration shouldn't overwrite?

@fanquake

Copy link
Copy Markdown
Member

What's the status here? Looks like there's not agreement to add the test, and no interest in fixing the release binaries, so maybe a new pull can be opened for a wallet refactor? Or something can be done following #34193?

@hebasto hebasto closed this Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants