Skip to content

Commit 3a58e11

Browse files
Youling TangSixWeining
authored andcommitted
[lsan] Add lsan support for loongarch64
This patch enabled lsan for loongarch64 with 47-bit VMA layout. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D139686
1 parent b7ae576 commit 3a58e11

File tree

9 files changed

+19
-6
lines changed

9 files changed

+19
-6
lines changed

clang/lib/Driver/ToolChains/Linux.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ SanitizerMask Linux::getSupportedSanitizers() const {
766766
if (IsX86_64 || IsMIPS64 || IsAArch64)
767767
Res |= SanitizerKind::DataFlow;
768768
if (IsX86_64 || IsMIPS64 || IsAArch64 || IsX86 || IsArmArch || IsPowerPC64 ||
769-
IsRISCV64 || IsSystemZ || IsHexagon)
769+
IsRISCV64 || IsSystemZ || IsHexagon || IsLoongArch64)
770770
Res |= SanitizerKind::Leak;
771771
if (IsX86_64 || IsMIPS64 || IsAArch64 || IsPowerPC64 || IsSystemZ ||
772772
IsLoongArch64)

clang/test/Driver/fsanitize.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,12 @@
430430
// RUN: %clang --target=riscv64-linux-gnu -fsanitize=address,leak -fno-sanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANA-SANL-NO-SANA-RISCV64
431431
// CHECK-SANA-SANL-NO-SANA-RISCV64: "-fsanitize=leak"
432432

433+
// RUN: %clang --target=loongarch64-unknown-linux-gnu -fsanitize=leak %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANL-LOONGARCH64
434+
// CHECK-SANL-LOONGARCH64: "-fsanitize=leak"
435+
436+
// RUN: %clang --target=loongarch64-unknown-linux-gnu -fsanitize=address,leak -fno-sanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANA-SANL-NO-SANA-LOONGARCH64
437+
// CHECK-SANA-SANL-NO-SANA-LOONGARCH64: "-fsanitize=leak"
438+
433439
// RUN: %clang --target=x86_64-linux-gnu -fsanitize=memory %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MSAN
434440
// CHECK-MSAN: "-fno-assume-sane-operator-new"
435441
// RUN: %clang --target=x86_64-linux-gnu -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN

compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ if(APPLE)
5252
set(ALL_LSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${MIPS64} ${ARM64})
5353
else()
5454
set(ALL_LSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${MIPS64} ${ARM64} ${ARM32}
55-
${PPC64} ${S390X} ${RISCV64} ${HEXAGON})
55+
${PPC64} ${S390X} ${RISCV64} ${HEXAGON} ${LOONGARCH64})
5656
endif()
5757
set(ALL_MSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${PPC64} ${S390X})
5858
set(ALL_HWASAN_SUPPORTED_ARCH ${X86_64} ${ARM64} ${RISCV64})

compiler-rt/lib/lsan/lsan_common.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ static inline bool MaybeUserPointer(uptr p) {
277277
# elif defined(__aarch64__)
278278
// Accept up to 48 bit VMA.
279279
return ((p >> 48) == 0);
280+
# elif defined(__loongarch_lp64)
281+
// Allow 47-bit user-space VMA at current.
282+
return ((p >> 47) == 0);
280283
# else
281284
return true;
282285
# endif

compiler-rt/lib/lsan/lsan_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
# define CAN_SANITIZE_LEAKS 1
4444
#elif defined(__arm__) && SANITIZER_LINUX
4545
# define CAN_SANITIZE_LEAKS 1
46+
#elif SANITIZER_LOONGARCH64 && SANITIZER_LINUX
47+
# define CAN_SANITIZE_LEAKS 1
4648
#elif SANITIZER_RISCV64 && SANITIZER_LINUX
4749
# define CAN_SANITIZE_LEAKS 1
4850
#elif SANITIZER_NETBSD || SANITIZER_FUCHSIA

compiler-rt/test/asan/lit.cfg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def build_invocation(compile_flags):
202202

203203
# Turn on leak detection on 64-bit Linux.
204204
leak_detection_android = config.android and 'android-thread-properties-api' in config.available_features and (config.target_arch in ['x86_64', 'i386', 'i686', 'aarch64'])
205-
leak_detection_linux = (config.host_os == 'Linux') and (not config.android) and (config.target_arch in ['x86_64', 'i386', 'riscv64'])
205+
leak_detection_linux = (config.host_os == 'Linux') and (not config.android) and (config.target_arch in ['x86_64', 'i386', 'riscv64', 'loongarch64'])
206206
leak_detection_mac = (config.host_os == 'Darwin') and (config.apple_platform == 'osx')
207207
leak_detection_netbsd = (config.host_os == 'NetBSD') and (config.target_arch in ['x86_64', 'i386'])
208208
if leak_detection_android or leak_detection_linux or leak_detection_mac or leak_detection_netbsd:

compiler-rt/test/lsan/TestCases/swapcontext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// RUN: %env_lsan_opts= %run %t 2>&1
66
// RUN: %env_lsan_opts= not %run %t foo 2>&1 | FileCheck %s
77
// Missing 'getcontext' and 'makecontext' on Android.
8-
// UNSUPPORTED: target={{(arm|aarch64|powerpc64).*}},android
8+
// UNSUPPORTED: target={{(arm|aarch64|loongarch64|powerpc64).*}},android
99

1010
#include "sanitizer_common/sanitizer_ucontext.h"
1111
#include <stdio.h>

compiler-rt/test/lsan/TestCases/use_registers.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ extern "C" void *registers_thread_func(void *arg) {
4343
"mov x14, %0"
4444
:
4545
: "r"(p));
46+
#elif defined(__loongarch_lp64)
47+
asm("move $s8, %0" : : "r"(p));
4648
#elif defined(__powerpc__)
4749
asm("mr 30, %0"
4850
:

compiler-rt/test/lsan/lit.common.cfg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ def build_invocation(compile_flags):
7474
config.substitutions.append( ("%clangxx_lsan ", build_invocation(clang_lsan_cxxflags)) )
7575

7676
# LeakSanitizer tests are currently supported on
77-
# Android{aarch64, x86, x86_64}, x86-64 Linux, PowerPC64 Linux, arm Linux, mips64 Linux, s390x Linux and x86_64 Darwin.
77+
# Android{aarch64, x86, x86_64}, x86-64 Linux, PowerPC64 Linux, arm Linux, mips64 Linux, s390x Linux, loongarch64 Linux and x86_64 Darwin.
7878
supported_android = config.android and config.target_arch in ['x86_64', 'i386', 'aarch64'] and 'android-thread-properties-api' in config.available_features
79-
supported_linux = (not config.android) and config.host_os == 'Linux' and config.host_arch in ['aarch64', 'x86_64', 'ppc64', 'ppc64le', 'mips64', 'riscv64', 'arm', 'armhf', 'armv7l', 's390x']
79+
supported_linux = (not config.android) and config.host_os == 'Linux' and config.host_arch in ['aarch64', 'x86_64', 'ppc64', 'ppc64le', 'mips64', 'riscv64', 'arm', 'armhf', 'armv7l', 's390x', 'loongarch64']
8080
supported_darwin = config.host_os == 'Darwin' and config.target_arch in ['x86_64']
8181
supported_netbsd = config.host_os == 'NetBSD' and config.target_arch in ['x86_64', 'i386']
8282
if not (supported_android or supported_linux or supported_darwin or supported_netbsd):

0 commit comments

Comments
 (0)