-
Notifications
You must be signed in to change notification settings - Fork 37.8k
build: enable libc++ hardening in debug builds #31424
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
base: master
Are you sure you want to change the base?
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/31424. ReviewsSee the guideline for information on the review process. ConflictsNo conflicts as of last run. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @hebasto
0398eb6
to
5523b84
Compare
9a024f7
to
3d3f9b3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3d3f9b3
to
f588893
Compare
f588893
to
bda1476
Compare
bda1476
to
7daae2c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
concept ack, but it would be good to get the (CI) changes right
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
|
This should already be done via depends. For example:
|
Excellent! Removed from OP. |
Would be nice to have steps to test this with gcc and clang (maybe with an example bug from the past or a synthetic one). Otherwise, it will be harder to test and the real benefits are harder to see and touch. Also the pull title could be adjusted to mention the Debug restriction. |
--- i/src/test/random_tests.cpp
+++ w/src/test/random_tests.cpp
@@ -17,12 +17,18 @@ BOOST_FIXTURE_TEST_SUITE(random_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(osrandom_tests)
{
BOOST_CHECK(Random_SanityCheck());
}
+BOOST_AUTO_TEST_CASE(t)
+{
+ std::vector<int> v{1, 2, 3};
+ (void)v[10];
+}
+
BOOST_AUTO_TEST_CASE(fastrandom_tests_deterministic)
{
// Check that deterministic FastRandomContexts are deterministic
SeedRandomForTest(SeedRand::ZEROS);
FastRandomContext ctx1{true};
FastRandomContext ctx2{true}; Compile with clang and run Without this PR:
With this PR:
|
I tried this with GCC with -DCMAKE_BUILD_TYPE=Debug, but it passed without error. What are the exact steps to reproduce your claim?
|
The documentation that I linked is explicit: https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_macros.html
If you suspect that there is a bug in GCC or the documentation is wrong, you can try the above
|
There is no GCC release with this feature yet (gcc-mirror/gcc@361d230), so simply claiming that it is enabled by default is a bit misleading. I tried with the latest GCC release (14) and it didn't work. |
Also, for libc++ you are enabling the strongest non-abi breaking one, so it would be better to do the same for gcc, which probably is |
Can't enable |
libc++ hardening is also enabled in the CI. I find it extremely hard to review this pull request, because for months, on every push it is changing what hardening setting to apply in what severity to what part of the system. My recommendation would be to just state your goal, so that reviewers can easily decide what is the best way to achieve your goal. |
Yes. That is not ABI breaking, so it can be enabled out in the wild (ie for everybody via CMake) in addition to the CI.
I changed it based on reviewers' feedback, including yours. Thanks for that! Also reduced the scope and dropped parts of it because of possible performance issues. Right now it is
It is stated in the PR title and description. |
I'd just find it odd to enable hardening for libc++, but not for GCC in debug builds. GCC is probably used more widely by devs. I know it may be enabled by default for the GCC std lib in a future release, but it may take some time until devs are updating to that. libc++ will also do the same: https://www.github.com/llvm/llvm-project/issues/122925 So if upstream is a reason to not do it for gcc, then it could also be skipped for libc++? However, you are enabling the strongest debug mode for libc++ here, so I also wonder about the performance impact? I guess performance expectations are non-existing in debug builds, but it would still be good to know, as it would be impossible to disable, and would disallow hacks such as https://www.github.com/bitcoin/bitcoin/pull/32113#issuecomment-2747808769 |
This conversation is going in circles: can't enable full GCC debug like for Clang because the GCC one is ABI breaking: #31424 (comment)
This is about the "fast/light" debug which is not in the scope of this PR (anymore). GCC is not in the scope of this PR either. If you want to do GCC and/or "fast" debug, feel free to open another PR, I will review. That was here and was dropped.
GCC is ABI breaking and Clang is not. So, only do Clang in this PR.
Can be disabled with:
|
The fast GCC debug mode should not be abi-breaking ( However, before merge, it would be good to know the performance impact of the slow one. This makes it easier to judge the impact on CI (c.f. #29796 (comment)) and easier to judge when it should be disabled, or if it can just be left turned on all the time. |
Note that this will also appear broken in the summary: cmake -B build -DCMAKE_BUILD_TYPE=Debug
<snip>
Preprocessor defined macros ........... <snip> RPC_DOC_CHECK ABORT_ON_FAILED_ASSUME $<IF:$<CONFIG:Debug>,_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG,> |
Agree. Debug-performance of the unit tests seems to be the same as in master:
PR:
clang 21.0.0 |
Turned this into a brainstorming issue, see #32265 |
|
Thanks for the note. There was a silent merge conflict.
|
When compiling with libc++ in debug mode, then enable full libc++ hardening. Inspired by bitcoin#31272 (comment)
|
Seems fine. I tested not this pull, but Not sure how many devs would benefit from this. I can trivially set this myself, and I presume the majority isn't using libc++, except for macOS devs? So it may be better to ask macOS devs for review/testing? |
When compiling with libc++ in debug mode, then enable full libc++ hardening.
Inspired by #31272 (comment)
Note that
libstdc++
's_GLIBCXX_ASSERTIONS
(aka light debug mode) is enabled by default when compiling without optimizations), that is in our debug builds. But see #31424 (comment).Further considerations:
Consider enabling
libstdc++
s_GLIBCXX_ASSERTIONS
(aka light debug mode) also in non-debug builds. Should assess performance impact.Consider enabling
libc++
s_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST
in non-debug builds. Should assess peformance impact as well.