[PATCH] D131345: [RISC-V][HWASAN] Enable HWASAN for RISC-V architecture

Alexey Baturo via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Aug 7 03:29:49 PDT 2022


smd created this revision.
Herald added subscribers: Enna1, sunshaoce, VincentWu, luke957, vkmr, luismarques, sameer.abuasal, s.egerton, Jim, PkmX, rogfer01, shiva0217, kito-cheng, simoncook, arichardson, mgorny.
Herald added a project: All.
smd edited the summary of this revision.
smd added reviewers: eugenis, vitalybuka, luismarques.
smd published this revision for review.
Herald added subscribers: Sanitizers, cfe-commits, pcwang-thead, MaskRay.
Herald added projects: clang, Sanitizers.

[7/7] patch series to port ASAN for riscv64

These changes allow using HWASAN on RISCV64 architecture.

The majority of existing tests are passing with a few exceptions(see below).
The tests were run on QEMU, since currently there're no hardware with support
for J-extension.

For this feature to work the system must support PR_{SET,GET}_TAGGED_ADDR_CTRL
syscall. For now this is only available for a patched Linux kernel and QEMU with
enabled experimental J-extension.

Results of running HWASAN lit tests for RISC-V:

  Unsupported      :  5
  Passed           : 73
  Expectedly Failed:  9

Current RISC-V code models and existing relocation symbols don't allow us to
tag global variables. This will be addressed in further patches.
These tests are marked as expected to fail since they check tagging globals:

  HWAddressSanitizer-riscv64 :: TestCases/Linux/create-thread-stress.cpp (3 of 87)
  HWAddressSanitizer-riscv64 :: TestCases/print-memory-usage.c (23 of 87)
  HWAddressSanitizer-riscv64 :: TestCases/Linux/atfork.cpp (24 of 87)
  HWAddressSanitizer-riscv64 :: TestCases/thread-uaf.c (25 of 87)
  HWAddressSanitizer-riscv64 :: TestCases/exported-tagged-global.c (39 of 87)
  HWAddressSanitizer-riscv64 :: TestCases/many-threads-uaf.c (42 of 87)
  HWAddressSanitizer-riscv64 :: TestCases/pthread_create.c (69 of 87)
  HWAddressSanitizer-riscv64 :: TestCases/global.c (75 of 87)
  HWAddressSanitizer-riscv64 :: TestCases/global-with-reduction.c (76 of 87)

Depends On D131344 <https://reviews.llvm.org/D131344>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131345

Files:
  clang/lib/Driver/ToolChains/Linux.cpp
  compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake


Index: compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
===================================================================
--- compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
+++ compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
@@ -55,7 +55,7 @@
       ${PPC64} ${S390X} ${RISCV64} ${HEXAGON})
 endif()
 set(ALL_MSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${PPC64} ${S390X})
-set(ALL_HWASAN_SUPPORTED_ARCH ${X86_64} ${ARM64})
+set(ALL_HWASAN_SUPPORTED_ARCH ${X86_64} ${ARM64} ${RISCV64})
 set(ALL_MEMPROF_SUPPORTED_ARCH ${X86_64})
 set(ALL_PROFILE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${PPC32} ${PPC64}
     ${MIPS32} ${MIPS64} ${S390X} ${SPARC} ${SPARCV9} ${HEXAGON}
Index: clang/lib/Driver/ToolChains/Linux.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -765,8 +765,10 @@
   if (IsX86_64 || IsMIPS64 || IsAArch64 || IsX86 || IsMIPS || IsArmArch ||
       IsPowerPC64 || IsHexagon)
     Res |= SanitizerKind::Scudo;
-  if (IsX86_64 || IsAArch64) {
+  if (IsX86_64 || IsAArch64 || IsRISCV64) {
     Res |= SanitizerKind::HWAddress;
+  }
+  if (IsX86_64 || IsAArch64) {
     Res |= SanitizerKind::KernelHWAddress;
   }
   return Res;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131345.450579.patch
Type: text/x-patch
Size: 1277 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220807/e8563cd1/attachment-0001.bin>


More information about the cfe-commits mailing list