[compiler-rt] 643ccf6 - Revert "[Scudo] Use GWP-ASan's aligned allocations and fixup postalloc hooks."
Mitch Phillips via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 23 15:40:55 PDT 2021
Author: Mitch Phillips
Date: 2021-04-23T15:40:38-07:00
New Revision: 643ccf6e4b85ad1edae48e64c178bf6b00991a96
URL: https://github.com/llvm/llvm-project/commit/643ccf6e4b85ad1edae48e64c178bf6b00991a96
DIFF: https://github.com/llvm/llvm-project/commit/643ccf6e4b85ad1edae48e64c178bf6b00991a96.diff
LOG: Revert "[Scudo] Use GWP-ASan's aligned allocations and fixup postalloc hooks."
This reverts commit a683abe5c026cffff12a943564f4cb1b20972abf.
Broke the upstream buildbots:
https://lab.llvm.org/buildbot/#/builders/37/builds/3731/steps/16/logs/stdio
Added:
Modified:
compiler-rt/lib/scudo/scudo_allocator.cpp
compiler-rt/lib/scudo/standalone/combined.h
compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
compiler-rt/lib/scudo/standalone/tests/wrappers_cpp_test.cpp
compiler-rt/test/scudo/standalone/CMakeLists.txt
Removed:
compiler-rt/test/scudo/standalone/unit/gwp_asan/lit.site.cfg.py.in
################################################################################
diff --git a/compiler-rt/lib/scudo/scudo_allocator.cpp b/compiler-rt/lib/scudo/scudo_allocator.cpp
index d8a9a9cc5f90..82864405dfb0 100644
--- a/compiler-rt/lib/scudo/scudo_allocator.cpp
+++ b/compiler-rt/lib/scudo/scudo_allocator.cpp
@@ -303,6 +303,13 @@ struct Allocator {
bool ForceZeroContents = false) {
initThreadMaybe();
+#ifdef GWP_ASAN_HOOKS
+ if (UNLIKELY(GuardedAlloc.shouldSample())) {
+ if (void *Ptr = GuardedAlloc.allocate(Size))
+ return Ptr;
+ }
+#endif // GWP_ASAN_HOOKS
+
if (UNLIKELY(Alignment > MaxAlignment)) {
if (AllocatorMayReturnNull())
return nullptr;
@@ -311,16 +318,6 @@ struct Allocator {
if (UNLIKELY(Alignment < MinAlignment))
Alignment = MinAlignment;
-#ifdef GWP_ASAN_HOOKS
- if (UNLIKELY(GuardedAlloc.shouldSample())) {
- if (void *Ptr = GuardedAlloc.allocate(Size, Alignment)) {
- if (SCUDO_CAN_USE_HOOKS && &__sanitizer_malloc_hook)
- __sanitizer_malloc_hook(Ptr, Size);
- return Ptr;
- }
- }
-#endif // GWP_ASAN_HOOKS
-
const uptr NeededSize = RoundUpTo(Size ? Size : 1, MinAlignment) +
Chunk::getHeaderSize();
const uptr AlignedSize = (Alignment > MinAlignment) ?
diff --git a/compiler-rt/lib/scudo/standalone/combined.h b/compiler-rt/lib/scudo/standalone/combined.h
index 4c95b8764c3f..33ae6c42eca9 100644
--- a/compiler-rt/lib/scudo/standalone/combined.h
+++ b/compiler-rt/lib/scudo/standalone/combined.h
@@ -290,31 +290,27 @@ class Allocator {
bool ZeroContents = false) {
initThreadMaybe();
- const Options Options = Primary.Options.load();
- if (UNLIKELY(Alignment > MaxAlignment)) {
- if (Options.get(OptionBit::MayReturnNull))
- return nullptr;
- reportAlignmentTooBig(Alignment, MaxAlignment);
- }
- if (Alignment < MinAlignment)
- Alignment = MinAlignment;
-
#ifdef GWP_ASAN_HOOKS
if (UNLIKELY(GuardedAlloc.shouldSample())) {
- if (void *Ptr = GuardedAlloc.allocate(Size, Alignment)) {
- if (UNLIKELY(&__scudo_allocate_hook))
- __scudo_allocate_hook(Ptr, Size);
- Stats.add(StatAllocated, Size);
+ if (void *Ptr = GuardedAlloc.allocate(roundUpTo(Size, Alignment)))
return Ptr;
- }
}
#endif // GWP_ASAN_HOOKS
+ const Options Options = Primary.Options.load();
const FillContentsMode FillContents = ZeroContents ? ZeroFill
: TSDRegistry.getDisableMemInit()
? NoFill
: Options.getFillContentsMode();
+ if (UNLIKELY(Alignment > MaxAlignment)) {
+ if (Options.get(OptionBit::MayReturnNull))
+ return nullptr;
+ reportAlignmentTooBig(Alignment, MaxAlignment);
+ }
+ if (Alignment < MinAlignment)
+ Alignment = MinAlignment;
+
// If the requested size happens to be 0 (more common than you might think),
// allocate MinAlignment bytes on top of the header. Then add the extra
// bytes required to fulfill the alignment requirements: we allocate enough
@@ -507,20 +503,18 @@ class Allocator {
// being destroyed properly. Any other heap operation will do a full init.
initThreadMaybe(/*MinimalInit=*/true);
- if (UNLIKELY(&__scudo_deallocate_hook))
- __scudo_deallocate_hook(Ptr);
-
- if (UNLIKELY(!Ptr))
- return;
-
#ifdef GWP_ASAN_HOOKS
if (UNLIKELY(GuardedAlloc.pointerIsMine(Ptr))) {
GuardedAlloc.deallocate(Ptr);
- Stats.add(StatFree, GuardedAlloc.getSize(Ptr));
return;
}
#endif // GWP_ASAN_HOOKS
+ if (UNLIKELY(&__scudo_deallocate_hook))
+ __scudo_deallocate_hook(Ptr);
+
+ if (UNLIKELY(!Ptr))
+ return;
if (UNLIKELY(!isAligned(reinterpret_cast<uptr>(Ptr), MinAlignment)))
reportMisalignedPointer(AllocatorAction::Deallocating, Ptr);
@@ -577,7 +571,6 @@ class Allocator {
if (NewPtr)
memcpy(NewPtr, OldPtr, (NewSize < OldSize) ? NewSize : OldSize);
GuardedAlloc.deallocate(OldPtr);
- Stats.add(StatFree, OldSize);
return NewPtr;
}
#endif // GWP_ASAN_HOOKS
diff --git a/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp b/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
index eed8f0319337..e8872a154fc1 100644
--- a/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
@@ -94,18 +94,6 @@ TEST(ScudoWrappersCTest, Calloc) {
EXPECT_EQ(errno, ENOMEM);
}
-TEST(ScudoWrappersCTest, SmallAlign) {
- void *P;
- for (size_t Size = 1; Size <= 0x10000; Size <<= 1) {
- for (size_t Align = 1; Align <= 0x10000; Align <<= 1) {
- for (size_t Count = 0; Count < 3; ++Count) {
- P = memalign(Align, Size);
- EXPECT_TRUE(reinterpret_cast<uintptr_t>(P) % Align == 0);
- }
- }
- }
-}
-
TEST(ScudoWrappersCTest, Memalign) {
void *P;
for (size_t I = FIRST_32_SECOND_64(2U, 3U); I <= 18U; I++) {
diff --git a/compiler-rt/lib/scudo/standalone/tests/wrappers_cpp_test.cpp b/compiler-rt/lib/scudo/standalone/tests/wrappers_cpp_test.cpp
index 9df06dcdf142..d24b6651d95e 100644
--- a/compiler-rt/lib/scudo/standalone/tests/wrappers_cpp_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/wrappers_cpp_test.cpp
@@ -66,10 +66,6 @@ class Pixel {
};
TEST(ScudoWrappersCppTest, New) {
- if (getenv("SKIP_TYPE_MISMATCH")) {
- printf("Skipped type mismatch tests.\n");
- return;
- }
testCxxNew<bool>();
testCxxNew<uint8_t>();
testCxxNew<uint16_t>();
diff --git a/compiler-rt/test/scudo/standalone/CMakeLists.txt b/compiler-rt/test/scudo/standalone/CMakeLists.txt
index 3452398a65b5..a55fc6b5daa5 100644
--- a/compiler-rt/test/scudo/standalone/CMakeLists.txt
+++ b/compiler-rt/test/scudo/standalone/CMakeLists.txt
@@ -4,12 +4,6 @@ if(COMPILER_RT_INCLUDE_TESTS AND COMPILER_RT_HAS_SCUDO_STANDALONE)
${CMAKE_CURRENT_BINARY_DIR}/unit/lit.site.cfg.py)
list(APPEND SCUDO_STANDALONE_TEST_DEPS ScudoUnitTests)
list(APPEND SCUDO_STANDALONE_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/unit)
- if (COMPILER_RT_HAS_GWP_ASAN)
- configure_lit_site_cfg(
- ${CMAKE_CURRENT_SOURCE_DIR}/unit/gwp_asan/lit.site.cfg.py.in
- ${CMAKE_CURRENT_BINARY_DIR}/unit/gwp_asan/lit.site.cfg.py)
- list(APPEND SCUDO_STANDALONE_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/unit/gwp_asan)
- endif()
endif()
add_lit_testsuite(check-scudo_standalone
diff --git a/compiler-rt/test/scudo/standalone/unit/gwp_asan/lit.site.cfg.py.in b/compiler-rt/test/scudo/standalone/unit/gwp_asan/lit.site.cfg.py.in
deleted file mode 100644
index c12b72c009b2..000000000000
--- a/compiler-rt/test/scudo/standalone/unit/gwp_asan/lit.site.cfg.py.in
+++ /dev/null
@@ -1,24 +0,0 @@
- at LIT_SITE_CFG_IN_HEADER@
-
-# Load common config for all compiler-rt unit tests.
-lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/unittests/lit.common.unit.configured")
-
-# Setup config name.
-config.name = 'ScudoStandalone-Unit-GwpAsanTorture'
-
-# Setup test source and exec root.
-# For unit tests, we define it as build directory with unit tests.
-config.test_exec_root = "@COMPILER_RT_BINARY_DIR@/lib/scudo/standalone/tests"
-config.test_source_root = config.test_exec_root
-
-# This is a second run of the Scudo test suite, but this time under a "torture"
-# GWP-ASan mode. Every allocation that can go to GWP-ASan, should go to
-# GWP-ASan. This ensures that GWP-ASan allocations meet the same testing
-# requirements as the native Scudo allocations. Reserves 409MiB of vaddr space
-# for the guarded pool, and this should be paged in on demand. If necessary (for
-# 32-bit or places where kernel commits immediately), this could possibly be
-# reduced.
-config.environment['SCUDO_OPTIONS'] = 'GWP_ASAN_SampleRate=1:GWP_ASAN_MaxSimultaneousAllocations=100000'
-
-# GWP-ASan doesn't support malloc-type mismatch.
-config.environment['SKIP_TYPE_MISMATCH'] = '1'
More information about the llvm-commits
mailing list