Skip to content
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

build: Enable fuzz binary in MSVC #29774

Merged
merged 6 commits into from Apr 28, 2024
Merged

Conversation

hebasto
Copy link
Member

@hebasto hebasto commented Mar 31, 2024

Closes #29760.

Suggested in #29758 (comment).

@DrahtBot
Copy link
Contributor

DrahtBot commented Mar 31, 2024

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

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK maflcko, sipsorcery, sipa

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #29868 (Reintroduce external signer support for Windows by hebasto)
  • #29494 (build: Assume HAVE_CONFIG_H, Add IWYU pragma keep to bitcoin-config.h includes by maflcko)
  • #28526 (Add 1-way SSE4 SHA256 implementation using intrinsics for MSVC builds by hebasto)

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
Copy link
Member Author

hebasto commented Mar 31, 2024

Friendly ping @sipa @maflcko @sipsorcery @dergoegge ;)

@sipa
Copy link
Member

sipa commented Mar 31, 2024

@hebasto What is the issue with the bitdeque and miniscript fuzz tests?

@hebasto
Copy link
Member Author

hebasto commented Mar 31, 2024

What is the issue with the bitdeque and miniscript fuzz tests?

Here is a branch with included bitdeque.cpp and the excerpt from its build log:

  bitdeque.cpp
D:\a\bitcoin\bitcoin\src\util\bitdeque.h(91,20): error C2248: 'bitdeque<128>::BITS_PER_WORD': cannot access private member declared in class 'bitdeque<128>' [D:\a\bitcoin\bitcoin\build_msvc\fuzz\fuzz.vcxproj]
  D:\a\bitcoin\bitcoin\src\util\bitdeque.h(28,26): note: see declaration of 'bitdeque<128>::BITS_PER_WORD'
  D:\a\bitcoin\bitcoin\src\test\fuzz\bitdeque.cpp(18,23): note: see declaration of 'bitdeque<128>'
  D:\a\bitcoin\bitcoin\src\util\bitdeque.h(91,20): note: the template instantiation context (the oldest one first) is
  D:\a\bitcoin\bitcoin\src\test\fuzz\bitdeque.cpp(215,17): note: see reference to class template instantiation 'bitdeque<128>::Iterator<true>' being compiled
  D:\a\bitcoin\bitcoin\src\util\bitdeque.h(89,32): note: while compiling class template member function 'bitdeque<128>::Iterator<true>::difference_type operator -(const bitdeque<128>::Iterator<true> &,const bitdeque<128>::Iterator<true> &)'
  D:\a\bitcoin\bitcoin\src\test\fuzz\bitdeque.cpp(215,17): note: see the first reference to 'operator -' in 'bitdeque_fuzz_target::<lambda_18>::operator ()'
D:\a\bitcoin\bitcoin\src\util\bitdeque.h(91,20): error C2248: 'bitdeque<128>::BITS_PER_WORD': cannot access private member declared in class 'bitdeque<128>' [D:\a\bitcoin\bitcoin\build_msvc\fuzz\fuzz.vcxproj]
  (compiling source file '../../src/test/fuzz/bitdeque.cpp')
  D:\a\bitcoin\bitcoin\src\util\bitdeque.h(28,26):
  see declaration of 'bitdeque<128>::BITS_PER_WORD'
  D:\a\bitcoin\bitcoin\src\test\fuzz\bitdeque.cpp(18,23):
  see declaration of 'bitdeque<128>'
  D:\a\bitcoin\bitcoin\src\util\bitdeque.h(91,20):
  the template instantiation context (the oldest one first) is
  	D:\a\bitcoin\bitcoin\src\test\fuzz\bitdeque.cpp(215,17):
  	see reference to class template instantiation 'bitdeque<128>::Iterator<true>' being compiled
  	D:\a\bitcoin\bitcoin\src\util\bitdeque.h(89,32):
  	while compiling class template member function 'bitdeque<128>::Iterator<true>::difference_type operator -(const bitdeque<128>::Iterator<true> &,const bitdeque<128>::Iterator<true> &)'
  		D:\a\bitcoin\bitcoin\src\test\fuzz\bitdeque.cpp(215,17):
  		see the first reference to 'operator -' in 'bitdeque_fuzz_target::<lambda_18>::operator ()'  

Here is a branch with included miniscript.cpp and the excerpt from its build log:

  miniscript.cpp
D:\a\bitcoin\bitcoin\src\script\miniscript.h(154,13): error C2248: 'miniscript::Type::Type': cannot access private member declared in class 'miniscript::Type' [D:\a\bitcoin\bitcoin\build_msvc\fuzz\fuzz.vcxproj]
  D:\a\bitcoin\bitcoin\src\script\miniscript.h(127,5): note: see declaration of 'miniscript::Type::Type'
  D:\a\bitcoin\bitcoin\src\script\miniscript.h(122,7): note: see declaration of 'miniscript::Type'
  D:\a\bitcoin\bitcoin\src\test\fuzz\miniscript.cpp(1226,53): note: while evaluating constexpr function 'miniscript::operator ""_mst'

@Richlilyjoy100
Copy link

Closes #29760.

Suggested in #29758 (comment).

Once this PR collects concept ACKs, I'm going to open dedicated PRs to fix portability issues in the code.

@sipa
Copy link
Member

sipa commented Apr 1, 2024

utACK 239d1d6

Nice, I'm surprised how few changes/disabling of tests were needed to make this work.

src/test/fuzz/fuzz.cpp Outdated Show resolved Hide resolved
src/test/fuzz/fuzz.cpp Outdated Show resolved Hide resolved
src/test/fuzz/fuzz.cpp Outdated Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
@sipsorcery
Copy link
Member

I get 14 compiler errors when building this PR with Visual Studio.

One example on line 282 of transaction_tests.cpp:

UniValue tests = read_json(json_tests::tx_invalid);

Gives compiler error of:

Error	C2664	'UniValue read_json(const std::string &)': 
cannot convert argument 1 from 'const unsigned char [53413]' to 'const std::string &'	
test_bitcoin	C:\dev\github\bitcoin\src\test\transaction_tests.cpp	282

It's easy enough to fix by casting the unsigned char[] to std::string but perhaps there's a deeper issue?

@hebasto
Copy link
Member Author

hebasto commented Apr 1, 2024

@sipsorcery

I get 14 compiler errors when building this PR with Visual Studio.

How does your setup differ from the one in the CI?

@dergoegge
Copy link
Member

One example on line 282 of transaction_tests.cpp:

I believe this is unrelated to this PR, see #29051. make clean and rebuilding should fix it.

@sipsorcery
Copy link
Member

I believe this is unrelated to this PR, see #29051. make clean and rebuilding should fix it.

I'm on Windows and using msvc but I did do a clean build but it didn't help.

I suspect it's down to msvc being less forgiving than gcc, probably due to a recent msvc change although I couldn't find anything in the release notes.

Apolgies for dumping a screenshot but it does show a succinct summary of the issue. This is from an attempt to compile (no linking involved) the single blockfilter_tests.cpp file.

image

@hebasto
Copy link
Member Author

hebasto commented Apr 6, 2024

@sipsorcery

I'm on Windows and using msvc but I did do a clean build but it didn't help.

What VS / MSVC versions do you use?

@hebasto
Copy link
Member Author

hebasto commented Apr 6, 2024

This is from an attempt to compile (no linking involved) the single blockfilter_tests.cpp file.

Does it compile on the master branch for you?

@sipsorcery
Copy link
Member

@sipsorcery

I'm on Windows and using msvc but I did do a clean build but it didn't help.

What VS / MSVC versions do you use?

Visual Studio (including msvc) updates get automatically pushed every couple of weeks. I'm generally always pretty close to the latest stable version.

Currently Visual Studio 2022 17.8.0

msbuild --version
MSBuild version 17.8.3+195e7f5a3 for .NET Framework
17.8.3.51904

@sipsorcery
Copy link
Member

This is from an attempt to compile (no linking involved) the single blockfilter_tests.cpp file.

Does it compile on the master branch for you?

No.

I only checked that after posting the compiler error message. The msvc compiler error isn't related to this PR, it's on master as well.

@hebasto
Copy link
Member Author

hebasto commented Apr 6, 2024

The msvc compiler error isn't related to this PR, it's on master as well.

Could you please open a separate issue then?

FWIW, I have no compile errors for the master branch @ b5d2118 using VS Community 2022 17.9.5. For example, the test_bitcoin.exe compiles for both Debug and Release configurations:

> msbuild --version
MSBuild version 17.9.8+b34f75857 for .NET Framework
17.9.8.16306
> py -3 build_msvc\msvc-autogen.py
> msbuild build_msvc\bitcoin.sln -p:UseMultiToolTask=true -p:Configuration=Debug -maxCpuCount -v:minimal -noLogo -t:test_bitcoin
> msbuild build_msvc\bitcoin.sln -p:UseMultiToolTask=true -p:Configuration=Release -maxCpuCount -v:minimal -noLogo -t:test_bitcoin

@hebasto
Copy link
Member Author

hebasto commented Apr 6, 2024

The branch has been reworked to address @maflcko's comments.

... but bool return value + exceptions doesn't make sense, does it?

Whether std::istream::read() throws or not depends on how exceptions() is set. The suggested code does not use exceptions.

fanquake added a commit that referenced this pull request Apr 9, 2024
47cedee fuzz: Introduce `BITCOINFUZZ` environment variable (Hennadii Stepanov)
1573e9a fuzz, refactor: Deduplicate fuzz binary path creation (Hennadii Stepanov)

Pull request description:

  These changes are split from #29774 and can be beneficial on their own.

  The new `BITCOINFUZZ` environment variable complements the already existing set of variables used by tests: https://github.com/bitcoin/bitcoin/blob/b5d21182e5a66110ce2796c2c99da39c8ebf0d72/test/functional/test_framework/test_framework.py#L238-L243

ACKs for top commit:
  maflcko:
    lgtm ACK 47cedee
  davidgumberg:
    utACK 47cedee

Tree-SHA512: 45809cfd13dc4a45c44cc433184352e84726cb95bea80fd8f581c59a0b8b0a5495260ff66922f9c57c38adbdbdd102439238f370fd49d6ea27a241a5e6249895
fanquake added a commit that referenced this pull request Apr 9, 2024
56e1e5d refactor, bench, fuzz: Drop unneeded `UCharCast` calls (Hennadii Stepanov)

Pull request description:

  The `CKey::Set()` template function handles `std::byte` just fine: https://github.com/bitcoin/bitcoin/blob/b5d21182e5a66110ce2796c2c99da39c8ebf0d72/src/key.h#L105

  Noticed in #29774 (comment).

ACKs for top commit:
  maflcko:
    lgtm ACK 56e1e5d
  laanwj:
    Seems fine, code review ACK 56e1e5d
  hernanmarino:
    ACK 56e1e5d

Tree-SHA512: 0f6b6e66692e70e083c7768aa4859c7db11aa034f555d19df0e5d33b18c0367ba1c886bcb6be3fdea78248a3cf8285576120812da55b995ef5e6c94a9dbd9f7c
@maflcko
Copy link
Member

maflcko commented Apr 18, 2024

I believe this is unrelated to this PR, see #29051. make clean and rebuilding should fix it.

I'm on Windows and using msvc but I did do a clean build but it didn't help.

Does it still happen after you clear the git repo carefully and start from scratch? git clean -dffx, or similar, but this will delete all non-git files, so be careful.

@hebasto
Copy link
Member Author

hebasto commented Apr 18, 2024

Addressed the recent @maflcko's comments.

@maflcko
Copy link
Member

maflcko commented Apr 18, 2024

Haven't reviewed anything in build_msvc

lgtm ACK 18fd522 🔍

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: lgtm ACK 18fd522ca9a74cf8690a6c9b9b729e78c6ed41fd 🔍
gNifTt5s+7OtYIlaXMdEJ3HLZ9C6g8ytDavFNfVc383QbognEyerTmREnewCCAQL5VnglQrDEpSetYJvM+yaAg==

@hebasto
Copy link
Member Author

hebasto commented Apr 18, 2024

@dergoegge @sipa @sipsorcery

Mind having another look into this PR?

@sipsorcery
Copy link
Member

tACK 09f5a74.

@hebasto
Copy link
Member Author

hebasto commented Apr 26, 2024

@sipsorcery

tACK 09f5a74.

Wrong commit hash?

:)

@sipsorcery
Copy link
Member

sipsorcery commented Apr 26, 2024

@sipsorcery

tACK 09f5a74.

Wrong commit hash?

:)

Every time :( I wish there were timestamps on the Github list. If only my old brain could remember to use git log next time.

tACK 18fd522

Copy link
Member

@sipa sipa left a comment

Choose a reason for hiding this comment

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

utACK 18fd522

@fanquake fanquake merged commit 3aaf732 into bitcoin:master Apr 28, 2024
16 checks passed
@hebasto hebasto deleted the 240331-msvc-fuzz branch April 28, 2024 05:23
@hebasto
Copy link
Member Author

hebasto commented Apr 28, 2024

What is the issue with the bitdeque and miniscript fuzz tests?

The #29983 resolves the issue with the former.

achow101 added a commit that referenced this pull request May 1, 2024
774359b build, msvc: Compile `test\fuzz\bitdeque.cpp` (Hennadii Stepanov)
85f50a4 refactor: Fix "error C2248: cannot access private member" on MSVC (Hennadii Stepanov)

Pull request description:

  This PR resolves one point from the #29774 (comment):
  > What is the issue with the bitdeque... ?

ACKs for top commit:
  maflcko:
    lgtm ACK 774359b
  sipa:
    utACK 774359b
  achow101:
    ACK 774359b
  dergoegge:
    utACK 774359b

Tree-SHA512: dba5c0217b915468af08475795437a10d8e8dedfadeb319f36d9b1bf54a91a8b2c61470a6047565855276c2bc8589c7776dc19237610b65b57cc841a303de8b3
@hebasto hebasto added the Windows label May 1, 2024
@hebasto
Copy link
Member Author

hebasto commented May 1, 2024

Ported to the CMake-based build system in hebasto#182.

@hebasto
Copy link
Member Author

hebasto commented May 3, 2024

@sipa

What is the issue with the ... miniscript fuzz tests?

The miniscript issue is resolved with your #28657 :)

hebasto added a commit to hebasto/bitcoin that referenced this pull request May 3, 2024
fc91bfe fixup! cmake: Add fuzzing options (Hennadii Stepanov)
5927338 fixup! cmake: Add platform-specific definitions and properties (Hennadii Stepanov)
dcf2e66 refactor: Make 64-bit shift explicit (Hennadii Stepanov)
a7edea8 refactor: Fix "error C2248: cannot access private member" on MSVC (Hennadii Stepanov)

Pull request description:

  This PR ports bitcoin#29774 after the recent sync/rebase [PR](#179).

  Also included changes from bitcoin#29983.

Top commit has no ACKs.

Tree-SHA512: 562919ec9b89401d193c6d59a8634f5086a1a063b6ee075c465c5dbc9bf59da4bb1eb7b826deac91f470e22fe9bf049b43b7106bdc66c5d26c715d68a1008f4d
fanquake added a commit that referenced this pull request May 6, 2024
9155b73 build, msvc: Compile test\fuzz\miniscript.cpp (Hennadii Stepanov)

Pull request description:

  This PR resolves the remained point from the #29774 (comment):
  > What is the issue with the ... miniscript fuzz tests?

  From the CI [log](https://github.com/bitcoin/bitcoin/actions/runs/8941546183/job/24562123707?pr=30031#step:29:234):
  ```
  miniscript_script: succeeded against 721 files in 1s.
  Run miniscript_script with args ['D:\\a\\bitcoin\\bitcoin\\src\\fuzz.exe', WindowsPath('D:/a/_temp/qa-assets/fuzz_seed_corpus/miniscript_script')]
  miniscript_smart: succeeded against 1429 files in 2s.
  Run miniscript_smart with args ['D:\\a\\bitcoin\\bitcoin\\src\\fuzz.exe', WindowsPath('D:/a/_temp/qa-assets/fuzz_seed_corpus/miniscript_smart')]
  miniscript_stable: succeeded against 1871 files in 2s.
  Run miniscript_stable with args ['D:\\a\\bitcoin\\bitcoin\\src\\fuzz.exe', WindowsPath('D:/a/_temp/qa-assets/fuzz_seed_corpus/miniscript_stable')]
  miniscript_string: succeeded against 918 files in 3s.
  Run miniscript_string with args ['D:\\a\\bitcoin\\bitcoin\\src\\fuzz.exe', WindowsPath('D:/a/_temp/qa-assets/fuzz_seed_corpus/miniscript_string')]
  ```

ACKs for top commit:
  maflcko:
    ACK 9155b73
  TheCharlatan:
    ACK 9155b73

Tree-SHA512: 967f199aac41733265532518ff7b1d881ba5a7bbde9f827d6a0b6d984c94a65b20d5854ce0ea247158eaa17b21d4c9f7d25c79bac17960788bacd2586112630b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

build: Enable Fuzz binary in MSVC
9 participants