[compiler-rt] 921009e - [MSan] Enable for SystemZ
Ilya Leoshkevich via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 16 03:15:24 PDT 2020
Author: Ilya Leoshkevich
Date: 2020-04-16T12:15:01+02:00
New Revision: 921009e66798f8a40b59d4e7c63545adaead0f54
URL: https://github.com/llvm/llvm-project/commit/921009e66798f8a40b59d4e7c63545adaead0f54
DIFF: https://github.com/llvm/llvm-project/commit/921009e66798f8a40b59d4e7c63545adaead0f54.diff
LOG: [MSan] Enable for SystemZ
Summary:
This patch adds runtime support, adjusts tests and enables MSan.
Like for ASan and UBSan, compile the tests with -mbackchain.
Reviewers: eugenis, uweigand, jonpa, vitalybuka
Reviewed By: eugenis, vitalybuka
Subscribers: vitalybuka, mgorny, hiraditya, #sanitizers, stefansf, Andreas-Krebbel
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D76358
Added:
Modified:
compiler-rt/cmake/config-ix.cmake
compiler-rt/lib/msan/msan.h
compiler-rt/lib/msan/msan_allocator.cpp
compiler-rt/test/msan/backtrace.cpp
compiler-rt/test/msan/lit.cfg.py
compiler-rt/test/msan/mmap.cpp
compiler-rt/test/msan/mmap_below_shadow.cpp
compiler-rt/test/msan/param_tls_limit.cpp
compiler-rt/test/msan/strlen_of_shadow.cpp
Removed:
################################################################################
diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake
index 8261bc9fcdd5..ef62d701dee2 100644
--- a/compiler-rt/cmake/config-ix.cmake
+++ b/compiler-rt/cmake/config-ix.cmake
@@ -305,7 +305,7 @@ if(APPLE)
else()
set(ALL_LSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${MIPS64} ${ARM64} ${ARM32} ${PPC64})
endif()
-set(ALL_MSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${PPC64})
+set(ALL_MSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${PPC64} ${S390X})
set(ALL_HWASAN_SUPPORTED_ARCH ${X86_64} ${ARM64})
set(ALL_PROFILE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${PPC64}
${MIPS32} ${MIPS64} ${S390X} ${SPARC} ${SPARCV9})
diff --git a/compiler-rt/lib/msan/msan.h b/compiler-rt/lib/msan/msan.h
index 12aeaa43519a..e794c7c15f89 100644
--- a/compiler-rt/lib/msan/msan.h
+++ b/compiler-rt/lib/msan/msan.h
@@ -181,6 +181,20 @@ const MappingDesc kMemoryLayout[] = {
#define MEM_TO_SHADOW(mem) (LINEARIZE_MEM((mem)) + 0x080000000000ULL)
#define SHADOW_TO_ORIGIN(shadow) (((uptr)(shadow)) + 0x140000000000ULL)
+#elif SANITIZER_LINUX && SANITIZER_S390_64
+const MappingDesc kMemoryLayout[] = {
+ {0x000000000000ULL, 0x040000000000ULL, MappingDesc::APP, "low memory"},
+ {0x040000000000ULL, 0x080000000000ULL, MappingDesc::INVALID, "invalid"},
+ {0x080000000000ULL, 0x180000000000ULL, MappingDesc::SHADOW, "shadow"},
+ {0x180000000000ULL, 0x1C0000000000ULL, MappingDesc::INVALID, "invalid"},
+ {0x1C0000000000ULL, 0x2C0000000000ULL, MappingDesc::ORIGIN, "origin"},
+ {0x2C0000000000ULL, 0x440000000000ULL, MappingDesc::INVALID, "invalid"},
+ {0x440000000000ULL, 0x500000000000ULL, MappingDesc::APP, "high memory"}};
+
+#define MEM_TO_SHADOW(mem) \
+ ((((uptr)(mem)) & ~0xC00000000000ULL) + 0x080000000000ULL)
+#define SHADOW_TO_ORIGIN(shadow) (((uptr)(shadow)) + 0x140000000000ULL)
+
#elif SANITIZER_FREEBSD && SANITIZER_WORDSIZE == 64
// Low memory: main binary, MAP_32BIT mappings and modules
diff --git a/compiler-rt/lib/msan/msan_allocator.cpp b/compiler-rt/lib/msan/msan_allocator.cpp
index a08c1a00d2e5..68be794106b1 100644
--- a/compiler-rt/lib/msan/msan_allocator.cpp
+++ b/compiler-rt/lib/msan/msan_allocator.cpp
@@ -92,6 +92,20 @@ struct AP64 { // Allocator64 parameters. Deliberately using a short name.
using AddressSpaceView = LocalAddressSpaceView;
};
+typedef SizeClassAllocator64<AP64> PrimaryAllocator;
+#elif defined(__s390x__)
+static const uptr kMaxAllowedMallocSize = 2UL << 30; // 2G
+
+struct AP64 { // Allocator64 parameters. Deliberately using a short name.
+ static const uptr kSpaceBeg = 0x440000000000;
+ static const uptr kSpaceSize = 0x020000000000; // 2T.
+ static const uptr kMetadataSize = sizeof(Metadata);
+ typedef DefaultSizeClassMap SizeClassMap;
+ typedef MsanMapUnmapCallback MapUnmapCallback;
+ static const uptr kFlags = 0;
+ using AddressSpaceView = LocalAddressSpaceView;
+};
+
typedef SizeClassAllocator64<AP64> PrimaryAllocator;
#elif defined(__aarch64__)
static const uptr kMaxAllowedMallocSize = 2UL << 30; // 2G
diff --git a/compiler-rt/test/msan/backtrace.cpp b/compiler-rt/test/msan/backtrace.cpp
index cde4e8fc1c9e..7a8e041b3396 100644
--- a/compiler-rt/test/msan/backtrace.cpp
+++ b/compiler-rt/test/msan/backtrace.cpp
@@ -12,8 +12,14 @@ void f() {
int sz = backtrace(buf, sizeof(buf) / sizeof(*buf));
assert(sz > 0);
for (int i = 0; i < sz; ++i)
- if (!buf[i])
+ if (!buf[i]) {
+#if defined(__s390x__)
+ // backtrace() may return a bogus trailing NULL on s390x.
+ if (i == sz - 1)
+ continue;
+#endif
exit(1);
+ }
char **s = backtrace_symbols(buf, sz);
assert(s != 0);
for (int i = 0; i < sz; ++i)
diff --git a/compiler-rt/test/msan/lit.cfg.py b/compiler-rt/test/msan/lit.cfg.py
index 0b43d0810d89..8ec1614be130 100644
--- a/compiler-rt/test/msan/lit.cfg.py
+++ b/compiler-rt/test/msan/lit.cfg.py
@@ -18,6 +18,9 @@
# Some Msan tests leverage backtrace() which requires libexecinfo on FreeBSD.
if config.host_os == 'FreeBSD':
clang_msan_cflags += ["-lexecinfo", "-fPIC"]
+# On SystemZ we need -mbackchain to make the fast unwinder work.
+if config.target_arch == 's390x':
+ clang_msan_cflags.append("-mbackchain")
clang_msan_cxxflags = config.cxx_mode_flags + clang_msan_cflags
# Flags for KMSAN invocation. This is C-only, we're not interested in C++.
diff --git a/compiler-rt/test/msan/mmap.cpp b/compiler-rt/test/msan/mmap.cpp
index d83423735211..2e7e883c863a 100644
--- a/compiler-rt/test/msan/mmap.cpp
+++ b/compiler-rt/test/msan/mmap.cpp
@@ -24,6 +24,9 @@ bool AddrIsApp(void *p) {
addr >= 0xe200000000ULL;
#elif defined(__powerpc64__)
return addr < 0x000100000000ULL || addr >= 0x300000000000ULL;
+#elif defined(__s390x__)
+ return addr < 0x040000000000ULL ||
+ (addr >= 0x440000000000ULL && addr < 0x500000000000);
#elif defined(__aarch64__)
struct AddrMapping {
diff --git a/compiler-rt/test/msan/mmap_below_shadow.cpp b/compiler-rt/test/msan/mmap_below_shadow.cpp
index 806b19da8ca6..46d948c9a5eb 100644
--- a/compiler-rt/test/msan/mmap_below_shadow.cpp
+++ b/compiler-rt/test/msan/mmap_below_shadow.cpp
@@ -27,6 +27,9 @@ int main(void) {
#elif defined (__powerpc64__)
uintptr_t hint = 0x2f0000000000ULL;
const uintptr_t app_start = 0x300000000000ULL;
+#elif defined(__s390x__)
+ uintptr_t hint = 0x07f000000000ULL;
+ const uintptr_t app_start = 0x020000000000ULL;
#elif defined (__aarch64__)
uintptr_t hint = 0x4f0000000ULL;
const uintptr_t app_start = 0x7000000000ULL;
diff --git a/compiler-rt/test/msan/param_tls_limit.cpp b/compiler-rt/test/msan/param_tls_limit.cpp
index d34376a1f0c4..43e66858e26f 100644
--- a/compiler-rt/test/msan/param_tls_limit.cpp
+++ b/compiler-rt/test/msan/param_tls_limit.cpp
@@ -8,6 +8,12 @@
// AArch64 fails with:
// void f801(S<801>): Assertion `__msan_test_shadow(&s, sizeof(s)) == -1' failed
// XFAIL: aarch64
+// When passing huge structs by value, SystemZ uses pointers, therefore this
+// test in its present form is unfortunately not applicable.
+// ABI says: "A struct or union of any other size <snip>. Replace such an
+// argument by a pointer to the object, or to a copy where necessary to enforce
+// call-by-value semantics."
+// XFAIL: s390x
#include <sanitizer/msan_interface.h>
#include <assert.h>
diff --git a/compiler-rt/test/msan/strlen_of_shadow.cpp b/compiler-rt/test/msan/strlen_of_shadow.cpp
index 718cc08dc1fd..5e7c89c7b59f 100644
--- a/compiler-rt/test/msan/strlen_of_shadow.cpp
+++ b/compiler-rt/test/msan/strlen_of_shadow.cpp
@@ -21,6 +21,8 @@ const char *mem_to_shadow(const char *p) {
#define LINEARIZE_MEM(mem) \
(((uintptr_t)(mem) & ~0x200000000000ULL) ^ 0x100000000000ULL)
return (char *)(LINEARIZE_MEM(p) + 0x080000000000ULL);
+#elif defined(__s390x__)
+ return (char *)(((uintptr_t)p & ~0xC00000000000ULL) + 0x080000000000ULL);
#elif defined(__aarch64__)
return (char *)((uintptr_t)p ^ 0x6000000000ULL);
#endif
More information about the llvm-commits
mailing list