[compiler-rt] b7d1ab7 - [HWASan] Add aliasing flag and enable HWASan to use it.

Matt Morehouse via llvm-commits llvm-commits at lists.llvm.org
Fri May 14 09:47:40 PDT 2021


Author: Matt Morehouse
Date: 2021-05-14T09:47:20-07:00
New Revision: b7d1ab75cf474fb3ffc7e7173762c4d83eb2ef8e

URL: https://github.com/llvm/llvm-project/commit/b7d1ab75cf474fb3ffc7e7173762c4d83eb2ef8e
DIFF: https://github.com/llvm/llvm-project/commit/b7d1ab75cf474fb3ffc7e7173762c4d83eb2ef8e.diff

LOG: [HWASan] Add aliasing flag and enable HWASan to use it.

-fsanitize-hwaddress-experimental-aliasing is intended to distinguish
aliasing mode from LAM mode on x86_64.  check-hwasan is configured
to use aliasing mode while check-hwasan-lam is configured to use LAM
mode.

The current patch doesn't actually do anything differently in the two
modes.  A subsequent patch will actually build the separate runtimes
and use them in each mode.

Currently LAM mode tests must be run in an emulator that
has LAM support.  To ensure LAM mode isn't broken by future patches, I
will next set up a QEMU buildbot to run the HWASan tests in LAM.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D102288

Added: 
    

Modified: 
    clang/include/clang/Driver/Options.td
    clang/include/clang/Driver/SanitizerArgs.h
    clang/lib/Driver/SanitizerArgs.cpp
    compiler-rt/test/hwasan/CMakeLists.txt
    compiler-rt/test/hwasan/TestCases/Linux/vfork.c
    compiler-rt/test/hwasan/lit.cfg.py
    compiler-rt/test/hwasan/lit.site.cfg.py.in

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 1fda2dac0f76f..a7adab50657af 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1547,6 +1547,14 @@ def fno_sanitize_memory_track_origins : Flag<["-"], "fno-sanitize-memory-track-o
                                         Group<f_clang_Group>,
                                         Flags<[CoreOption, NoXarchOption]>,
                                         HelpText<"Disable origins tracking in MemorySanitizer">;
+def fsanitize_hwaddress_experimental_aliasing
+  : Flag<["-"], "fsanitize-hwaddress-experimental-aliasing">,
+    Group<f_clang_Group>,
+    HelpText<"Enable aliasing mode in HWAddressSanitizer">;
+def fno_sanitize_hwaddress_experimental_aliasing
+  : Flag<["-"], "fno-sanitize-hwaddress-experimental-aliasing">,
+    Group<f_clang_Group>, Flags<[CoreOption, NoXarchOption]>,
+    HelpText<"Disable aliasing mode in HWAddressSanitizer">;
 defm sanitize_memory_use_after_dtor : BoolOption<"f", "sanitize-memory-use-after-dtor",
   CodeGenOpts<"SanitizeMemoryUseAfterDtor">, DefaultFalse,
   PosFlag<SetTrue, [CC1Option], "Enable">, NegFlag<SetFalse, [], "Disable">,

diff  --git a/clang/include/clang/Driver/SanitizerArgs.h b/clang/include/clang/Driver/SanitizerArgs.h
index e9609268ecd73..adfc26382f607 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -57,6 +57,7 @@ class SanitizerArgs {
   // True if cross-dso CFI support if provided by the system (i.e. Android).
   bool ImplicitCfiRuntime = false;
   bool NeedsMemProfRt = false;
+  bool HwasanUseAliases = false;
 
 public:
   /// Parses the sanitizer arguments from an argument list.
@@ -69,6 +70,9 @@ class SanitizerArgs {
   bool needsHwasanRt() const {
     return Sanitizers.has(SanitizerKind::HWAddress);
   }
+  bool needsHwasanAliasesRt() const {
+    return needsHwasanRt() && HwasanUseAliases;
+  }
   bool needsTsanRt() const { return Sanitizers.has(SanitizerKind::Thread); }
   bool needsMsanRt() const { return Sanitizers.has(SanitizerKind::Memory); }
   bool needsFuzzer() const { return Sanitizers.has(SanitizerKind::Fuzzer); }

diff  --git a/clang/lib/Driver/SanitizerArgs.cpp b/clang/lib/Driver/SanitizerArgs.cpp
index 7bd99e13010a6..9c54bd5fbab6c 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -865,6 +865,11 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
     } else {
       HwasanAbi = "interceptor";
     }
+    if (TC.getTriple().getArch() == llvm::Triple::x86_64)
+      HwasanUseAliases = Args.hasFlag(
+          options::OPT_fsanitize_hwaddress_experimental_aliasing,
+          options::OPT_fno_sanitize_hwaddress_experimental_aliasing,
+          HwasanUseAliases);
   }
 
   if (AllAddedKinds & SanitizerKind::SafeStack) {

diff  --git a/compiler-rt/test/hwasan/CMakeLists.txt b/compiler-rt/test/hwasan/CMakeLists.txt
index f6bdd510ad312..b463146132dbf 100644
--- a/compiler-rt/test/hwasan/CMakeLists.txt
+++ b/compiler-rt/test/hwasan/CMakeLists.txt
@@ -33,5 +33,15 @@ endif()
 add_lit_testsuite(check-hwasan "Running the HWAddressSanitizer tests"
   ${HWASAN_TESTSUITES}
   DEPENDS ${HWASAN_TEST_DEPS}
+  PARAMS "HWASAN_ENABLE_ALIASES=1"
   )
 set_target_properties(check-hwasan PROPERTIES FOLDER "Compiler-RT Misc")
+
+add_lit_testsuite(check-hwasan-lam
+  "Running the HWAddressSanitizer tests with Intel LAM"
+  ${HWASAN_TESTSUITES}
+  DEPENDS ${HWASAN_TEST_DEPS}
+  PARAMS "HWASAN_ENABLE_ALIASES=0"
+  EXCLUDE_FROM_CHECK_ALL
+  )
+set_target_properties(check-hwasan-lam PROPERTIES FOLDER "Compiler-RT Misc")

diff  --git a/compiler-rt/test/hwasan/TestCases/Linux/vfork.c b/compiler-rt/test/hwasan/TestCases/Linux/vfork.c
index 2b40c2bd1893f..f4e1d2a5885b5 100644
--- a/compiler-rt/test/hwasan/TestCases/Linux/vfork.c
+++ b/compiler-rt/test/hwasan/TestCases/Linux/vfork.c
@@ -2,9 +2,7 @@
 // RUN: %clang_hwasan -O0 %s -o %t && %run %t 2>&1
 
 // REQUIRES: aarch64-target-arch || x86_64-target-arch
-
-// Aliasing mode does not support stack tagging.
-// XFAIL: x86_64
+// REQUIRES: pointer-tagging
 
 #include <assert.h>
 #include <sys/types.h>

diff  --git a/compiler-rt/test/hwasan/lit.cfg.py b/compiler-rt/test/hwasan/lit.cfg.py
index 7c7ae08e5b8fe..62967fff5b1ec 100644
--- a/compiler-rt/test/hwasan/lit.cfg.py
+++ b/compiler-rt/test/hwasan/lit.cfg.py
@@ -12,6 +12,11 @@
 clang_cflags = [config.target_cflags] + config.debug_info_flags
 clang_cxxflags = config.cxx_mode_flags + clang_cflags
 clang_hwasan_common_cflags = clang_cflags + ["-fsanitize=hwaddress", "-fuse-ld=lld"]
+
+if config.target_arch == 'x86_64' and config.enable_aliases == '1':
+  clang_hwasan_common_cflags += ["-fsanitize-hwaddress-experimental-aliasing"]
+if config.enable_aliases != '1':
+  config.available_features.add('pointer-tagging')
 if config.target_arch == 'x86_64':
   # This does basically the same thing as tagged-globals on aarch64. Because
   # the x86_64 implementation is for testing purposes only there is no

diff  --git a/compiler-rt/test/hwasan/lit.site.cfg.py.in b/compiler-rt/test/hwasan/lit.site.cfg.py.in
index 8b6abd8f2e9f5..5181dc200d4f6 100644
--- a/compiler-rt/test/hwasan/lit.site.cfg.py.in
+++ b/compiler-rt/test/hwasan/lit.site.cfg.py.in
@@ -6,6 +6,9 @@ config.target_cflags = "@HWASAN_TEST_TARGET_CFLAGS@"
 config.target_arch = "@HWASAN_TEST_TARGET_ARCH@"
 config.android_files_to_push = @HWASAN_ANDROID_FILES_TO_PUSH@
 
+# Whether to use -mlam or not.
+config.enable_aliases = lit_config.params.get("HWASAN_ENABLE_ALIASES", "@HWASAN_ENABLE_ALIASES@")
+
 # Load common config for all compiler-rt lit tests.
 lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
 


        


More information about the llvm-commits mailing list