[compiler-rt] adb555e - [CFI] Allow LoongArch (#67314)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 28 00:40:46 PDT 2023


Author: Ami-zhang
Date: 2023-09-28T15:40:42+08:00
New Revision: adb555ea369a3a989a9db619c784aa76cccdb823

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

LOG: [CFI] Allow LoongArch (#67314)

Enable icall tests on loongarch64 and `check-cfi` all pass.

Added: 
    

Modified: 
    compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
    compiler-rt/lib/cfi/cfi.cpp
    compiler-rt/test/cfi/cross-dso/icall/dlopen.cpp
    compiler-rt/test/cfi/cross-dso/icall/lit.local.cfg.py
    compiler-rt/test/cfi/icall/lit.local.cfg.py

Removed: 
    


################################################################################
diff  --git a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
index 59c322002d3cd37..e8ab660c1d83c0c 100644
--- a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
+++ b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
@@ -73,7 +73,7 @@ set(ALL_UBSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV64}
 set(ALL_SAFESTACK_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM64} ${MIPS32} ${MIPS64}
     ${HEXAGON} ${LOONGARCH64})
 set(ALL_CFI_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${MIPS64}
-    ${HEXAGON})
+    ${HEXAGON} ${LOONGARCH64})
 set(ALL_SCUDO_STANDALONE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
     ${MIPS32} ${MIPS64} ${PPC64} ${HEXAGON} ${LOONGARCH64} ${RISCV64})
 if(APPLE)

diff  --git a/compiler-rt/lib/cfi/cfi.cpp b/compiler-rt/lib/cfi/cfi.cpp
index 22f0b175dd87d9a..ad1c91623514e8f 100644
--- a/compiler-rt/lib/cfi/cfi.cpp
+++ b/compiler-rt/lib/cfi/cfi.cpp
@@ -51,7 +51,11 @@ using namespace __sanitizer;
 
 namespace __cfi {
 
+#if SANITIZER_LOONGARCH64
+#define kCfiShadowLimitsStorageSize 16384 // 16KiB on loongarch64 per page
+#else
 #define kCfiShadowLimitsStorageSize 4096 // 1 page
+#endif
 // Lets hope that the data segment is mapped with 4K pages.
 // The pointer to the cfi shadow region is stored at the start of this page.
 // The rest of the page is unused and re-mapped read-only.

diff  --git a/compiler-rt/test/cfi/cross-dso/icall/dlopen.cpp b/compiler-rt/test/cfi/cross-dso/icall/dlopen.cpp
index c9674c3fb412a2a..d04f7ba5dd0e06c 100644
--- a/compiler-rt/test/cfi/cross-dso/icall/dlopen.cpp
+++ b/compiler-rt/test/cfi/cross-dso/icall/dlopen.cpp
@@ -53,6 +53,13 @@ struct A {
   virtual void f();
 };
 
+// The page size of LoongArch is 16KiB, aligned to the memory page size.
+#ifdef __loongarch__
+#  define PAGESIZE 16384
+#else
+#  define PAGESIZE 4096
+#endif
+
 #ifdef SHARED_LIB
 
 #include "../../utils.h"
@@ -66,13 +73,13 @@ extern "C" void *create_B() {
   return (void *)(new B());
 }
 
-extern "C" __attribute__((aligned(4096))) void do_nothing() {}
+extern "C" __attribute__((aligned(PAGESIZE))) void do_nothing() {}
 
 #else
 
 void A::f() {}
 
-static const int kCodeAlign = 4096;
+static const int kCodeAlign = PAGESIZE;
 static const int kCodeSize = 4096;
 static char saved_code[kCodeSize];
 static char *real_start;

diff  --git a/compiler-rt/test/cfi/cross-dso/icall/lit.local.cfg.py b/compiler-rt/test/cfi/cross-dso/icall/lit.local.cfg.py
index 749c265bbf1c0c0..6e64199ed5c5043 100644
--- a/compiler-rt/test/cfi/cross-dso/icall/lit.local.cfg.py
+++ b/compiler-rt/test/cfi/cross-dso/icall/lit.local.cfg.py
@@ -1,3 +1,3 @@
 # The cfi-icall checker is only supported on x86 and x86_64 for now.
-if config.root.host_arch not in ["x86", "x86_64"]:
+if config.root.host_arch not in ["x86", "x86_64", "loongarch64"]:
     config.unsupported = True

diff  --git a/compiler-rt/test/cfi/icall/lit.local.cfg.py b/compiler-rt/test/cfi/icall/lit.local.cfg.py
index 749c265bbf1c0c0..6e64199ed5c5043 100644
--- a/compiler-rt/test/cfi/icall/lit.local.cfg.py
+++ b/compiler-rt/test/cfi/icall/lit.local.cfg.py
@@ -1,3 +1,3 @@
 # The cfi-icall checker is only supported on x86 and x86_64 for now.
-if config.root.host_arch not in ["x86", "x86_64"]:
+if config.root.host_arch not in ["x86", "x86_64", "loongarch64"]:
     config.unsupported = True


        


More information about the llvm-commits mailing list