Repository navigation
Conversation
…izer Under ASan, TSan or LSan the runtime owns malloc, and replacing it through dlsym(RTLD_NEXT) crashes run_tests before main (ASan: segfault, no output; LSan: duplicate operator new at link time). With a sanitizer, allocation_tracking now counts through __sanitizer_install_malloc_and_free_hooks instead, so the real-time-safety tests keep their meaning there. Builds without a sanitizer are unchanged. Reproduce: configure with -DCMAKE_CXX_FLAGS=-fsanitize=address (or thread, leak) and the matching linker flag; on main run_tests exits 139 with no output, on this branch it passes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Makes
run_testsusable under AddressSanitizer, ThreadSanitizer and LeakSanitizer.Problem.
tools/test/allocation_tracking.cppreplacesmallocand friends and finds the originals throughdlsym(RTLD_NEXT). Under a sanitizer the runtime ownsmalloc, and that replacement recurses: onmaintoday,run_testsbuilt with-fsanitize=addresssegfaults before printing anything (exit 139). With-fsanitize=leakit fails to link (duplicateoperator new).Fix. When built with a sanitizer, count allocations through the sanitizer's own hooks (
__sanitizer_install_malloc_and_free_hooks) instead. The real-time-safety tests keep their meaning, since they only ever check "zero" against "more than zero". Builds without a sanitizer are unchanged: the new code sits entirely behind#ifdef NAM_TEST_UNDER_SANITIZER.Reproduce.
cmake -B build-asan -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS=-fsanitize=address -DCMAKE_EXE_LINKER_FLAGS=-fsanitize=address cmake --build build-asan -j && ./build-asan/tools/run_testsOn
main: exit 139, no output. With this change:Success!. Checked the same way withthreadandleak, on Linux with clang 18.One file, +35 lines.