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: Pass sanitize flags to instrument libsecp256k1 code #28875

Merged
merged 1 commit into from Jan 26, 2024

Conversation

hebasto
Copy link
Member

@hebasto hebasto commented Nov 14, 2023

This PR is a revived #27991 with an addressed comment.

Fixes #27990.

Might be tested as follows:

$ ./autogen.sh && ./configure --enable-fuzz --with-sanitizers=fuzzer CC=clang-13 CXX=clang++-13
$ make clean > /dev/null && make
$ objdump --disassemble=secp256k1_xonly_pubkey_serialize src/test/fuzz/fuzz | grep __sanitizer_cov
 1953bd0:	e8 bb c6 05 ff       	call   9b0290 <__sanitizer_cov_trace_const_cmp8>
 1953d32:	e8 69 c4 05 ff       	call   9b01a0 <__sanitizer_cov_trace_pc_indir>
 1953d58:	e8 43 c4 05 ff       	call   9b01a0 <__sanitizer_cov_trace_pc_indir>
 1953d82:	e8 19 c4 05 ff       	call   9b01a0 <__sanitizer_cov_trace_pc_indir>

@DrahtBot
Copy link
Contributor

DrahtBot commented Nov 14, 2023

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 fanquake, dergoegge

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:

  • #28983 (Stratum v2 Template Provider (take 2) by Sjors)
  • #28241 (Silent payment index (for light wallets and consistency check) by Sjors)
  • #28201 (Silent Payments: sending by josibake)
  • #28122 (Silent Payments: Implement BIP352 by josibake)

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.

@dergoegge
Copy link
Member

Concept ACK

Thanks! will review soon

@hebasto
Copy link
Member Author

hebasto commented Nov 14, 2023

Converted to a draft, as I'm not sure how to suppress new UBSan reports.

@hebasto
Copy link
Member Author

hebasto commented Jan 6, 2024

The CI has been fixed and this PR is ready for review now.

Friendly ping @dergoegge :)

Copy link
Member

@dergoegge dergoegge left a comment

Choose a reason for hiding this comment

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

tACK a041915

It might be better to reverse the order of the commits or squash them to avoid bisect failures in between.

@hebasto
Copy link
Member Author

hebasto commented Jan 13, 2024

It might be better to reverse the order of the commits or squash them to avoid bisect failures in between.

Squashed.

Copy link
Member

@dergoegge dergoegge left a comment

Choose a reason for hiding this comment

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

reACK e39bae1

Also a new UBSan suppression has been added.
Copy link
Member

@fanquake fanquake left a comment

Choose a reason for hiding this comment

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

ACK cbea49c

@@ -1946,6 +1947,9 @@ CPPFLAGS_TEMP="$CPPFLAGS"
unset CPPFLAGS
CPPFLAGS="$CPPFLAGS_TEMP"

if test -n "$use_sanitizers"; then
export SECP_CFLAGS="$SECP_CFLAGS $SANITIZER_CFLAGS"
Copy link
Contributor

Choose a reason for hiding this comment

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

My take on SECP_CFLAGS is that it's an internal of the libsecp256k1 build system, and users are not supposed to set it (and are not guaranteed that it does anything meaningful). The proper user variable is just CFLAGS.

You could either export CFLAGS="-g $SANITIZER_CFLAGS" temporarily, or perhaps add a CFLAGS arg to ac_configure_args.

We could also expose the SECP_CFLAGS "officially" in the lib. Then it should probably be renamed to SECP256K1_CFLAGS. But I think it's a bit arbitrary, given there's an official way to set CFLAGS (namely setting CFLAGS ;)).

There's also this, which may be an elegant solution or overkill, depending on your taste... https://www.gnu.org/software/autoconf-archive/ax_subdirs_configure.html

Sorry for noticing this only now in a second review...

Copy link
Member

@fanquake fanquake Jan 25, 2024

Choose a reason for hiding this comment

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

I was thinking about the best way to handle this, and my current take was that given this is only when we are using sanitizers, and we are a somewhat non-standard/more-tightly-coupled users of secp in any case, I wasn't too worried. Happy for any other approach that achieves the same thing, but also don't want secp to expose additional (non-standard) flags just for us.

edit: we have looked at the subdirs_configure before, and iirc it didn't work quite how we wanted for various reasons.

Copy link
Contributor

Choose a reason for hiding this comment

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

I wasn't too worried.

Yep, I agree, any approach is ok in the end. My feeling is just that setting SECP_CFLAGS is not the cleanest choice and more likely than my other suggestions to cause breaks in the future.

Copy link
Member

Choose a reason for hiding this comment

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

My feeling is just that setting SECP_CFLAGS is not the cleanest choice and more likely than my other suggestions to cause breaks in the future.

We can accept that possibility for now, and at the next subtree update (if/when things break), we'll take another look.

@@ -2006,7 +2010,7 @@ echo " target os = $host_os"
echo " build os = $build_os"
echo
echo " CC = $CC"
echo " CFLAGS = $PTHREAD_CFLAGS $CFLAGS"
echo " CFLAGS = $PTHREAD_CFLAGS $SANITIZER_CFLAGS $CFLAGS"
Copy link
Contributor

Choose a reason for hiding this comment

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

Serious question: What is this line supposed to print, given that there are also ZMQ_CFLAGS, BDB_CFLAGS and EVENT_CFLAGS? One could say that the libsecp256k1 configure output already prints its CFLAGS, so there's no need to cover that here, but I don't know because I don't know what the purpose of this line is. Where else do we need CFLAGS?

Copy link
Member

Choose a reason for hiding this comment

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

These lines have never been super consistent, but are meant to be a rough overview of the (interesting) flags being used for compilation. I think you're correct in that printing secp flags (again) here would be overkill. For any other flags, I don't think they are very meaningful for most builders. I think it's also unlikely we'll significantly change anything here too much further, given that this is going to be completely redone with CMake.

Copy link
Member

@dergoegge dergoegge left a comment

Choose a reason for hiding this comment

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

reACK cbea49c

@fanquake fanquake merged commit e3b68b3 into bitcoin:master Jan 26, 2024
16 checks passed
@hebasto hebasto deleted the 231114-sanitize branch January 26, 2024 12:00
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.

libsecp256k1 not instrumented when building with sanitizers
5 participants