Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 04df7c1

Browse files
committed
[asan] Add iOS support to AddressSanitzier
Differential Revision: http://reviews.llvm.org/D15625 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@259586 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 524fa2e commit 04df7c1

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,11 @@ using namespace llvm;
6565

6666
static const uint64_t kDefaultShadowScale = 3;
6767
static const uint64_t kDefaultShadowOffset32 = 1ULL << 29;
68-
static const uint64_t kIOSShadowOffset32 = 1ULL << 30;
6968
static const uint64_t kDefaultShadowOffset64 = 1ULL << 44;
69+
static const uint64_t kIOSShadowOffset32 = 1ULL << 30;
70+
static const uint64_t kIOSShadowOffset64 = 0x120200000;
71+
static const uint64_t kIOSSimShadowOffset32 = 1ULL << 30;
72+
static const uint64_t kIOSSimShadowOffset64 = kDefaultShadowOffset64;
7073
static const uint64_t kSmallX86_64ShadowOffset = 0x7FFF8000; // < 2G.
7174
static const uint64_t kLinuxKasan_ShadowOffset64 = 0xdffffc0000000000;
7275
static const uint64_t kPPC64_ShadowOffset64 = 1ULL << 41;
@@ -334,11 +337,12 @@ struct ShadowMapping {
334337
static ShadowMapping getShadowMapping(Triple &TargetTriple, int LongSize,
335338
bool IsKasan) {
336339
bool IsAndroid = TargetTriple.isAndroid();
337-
bool IsIOS = TargetTriple.isiOS();
340+
bool IsIOS = TargetTriple.isiOS() || TargetTriple.isWatchOS();
338341
bool IsFreeBSD = TargetTriple.isOSFreeBSD();
339342
bool IsLinux = TargetTriple.isOSLinux();
340343
bool IsPPC64 = TargetTriple.getArch() == llvm::Triple::ppc64 ||
341344
TargetTriple.getArch() == llvm::Triple::ppc64le;
345+
bool IsX86 = TargetTriple.getArch() == llvm::Triple::x86;
342346
bool IsX86_64 = TargetTriple.getArch() == llvm::Triple::x86_64;
343347
bool IsMIPS32 = TargetTriple.getArch() == llvm::Triple::mips ||
344348
TargetTriple.getArch() == llvm::Triple::mipsel;
@@ -359,7 +363,8 @@ static ShadowMapping getShadowMapping(Triple &TargetTriple, int LongSize,
359363
else if (IsFreeBSD)
360364
Mapping.Offset = kFreeBSD_ShadowOffset32;
361365
else if (IsIOS)
362-
Mapping.Offset = kIOSShadowOffset32;
366+
// If we're targeting iOS and x86, the binary is built for iOS simulator.
367+
Mapping.Offset = IsX86 ? kIOSSimShadowOffset32 : kIOSShadowOffset32;
363368
else if (IsWindows)
364369
Mapping.Offset = kWindowsShadowOffset32;
365370
else
@@ -376,6 +381,9 @@ static ShadowMapping getShadowMapping(Triple &TargetTriple, int LongSize,
376381
Mapping.Offset = kSmallX86_64ShadowOffset;
377382
} else if (IsMIPS64)
378383
Mapping.Offset = kMIPS64_ShadowOffset64;
384+
else if (IsIOS)
385+
// If we're targeting iOS and x86, the binary is built for iOS simulator.
386+
Mapping.Offset = IsX86_64 ? kIOSSimShadowOffset64 : kIOSShadowOffset64;
379387
else if (IsAArch64)
380388
Mapping.Offset = kAArch64_ShadowOffset64;
381389
else

0 commit comments

Comments
 (0)