Skip to content

Commit

Permalink
Revert "[ASan] Removed ASAN_SHADOW_SCALE."
Browse files Browse the repository at this point in the history
This reverts commit e4800fc.

Reviewed By: kstoimenov

Differential Revision: https://reviews.llvm.org/D115286
  • Loading branch information
kstoimenov committed Dec 7, 2021
1 parent e4800fc commit 36529a2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
19 changes: 19 additions & 0 deletions compiler-rt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,25 @@ mark_as_advanced(COMPILER_RT_BUILD_ORC)
option(COMPILER_RT_BUILD_GWP_ASAN "Build GWP-ASan, and link it into SCUDO" ON)
mark_as_advanced(COMPILER_RT_BUILD_GWP_ASAN)

set(COMPILER_RT_ASAN_SHADOW_SCALE ""
CACHE STRING "Override the shadow scale to be used in ASan runtime")

if (NOT COMPILER_RT_ASAN_SHADOW_SCALE STREQUAL "")
# Check that the shadow scale value is valid.
if (NOT (COMPILER_RT_ASAN_SHADOW_SCALE GREATER -1 AND
COMPILER_RT_ASAN_SHADOW_SCALE LESS 8))
message(FATAL_ERROR "
Invalid ASan Shadow Scale '${COMPILER_RT_ASAN_SHADOW_SCALE}'.")
endif()

set(COMPILER_RT_ASAN_SHADOW_SCALE_LLVM_FLAG
-mllvm -asan-mapping-scale=${COMPILER_RT_ASAN_SHADOW_SCALE})
set(COMPILER_RT_ASAN_SHADOW_SCALE_DEFINITION
ASAN_SHADOW_SCALE=${COMPILER_RT_ASAN_SHADOW_SCALE})
set(COMPILER_RT_ASAN_SHADOW_SCALE_FLAG
-D${COMPILER_RT_ASAN_SHADOW_SCALE_DEFINITION})
endif()

if(FUCHSIA)
set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS_DEFAULT OFF)
else()
Expand Down
9 changes: 7 additions & 2 deletions compiler-rt/lib/asan/asan_mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,15 @@
// || `[0x30000000, 0x35ffffff]` || LowShadow ||
// || `[0x00000000, 0x2fffffff]` || LowMem ||

#define SHADOW_SCALE 3

#if defined(ASAN_SHADOW_SCALE)
static const u64 kDefaultShadowScale = ASAN_SHADOW_SCALE;
#else
static const u64 kDefaultShadowScale = 3;
#endif
static const u64 kDefaultShadowSentinel = ~(uptr)0;

#define SHADOW_SCALE kDefaultShadowScale

#if SANITIZER_FUCHSIA
# define SHADOW_OFFSET_CONST (0)
#elif SANITIZER_WORDSIZE == 32
Expand Down
2 changes: 2 additions & 0 deletions compiler-rt/lib/asan/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ set(ASAN_UNITTEST_HEADERS
set(ASAN_UNITTEST_COMMON_CFLAGS
${COMPILER_RT_UNITTEST_CFLAGS}
${COMPILER_RT_GTEST_CFLAGS}
${COMPILER_RT_ASAN_SHADOW_SCALE_LLVM_FLAG}
-I${COMPILER_RT_SOURCE_DIR}/include
-I${COMPILER_RT_SOURCE_DIR}/lib
-I${COMPILER_RT_SOURCE_DIR}/lib/asan
Expand Down Expand Up @@ -51,6 +52,7 @@ list(APPEND ASAN_UNITTEST_COMMON_LINK_FLAGS -g)

# Use -D instead of definitions to please custom compile command.
list(APPEND ASAN_UNITTEST_COMMON_CFLAGS
${COMPILER_RT_ASAN_SHADOW_SCALE_FLAG}
-DASAN_HAS_IGNORELIST=1
-DASAN_HAS_EXCEPTIONS=1
-DASAN_UAR=0
Expand Down
2 changes: 2 additions & 0 deletions compiler-rt/lib/asan/tests/asan_interface_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ TEST(AddressSanitizerInterface, DeathCallbackTest) {
#define BAD_ACCESS(ptr, offset) \
EXPECT_TRUE(__asan_address_is_poisoned(ptr + offset))

#if !defined(ASAN_SHADOW_SCALE) || ASAN_SHADOW_SCALE == 3
static const char* kUseAfterPoisonErrorMessage = "use-after-poison";

TEST(AddressSanitizerInterface, SimplePoisonMemoryRegionTest) {
Expand Down Expand Up @@ -199,6 +200,7 @@ TEST(AddressSanitizerInterface, OverlappingPoisonMemoryRegionTest) {
BAD_ACCESS(array, 96);
free(array);
}
#endif // !defined(ASAN_SHADOW_SCALE) || ASAN_SHADOW_SCALE == 3

TEST(AddressSanitizerInterface, PushAndPopWithPoisoningTest) {
// Vector of capacity 20
Expand Down

0 comments on commit 36529a2

Please sign in to comment.