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

via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 25 04:29:04 PDT 2023


https://github.com/Ami-zhang created https://github.com/llvm/llvm-project/pull/67314

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

>From 258bfc27995da3d1dd91de5ded72ba3b42807425 Mon Sep 17 00:00:00 2001
From: zhanglimin <zhanglimin at loongson.cn>
Date: Thu, 31 Aug 2023 15:45:59 +0800
Subject: [PATCH] [CFI] Allow LoongArch

Enable icall tests on loongarch64 and `check-cfi` all pass.
---
 compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake  |  2 +-
 compiler-rt/lib/cfi/cfi.cpp                           |  4 ++++
 compiler-rt/test/cfi/cross-dso/icall/dlopen.cpp       | 11 +++++++++--
 compiler-rt/test/cfi/cross-dso/icall/lit.local.cfg.py |  2 +-
 compiler-rt/test/cfi/icall/lit.local.cfg.py           |  2 +-
 5 files changed, 16 insertions(+), 5 deletions(-)

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..3b989aae3994137 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 4096 * 4 // 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..5e6039c40129b5f 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 16KB, aligned to the memory page size.
+#ifdef __loongarch_lp64
+#  define PAGESIZE 4096 * 4
+#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