[compiler-rt] r318038 - [asan] Add CMake hook to override shadow scale in compiler_rt
Walter Lee via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 13 06:02:27 PST 2017
Author: waltl
Date: Mon Nov 13 06:02:27 2017
New Revision: 318038
URL: http://llvm.org/viewvc/llvm-project?rev=318038&view=rev
Log:
[asan] Add CMake hook to override shadow scale in compiler_rt
Allow user to override shadow scale in compiler_rt by passing
-DCOMPILER_RT_ASAN_SHADOW_SCALE=n to CMake. Propagate the override
shadow scale value via a compiler define to compiler-rt and asan
tests. Tests will use the define to partially disable unsupported
tests. Set "-mllvm -asan-mapping-scale=<n>" for compiler_rt tests.
Differential Revision: https://reviews.llvm.org/D39469
Modified:
compiler-rt/trunk/CMakeLists.txt
compiler-rt/trunk/lib/asan/CMakeLists.txt
compiler-rt/trunk/lib/asan/asan_mapping.h
compiler-rt/trunk/lib/asan/tests/CMakeLists.txt
compiler-rt/trunk/test/lit.common.cfg
compiler-rt/trunk/test/lit.common.configured.in
Modified: compiler-rt/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/CMakeLists.txt?rev=318038&r1=318037&r2=318038&view=diff
==============================================================================
--- compiler-rt/trunk/CMakeLists.txt (original)
+++ compiler-rt/trunk/CMakeLists.txt Mon Nov 13 06:02:27 2017
@@ -43,6 +43,25 @@ mark_as_advanced(COMPILER_RT_BUILD_PROFI
option(COMPILER_RT_BUILD_XRAY_NO_PREINIT "Build xray with no preinit patching" OFF)
mark_as_advanced(COMPILER_RT_BUILD_XRAY_NO_PREINIT)
+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()
+
set(COMPILER_RT_BAREMETAL_BUILD OFF CACHE BOOLEAN
"Build for a bare-metal target.")
Modified: compiler-rt/trunk/lib/asan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/CMakeLists.txt?rev=318038&r1=318037&r2=318038&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/asan/CMakeLists.txt Mon Nov 13 06:02:27 2017
@@ -40,6 +40,7 @@ set(ASAN_PREINIT_SOURCES
include_directories(..)
set(ASAN_CFLAGS ${SANITIZER_COMMON_CFLAGS})
+set(ASAN_COMMON_DEFINITIONS ${COMPILER_RT_ASAN_SHADOW_SCALE_DEFINITION})
append_rtti_flag(OFF ASAN_CFLAGS)
Modified: compiler-rt/trunk/lib/asan/asan_mapping.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_mapping.h?rev=318038&r1=318037&r2=318038&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_mapping.h (original)
+++ compiler-rt/trunk/lib/asan/asan_mapping.h Mon Nov 13 06:02:27 2017
@@ -131,7 +131,11 @@
// || `[0x30000000, 0x35ffffff]` || LowShadow ||
// || `[0x00000000, 0x2fffffff]` || LowMem ||
+#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;
static const u64 kDefaultShadowOffset32 = 1ULL << 29; // 0x20000000
static const u64 kDefaultShadowOffset64 = 1ULL << 44;
Modified: compiler-rt/trunk/lib/asan/tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/CMakeLists.txt?rev=318038&r1=318037&r2=318038&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/asan/tests/CMakeLists.txt Mon Nov 13 06:02:27 2017
@@ -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
@@ -52,6 +53,7 @@ list(APPEND ASAN_UNITTEST_COMMON_LINK_FL
# Use -D instead of definitions to please custom compile command.
list(APPEND ASAN_UNITTEST_COMMON_CFLAGS
+ ${COMPILER_RT_ASAN_SHADOW_SCALE_FLAG}
-DASAN_HAS_BLACKLIST=1
-DASAN_HAS_EXCEPTIONS=1
-DASAN_UAR=0)
Modified: compiler-rt/trunk/test/lit.common.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/lit.common.cfg?rev=318038&r1=318037&r2=318038&view=diff
==============================================================================
--- compiler-rt/trunk/test/lit.common.cfg (original)
+++ compiler-rt/trunk/test/lit.common.cfg Mon Nov 13 06:02:27 2017
@@ -46,6 +46,10 @@ else:
# Add compiler ID to the list of available features.
config.available_features.add(compiler_id)
+# If needed, add cflag for shadow scale.
+if config.asan_shadow_scale != '':
+ config.target_cflags += " -mllvm -asan-mapping-scale=" + config.asan_shadow_scale
+
# BFD linker in 64-bit android toolchains fails to find libm.so, which is a
# transitive shared library dependency (via asan runtime).
if config.android:
Modified: compiler-rt/trunk/test/lit.common.configured.in
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/lit.common.configured.in?rev=318038&r1=318037&r2=318038&view=diff
==============================================================================
--- compiler-rt/trunk/test/lit.common.configured.in (original)
+++ compiler-rt/trunk/test/lit.common.configured.in Mon Nov 13 06:02:27 2017
@@ -25,6 +25,7 @@ set_default("python_executable", "@PYTHO
set_default("compiler_rt_debug", @COMPILER_RT_DEBUG_PYBOOL@)
set_default("compiler_rt_libdir", "@COMPILER_RT_RESOLVED_LIBRARY_OUTPUT_DIR@")
set_default("emulator", "@COMPILER_RT_EMULATOR@")
+set_default("asan_shadow_scale", "@COMPILER_RT_ASAN_SHADOW_SCALE@")
set_default("ios", False)
set_default("iossim", False)
set_default("sanitizer_can_use_cxxabi", @SANITIZER_CAN_USE_CXXABI_PYBOOL@)
More information about the llvm-commits
mailing list