mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-27 00:21:03 +00:00
More MSan/ASan annotations.
This change lets us bootstrap LLVM/Clang under ASan and MSan. It contains fixes for 2 issues: - X86JIT reads return address from stack, which MSan does not know is initialized. - bugpoint tests run binaries with RLIMIT_AS. This does not work with certain Sanitizers. We are no longer including config.h in Compiler.h with this change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174306 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -468,9 +468,6 @@
|
|||||||
/* Define to 1 if the system has the type `u_int64_t'. */
|
/* Define to 1 if the system has the type `u_int64_t'. */
|
||||||
#cmakedefine HAVE_U_INT64_T ${HAVE_U_INT64_T}
|
#cmakedefine HAVE_U_INT64_T ${HAVE_U_INT64_T}
|
||||||
|
|
||||||
/* Define to 1 if you have the <sanitizer/msan_interface.h> header file. */
|
|
||||||
#cmakedefine HAVE_SANITIZER_MSAN_INTERFACE_H ${HAVE_SANITIZER_MSAN_INTERFACE_H}
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <valgrind/valgrind.h> header file. */
|
/* Define to 1 if you have the <valgrind/valgrind.h> header file. */
|
||||||
#cmakedefine HAVE_VALGRIND_VALGRIND_H ${HAVE_VALGRIND_VALGRIND_H}
|
#cmakedefine HAVE_VALGRIND_VALGRIND_H ${HAVE_VALGRIND_VALGRIND_H}
|
||||||
|
|
||||||
|
@@ -124,4 +124,7 @@
|
|||||||
/* Minor version of the LLVM API */
|
/* Minor version of the LLVM API */
|
||||||
#cmakedefine LLVM_VERSION_MINOR ${LLVM_VERSION_MINOR}
|
#cmakedefine LLVM_VERSION_MINOR ${LLVM_VERSION_MINOR}
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <sanitizer/msan_interface.h> header file. */
|
||||||
|
#cmakedefine LLVM_HAVE_MSAN_ANNOTATIONS ${HAVE_SANITIZER_MSAN_INTERFACE_H}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
#ifndef LLVM_SUPPORT_COMPILER_H
|
#ifndef LLVM_SUPPORT_COMPILER_H
|
||||||
#define LLVM_SUPPORT_COMPILER_H
|
#define LLVM_SUPPORT_COMPILER_H
|
||||||
|
|
||||||
#include "llvm/Config/config.h"
|
#include "llvm/Config/llvm-config.h"
|
||||||
|
|
||||||
#ifndef __has_feature
|
#ifndef __has_feature
|
||||||
# define __has_feature(x) 0
|
# define __has_feature(x) 0
|
||||||
@@ -295,12 +295,11 @@
|
|||||||
# define LLVM_FUNCTION_NAME __func__
|
# define LLVM_FUNCTION_NAME __func__
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// \macro LLVM_ENABLE_MSAN_ANNOTATIONS
|
#if defined(LLVM_HAVE_MSAN_ANNOTATIONS)
|
||||||
/// \brief Are MemorySanitizer annotations available.
|
|
||||||
#if defined(HAVE_SANITIZER_MSAN_INTERFACE_H)
|
|
||||||
# include <sanitizer/msan_interface.h>
|
# include <sanitizer/msan_interface.h>
|
||||||
#else
|
#else
|
||||||
# define __msan_allocated_memory(p, size)
|
# define __msan_allocated_memory(p, size)
|
||||||
|
# define __msan_unpoison(p, size)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// \macro LLVM_MEMORY_SANITIZER_BUILD
|
/// \macro LLVM_MEMORY_SANITIZER_BUILD
|
||||||
@@ -311,6 +310,14 @@
|
|||||||
# define LLVM_MEMORY_SANITIZER_BUILD 0
|
# define LLVM_MEMORY_SANITIZER_BUILD 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/// \macro LLVM_ADDRESS_SANITIZER_BUILD
|
||||||
|
/// \brief Whether LLVM itself is built with AddressSanitizer instrumentation.
|
||||||
|
#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
|
||||||
|
# define LLVM_ADDRESS_SANITIZER_BUILD 1
|
||||||
|
#else
|
||||||
|
# define LLVM_ADDRESS_SANITIZER_BUILD 0
|
||||||
|
#endif
|
||||||
|
|
||||||
/// \macro LLVM_IS_UNALIGNED_ACCESS_FAST
|
/// \macro LLVM_IS_UNALIGNED_ACCESS_FAST
|
||||||
/// \brief Is unaligned memory access fast on the host machine.
|
/// \brief Is unaligned memory access fast on the host machine.
|
||||||
///
|
///
|
||||||
|
@@ -104,8 +104,8 @@ void *BumpPtrAllocator::Allocate(size_t Size, size_t Alignment) {
|
|||||||
if (Ptr + Size <= End) {
|
if (Ptr + Size <= End) {
|
||||||
CurPtr = Ptr + Size;
|
CurPtr = Ptr + Size;
|
||||||
// Update the allocation point of this memory block in MemorySanitizer.
|
// Update the allocation point of this memory block in MemorySanitizer.
|
||||||
// Without this, MemorySanitizer reports for values originating from it will
|
// Without this, MemorySanitizer messages for values originated from here
|
||||||
// point to the allocation point of the entire slab.
|
// will point to the allocation of the entire slab.
|
||||||
__msan_allocated_memory(Ptr, Size);
|
__msan_allocated_memory(Ptr, Size);
|
||||||
return Ptr;
|
return Ptr;
|
||||||
}
|
}
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "Unix.h"
|
#include "Unix.h"
|
||||||
|
#include "llvm/Support/Compiler.h"
|
||||||
#include "llvm/Support/FileSystem.h"
|
#include "llvm/Support/FileSystem.h"
|
||||||
#include <llvm/Config/config.h>
|
#include <llvm/Config/config.h>
|
||||||
#if HAVE_SYS_STAT_H
|
#if HAVE_SYS_STAT_H
|
||||||
@@ -164,12 +165,16 @@ static void SetMemoryLimits (unsigned size)
|
|||||||
setrlimit (RLIMIT_RSS, &r);
|
setrlimit (RLIMIT_RSS, &r);
|
||||||
#endif
|
#endif
|
||||||
#ifdef RLIMIT_AS // e.g. NetBSD doesn't have it.
|
#ifdef RLIMIT_AS // e.g. NetBSD doesn't have it.
|
||||||
|
// Don't set virtual memory limit if built with any Sanitizer. They need 80Tb
|
||||||
|
// of virtual memory for shadow memory mapping.
|
||||||
|
#if !LLVM_MEMORY_SANITIZER_BUILD && !LLVM_ADDRESS_SANITIZER_BUILD
|
||||||
// Virtual memory.
|
// Virtual memory.
|
||||||
getrlimit (RLIMIT_AS, &r);
|
getrlimit (RLIMIT_AS, &r);
|
||||||
r.rlim_cur = limit;
|
r.rlim_cur = limit;
|
||||||
setrlimit (RLIMIT_AS, &r);
|
setrlimit (RLIMIT_AS, &r);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@@ -351,6 +351,9 @@ static
|
|||||||
void LLVM_ATTRIBUTE_USED
|
void LLVM_ATTRIBUTE_USED
|
||||||
X86CompilationCallback2(intptr_t *StackPtr, intptr_t RetAddr) {
|
X86CompilationCallback2(intptr_t *StackPtr, intptr_t RetAddr) {
|
||||||
intptr_t *RetAddrLoc = &StackPtr[1];
|
intptr_t *RetAddrLoc = &StackPtr[1];
|
||||||
|
// We are reading raw stack data here. Tell MemorySanitizer that it is
|
||||||
|
// sufficiently initialized.
|
||||||
|
__msan_unpoison(RetAddrLoc, sizeof(*RetAddrLoc));
|
||||||
assert(*RetAddrLoc == RetAddr &&
|
assert(*RetAddrLoc == RetAddr &&
|
||||||
"Could not find return address on the stack!");
|
"Could not find return address on the stack!");
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user