Skip to content

Commit

Permalink
[CFI] Allow LoongArch (#67314)
Browse files Browse the repository at this point in the history
Enable icall tests on loongarch64 and `check-cfi` all pass.
  • Loading branch information
Ami-zhang committed Sep 28, 2023
1 parent 8aa8604 commit adb555e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions compiler-rt/lib/cfi/cfi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 9 additions & 2 deletions compiler-rt/test/cfi/cross-dso/icall/dlopen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/test/cfi/cross-dso/icall/lit.local.cfg.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion compiler-rt/test/cfi/icall/lit.local.cfg.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit adb555e

Please sign in to comment.