Skip to content

Commit adb555e

Browse files
authored
[CFI] Allow LoongArch (#67314)
Enable icall tests on loongarch64 and `check-cfi` all pass.
1 parent 8aa8604 commit adb555e

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ set(ALL_UBSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV64}
7373
set(ALL_SAFESTACK_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM64} ${MIPS32} ${MIPS64}
7474
${HEXAGON} ${LOONGARCH64})
7575
set(ALL_CFI_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${MIPS64}
76-
${HEXAGON})
76+
${HEXAGON} ${LOONGARCH64})
7777
set(ALL_SCUDO_STANDALONE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
7878
${MIPS32} ${MIPS64} ${PPC64} ${HEXAGON} ${LOONGARCH64} ${RISCV64})
7979
if(APPLE)

compiler-rt/lib/cfi/cfi.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ using namespace __sanitizer;
5151

5252
namespace __cfi {
5353

54+
#if SANITIZER_LOONGARCH64
55+
#define kCfiShadowLimitsStorageSize 16384 // 16KiB on loongarch64 per page
56+
#else
5457
#define kCfiShadowLimitsStorageSize 4096 // 1 page
58+
#endif
5559
// Lets hope that the data segment is mapped with 4K pages.
5660
// The pointer to the cfi shadow region is stored at the start of this page.
5761
// The rest of the page is unused and re-mapped read-only.

compiler-rt/test/cfi/cross-dso/icall/dlopen.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ struct A {
5353
virtual void f();
5454
};
5555

56+
// The page size of LoongArch is 16KiB, aligned to the memory page size.
57+
#ifdef __loongarch__
58+
# define PAGESIZE 16384
59+
#else
60+
# define PAGESIZE 4096
61+
#endif
62+
5663
#ifdef SHARED_LIB
5764

5865
#include "../../utils.h"
@@ -66,13 +73,13 @@ extern "C" void *create_B() {
6673
return (void *)(new B());
6774
}
6875

69-
extern "C" __attribute__((aligned(4096))) void do_nothing() {}
76+
extern "C" __attribute__((aligned(PAGESIZE))) void do_nothing() {}
7077

7178
#else
7279

7380
void A::f() {}
7481

75-
static const int kCodeAlign = 4096;
82+
static const int kCodeAlign = PAGESIZE;
7683
static const int kCodeSize = 4096;
7784
static char saved_code[kCodeSize];
7885
static char *real_start;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# The cfi-icall checker is only supported on x86 and x86_64 for now.
2-
if config.root.host_arch not in ["x86", "x86_64"]:
2+
if config.root.host_arch not in ["x86", "x86_64", "loongarch64"]:
33
config.unsupported = True
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# The cfi-icall checker is only supported on x86 and x86_64 for now.
2-
if config.root.host_arch not in ["x86", "x86_64"]:
2+
if config.root.host_arch not in ["x86", "x86_64", "loongarch64"]:
33
config.unsupported = True

0 commit comments

Comments
 (0)