[asan] support for FreeBSD, LLVM part. patch by Viktor Kutuzov

llvm-svn: 201067
This commit is contained in:
Kostya Serebryany 2014-02-10 07:37:04 +00:00
parent 9f423d6f25
commit 8baa386670
2 changed files with 36 additions and 2 deletions

View File

@ -60,6 +60,8 @@ static const uint64_t kDefaultShadowOffset64 = 1ULL << 44;
static const uint64_t kDefaultShort64bitShadowOffset = 0x7FFF8000; // < 2G.
static const uint64_t kPPC64_ShadowOffset64 = 1ULL << 41;
static const uint64_t kMIPS32_ShadowOffset32 = 0x0aaa8000;
static const uint64_t kFreeBSD_ShadowOffset32 = 1ULL << 30;
static const uint64_t kFreeBSD_ShadowOffset64 = 1ULL << 46;
static const size_t kMinStackMallocSize = 1 << 6; // 64B
static const size_t kMaxStackMallocSize = 1 << 16; // 64K
@ -240,6 +242,7 @@ static ShadowMapping getShadowMapping(const Module &M, int LongSize) {
llvm::Triple TargetTriple(M.getTargetTriple());
bool IsAndroid = TargetTriple.getEnvironment() == llvm::Triple::Android;
bool IsMacOSX = TargetTriple.getOS() == llvm::Triple::MacOSX;
bool IsFreeBSD = TargetTriple.getOS() == llvm::Triple::FreeBSD;
bool IsPPC64 = TargetTriple.getArch() == llvm::Triple::ppc64 ||
TargetTriple.getArch() == llvm::Triple::ppc64le;
bool IsX86_64 = TargetTriple.getArch() == llvm::Triple::x86_64;
@ -255,11 +258,13 @@ static ShadowMapping getShadowMapping(const Module &M, int LongSize) {
Mapping.Offset = IsAndroid ? 0 :
(LongSize == 32 ?
(IsMIPS32 ? kMIPS32_ShadowOffset32 : kDefaultShadowOffset32) :
(IsMIPS32 ? kMIPS32_ShadowOffset32 :
(IsFreeBSD ? kFreeBSD_ShadowOffset32 : kDefaultShadowOffset32)) :
IsPPC64 ? kPPC64_ShadowOffset64 : kDefaultShadowOffset64);
if (!IsAndroid && ClShort64BitOffset && IsX86_64 && !IsMacOSX) {
assert(LongSize == 64);
Mapping.Offset = kDefaultShort64bitShadowOffset;
Mapping.Offset = (IsFreeBSD ?
kFreeBSD_ShadowOffset64 : kDefaultShort64bitShadowOffset);
}
if (!IsAndroid && ClMappingOffsetLog >= 0) {
// Zero offset log is the special case.

View File

@ -0,0 +1,29 @@
; RUN: opt < %s -asan -S \
; RUN: -mtriple=i386-unknown-freebsd \
; RUN: -default-data-layout="e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128" | \
; RUN: FileCheck --check-prefix=CHECK-32 %s
; RUN: opt < %s -asan -S \
; RUN: -mtriple=x86_64-unknown-freebsd \
; RUN: -default-data-layout="e-m:e-i64:64-f80:128-n8:16:32:64-S128" | \
; RUN: FileCheck --check-prefix=CHECK-64 %s
define i32 @read_4_bytes(i32* %a) sanitize_address {
entry:
%tmp1 = load i32* %a, align 4
ret i32 %tmp1
}
; CHECK-32: @read_4_bytes
; CHECK-32-NOT: ret
; Check for ASAN's Offset for 32-bit (2^30 or 0x40000000)
; CHECK-32: lshr {{.*}} 3
; CHECK-32-NEXT: {{1073741824}}
; CHECK-32: ret
; CHECK-64: @read_4_bytes
; CHECK-64-NOT: ret
; Check for ASAN's Offset for 64-bit (2^46 or 0x400000000000)
; CHECK-64: lshr {{.*}} 3
; CHECK-64-NEXT: {{70368744177664}}
; CHECK-64: ret