Skip to content

[compiler-rt][rtsan] Use Die instead of exit, define cf.exitcode #107635

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

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler-rt/lib/rtsan/rtsan_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static __rtsan::Context &GetContextForThisThreadImpl() {
Until then, and to keep the first PRs small, only the exit mode
is available.
*/
static void InvokeViolationDetectedAction() { exit(EXIT_FAILURE); }
static void InvokeViolationDetectedAction() { Die(); }

__rtsan::Context::Context() = default;

Expand Down
1 change: 1 addition & 0 deletions compiler-rt/lib/rtsan/rtsan_flags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ void __rtsan::InitializeFlags() {
{
CommonFlags cf;
cf.CopyFrom(*common_flags());
cf.exitcode = 43;
cf.external_symbolizer_path = GetEnv("RTSAN_SYMBOLIZER_PATH");
OverrideCommonFlags(cf);
}
Expand Down
17 changes: 17 additions & 0 deletions compiler-rt/lib/rtsan/tests/rtsan_test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,25 @@
//
//===----------------------------------------------------------------------===//

#include "sanitizer_common/sanitizer_platform.h"
#include "sanitizer_test_utils.h"

// Default RTSAN_OPTIONS for the unit tests.
extern "C" const char *__rtsan_default_options() {
#if SANITIZER_APPLE
// On Darwin, we default to `abort_on_error=1`, which would make tests run
// much slower. Let's override this and run lit tests with 'abort_on_error=0'
// and make sure we do not overwhelm the syslog while testing. Also, let's
// turn symbolization off to speed up testing, especially when not running
// with llvm-symbolizer but with atos.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This does fairly drastically speed up our unit tests. The difference is very noticeable

return "symbolize=false:abort_on_error=0:log_to_syslog=0";
#else
// Let's turn symbolization off to speed up testing (more than 3 times speedup
// observed).
return "symbolize=false";
#endif
}

int main(int argc, char **argv) {
testing::GTEST_FLAG(death_test_style) = "threadsafe";
testing::InitGoogleTest(&argc, argv);
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/lib/rtsan/tests/rtsan_test_utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ void ExpectRealtimeDeath(Function &&Func,
: "";
};

EXPECT_EXIT(RealtimeInvoke(std::forward<Function>(Func)),
ExitedWithCode(EXIT_FAILURE), GetExpectedErrorSubstring());
EXPECT_EXIT(RealtimeInvoke(std::forward<Function>(Func)), ExitedWithCode(43),
GetExpectedErrorSubstring());
}

template <typename Function> void ExpectNonRealtimeSurvival(Function &&Func) {
Expand Down
16 changes: 16 additions & 0 deletions compiler-rt/test/rtsan/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
# Setup config name.
config.name = "RTSAN" + config.name_suffix


default_rtsan_opts = "atexit_sleep_ms=0"

if config.host_os == "Darwin":
# On Darwin, we default to `abort_on_error=1`, which would make tests run
# much slower. Let's override this and run lit tests with 'abort_on_error=0'.
default_rtsan_opts += ":abort_on_error=0"

if default_rtsan_opts:
config.environment["RTSAN_OPTIONS"] = default_rtsan_opts
default_rtsan_opts += ":"

config.substitutions.append(
("%env_rtsan_opts=", "env RTSAN_OPTIONS=" + default_rtsan_opts)
)

# Setup source root.
config.test_source_root = os.path.dirname(__file__)

Expand Down
Loading