Skip to content

[WIP] ci: test valgrind build from source - #136

Closed
fanquake wants to merge 1 commit into
bitcoin-core:mainfrom
fanquake:valgrind_from_source
Closed

fanquake wants to merge 1 commit into
bitcoin-core:mainfrom
fanquake:valgrind_from_source

Conversation

@fanquake

Copy link
Copy Markdown
Member

No description provided.

@fanquake

Copy link
Copy Markdown
Member Author

Looks like this is running faster. i.e, comparing a recent PR run:

Run base_encode_decode with args ['valgrind', '--quiet', '--error-exitcode=1', '/tmp/cirrus-build/bitcoin-core/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/src/test/fuzz/fuzz', '-runs=1', PosixPath('/tmp/cirrus-build/bitcoin-core/ci/scratch/qa-assets/fuzz_seed_corpus/base_encode_decode')]INFO: Running with entropic power schedule (0xFF, 100).
INFO: Seed: 3272178655
INFO: Loaded 1 modules   (248538 inline 8-bit counters): 248538 [0x27fd278, 0x2839d52), 
INFO: Loaded 1 PC tables (248538 PCs): 248538 [0x2839d58,0x2c04af8), 
INFO:     7233 files found in /tmp/cirrus-build/bitcoin-core/ci/scratch/qa-assets/fuzz_seed_corpus/base_encode_decode
INFO: -max_len is not provided; libFuzzer will not generate inputs larger than 1048576 bytes
INFO: seed corpus: files: 7233 min: 1b max: 1048576b total: 83751368b rss: 180Mb
#128	pulse  cov: 815 ft: 1562 corp: 56/240b exec/s: 64 rss: 183Mb
#256	pulse  cov: 1016 ft: 1941 corp: 96/697b exec/s: 64 rss: 206Mb
#512	pulse  cov: 1411 ft: 2848 corp: 137/1524b exec/s: 73 rss: 218Mb
#1024	pulse  cov: 2596 ft: 7733 corp: 274/10217b exec/s: 37 rss: 237Mb
#2048	pulse  cov: 4184 ft: 13749 corp: 519/51Kb exec/s: 26 rss: 247Mb
#4096	pulse  cov: 4641 ft: 19775 corp: 906/201Kb exec/s: 20 rss: 253Mb
Slowest unit: 13 s:
artifact_prefix='./'; Test unit written to ./slow-unit-4bbf474818229be7c3eaa56e66d8a671f61a8c4b
Slowest unit: 15 s:
artifact_prefix='./'; Test unit written to ./slow-unit-434da0af3356a442e2e6ea3bcef590755c6574e0
#7234	INITED cov: 4730 ft: 25892 corp: 1581/12441Kb exec/s: 5 rss: 295Mb
#7234	DONE   cov: 4730 ft: 25892 corp: 1581/12441Kb lim: 1048576 exec/s: 5 rss: 295Mb
Done 7234 runs in 1246 second(s)

to this branch:

Run base_encode_decode with args ['valgrind', '--quiet', '--error-exitcode=1', '/tmp/cirrus-build-1174734651/bitcoin-core/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/src/test/fuzz/fuzz', '-runs=1', PosixPath('/tmp/cirrus-build-1174734651/bitcoin-core/ci/scratch/qa-assets/fuzz_seed_corpus/base_encode_decode')]INFO: Running with entropic power schedule (0xFF, 100).
INFO: Seed: 3639341585
INFO: Loaded 1 modules   (366489 inline 8-bit counters): 366489 [0x1c106d0, 0x1c69e69), 
INFO: Loaded 1 PC tables (366489 PCs): 366489 [0x1c69e70,0x2201800), 
INFO:     7233 files found in /tmp/cirrus-build-1174734651/bitcoin-core/ci/scratch/qa-assets/fuzz_seed_corpus/base_encode_decode
INFO: -max_len is not provided; libFuzzer will not generate inputs larger than 1048576 bytes
INFO: seed corpus: files: 7233 min: 1b max: 1048576b total: 83751368b rss: 212Mb
#256	pulse  cov: 407 ft: 683 corp: 105/715b exec/s: 128 rss: 236Mb
#512	pulse  cov: 545 ft: 935 corp: 155/1712b exec/s: 128 rss: 245Mb
#1024	pulse  cov: 1182 ft: 2772 corp: 321/12232b exec/s: 102 rss: 256Mb
#2048	pulse  cov: 2032 ft: 5181 corp: 640/66Kb exec/s: 93 rss: 268Mb
#4096	pulse  cov: 2481 ft: 8460 corp: 1223/292Kb exec/s: 81 rss: 278Mb
#7234	INITED cov: 2588 ft: 11977 corp: 2183/10809Kb exec/s: 19 rss: 312Mb
#7234	DONE   cov: 2588 ft: 11977 corp: 2183/10809Kb lim: 1042864 exec/s: 19 rss: 312Mb
Done 7234 runs in 373 second(s)

@maflcko

maflcko commented Jun 28, 2023

Copy link
Copy Markdown
Contributor

Again, are you sure you aren't missing build options?

@fanquake

Copy link
Copy Markdown
Member Author

Again, are you sure you aren't missing build options?

The only option I can see passed by debian is --enable-tls, which is only used in valgrinds unit tests.

@maflcko

maflcko commented Jun 28, 2023

Copy link
Copy Markdown
Contributor

They may also pass some CFLAGS etc?

@maflcko

maflcko commented Jun 28, 2023

Copy link
Copy Markdown
Contributor

Also in the commit description you mention:

* No need to "bless" a specific compiler for use with Valgrind, (current
  discussion includes switch from Clang to GCC)

Which seems unrelated, no? Or is compiling from source also going to fix that valgrind gcc false positive?

@fanquake

fanquake commented Jun 28, 2023 •

Copy link
Copy Markdown
Member Author

They may also pass some CFLAGS etc?

They may do, and that could be the reason their binaries are so slow (i.e hardening flags). Unless you can point to something, I very much doubt that any additional cflags would be controlling valgrind features.

Which seems unrelated, no?

No. It's related given we are/were considering dropping support for Clang and using GCC? Hence ending up with a "blessed" compiler.

@fanquake

Copy link
Copy Markdown
Member Author

Looking at https://buildd.debian.org/status/fetch.php?pkg=valgrind&arch=amd64&ver=1%3A3.19.0-1&stamp=1661686809&raw=0, which should be a fairly recent Debian valgrind build, the relevant ./configure / flags are:

dh_auto_configure -- --enable-tls CFLAGS="-g -O2 -ffile-prefix-map=/<<PKGBUILDDIR>>=. -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 "-I/usr/include/x86_64-linux-gnu"   " LDFLAGS="-Wl,-z,relro"
	./configure --build=x86_64-linux-gnu --prefix=/usr --includedir=\${prefix}/include --mandir=\${prefix}/share/man --infodir=\${prefix}/share/info --sysconfdir=/etc --localstatedir=/var --disable-option-checking --disable-silent-rules --libdir=\${prefix}/lib/x86_64-linux-gnu --runstatedir=/run --disable-maintainer-mode --disable-dependency-tracking --enable-tls "CFLAGS=-g -O2 -ffile-prefix-map=/<<PKGBUILDDIR>>=. -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -I/usr/include/x86_64-linux-gnu   " LDFLAGS=-Wl,-z,relro

Other than --enable-tls, these are all standard autoconf flags, and I can't see any special c/ldflags etc.

@fanquake

Copy link
Copy Markdown
Member Author

Will close for now. This has completed in 5 and a half hours, compared to a recent 34 hour runtime.

@fanquake fanquake closed this Jun 28, 2023
fanquake added a commit to fanquake/bitcoin that referenced this pull request Jul 4, 2023
I've been using this branch for some time, for working Valgrind CI jobs
on aarch64. Benefits include:
* Valgrind CI jobs work across x86_64 & aarch64.
* Can use latest (hopefully less buggy) Valgrind, rather than whatever
  the distro happens to package.
* No need to "bless" a specific compiler for use with Valgrind, (current
  discussion includes switching from Clang to GCC).
* Valgrind from source seems to run significantly faster compared to running
  the system package. i.e, when fuzzing under Valgrind:

Master:
```bash
asmap_direct with args
Done 646 runs in 155 second(s)
....
addrman_deserialize with args
Done 2944 runs in 2875 second(s)
```

vs running this branch:
```bash
asmap_direct with args
Done 646 runs in 23 second(s)
...
addrman_deserialize with args
Done 2944 runs in 413 second(s)
```

This is also being seen in the qa-assets repo: bitcoin-core/qa-assets#136 (comment).
For example, the `descriptor_parse` target under Valgrind currently takes:
`Done 6304 runs in 12971 second(s)`
however [with this branch, it takes](https://cirrus-ci.com/task/4623075795271680?):
`Done 6304 runs in 4609 second(s)`.

Running the native_valgrind CI (master, aarch64):
```bash
test/sighash_tests.cpp(120): Entering test case "sighash_test"
==21957== Source and destination overlap in memcpy(0x871e4b0, 0x871e4b0, 36)
==21957==    at 0x488CFA0: __GI_memcpy (in /usr/libexec/valgrind/vgpreload_memcheck-arm64-linux.so)
==21957==    by 0x8F7F63: CTxIn::operator=(CTxIn const&) (transaction.h:74)
==21957==    by 0x93F96B: SignatureHashOld(CScript, CTransaction const&, unsigned int, int) (sighash_tests.cpp:76)
==21957==    by 0x93EF1F: sighash_tests::sighash_test::test_method() (sighash_tests.cpp:138)
==21957==    by 0x93EB73: sighash_tests::sighash_test_invoker() (sighash_tests.cpp:120)
==21957==    by 0x36CF47: boost::detail::function::void_function_invoker0<void (*)(), void>::invoke(boost::detail::function::function_buffer&) (function_template.hpp:117)
==21957==    by 0x25B367: boost::function0<void>::operator()() const (function_template.hpp:763)
==21957==    by 0x2D6647: boost::detail::forward::operator()() (execution_monitor.ipp:1388)
==21957==    by 0x2D627F: boost::detail::function::function_obj_invoker0<boost::detail::forward, int>::invoke(boost::detail::function::function_buffer&) (function_template.hpp:137)
==21957==    by 0x2D0393: boost::function0<int>::operator()() const (function_template.hpp:763)
==21957==    by 0x234A6B: int boost::detail::do_invoke<boost::shared_ptr<boost::detail::translator_holder_base>, boost::function<int ()> >(boost::shared_ptr<boost::detail::translator_holder_base> const&, boost::function<int ()> const&) (execution_monitor.ipp:301)
==21957==    by 0x1F7277: boost::execution_monitor::catch_signals(boost::function<int ()> const&) (execution_monitor.ipp:903)
==21957==
{
   <insert_a_suppression_name_here>
   Memcheck:Overlap
   fun:__GI_memcpy
   fun:_ZN5CTxInaSERKS_
   fun:_ZL16SignatureHashOld7CScriptRK12CTransactionji
   fun:_ZN13sighash_tests12sighash_test11test_methodEv
   fun:_ZN13sighash_testsL20sighash_test_invokerEv
   fun:_ZN5boost6detail8function22void_function_invoker0IPFvvEvE6invokeERNS1_15function_bufferE
   fun:_ZNK5boost9function0IvEclEv
   fun:_ZN5boost6detail7forwardclEv
   fun:_ZN5boost6detail8function21function_obj_invoker0INS0_7forwardEiE6invokeERNS1_15function_bufferE
   fun:_ZNK5boost9function0IiEclEv
   fun:_ZN5boost6detail9do_invokeINS_10shared_ptrINS0_22translator_holder_baseEEENS_8functionIFivEEEEEiRKT_RKT0_
   fun:_ZN5boost17execution_monitor13catch_signalsERKNS_8functionIFivEEE
}
```

vs running this branch:
```bash
real	118m55.057s
```

Disadvantages includes:
* Becoming slightly more of a package manager in the CI.

Related to the discussion in
bitcoin#27444.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants