@@ -119,6 +119,9 @@ static const uint64_t kNetBSDKasan_ShadowOffset64 = 0xdfff900000000000;
119
119
static const uint64_t kPS_ShadowOffset64 = 1ULL << 40 ;
120
120
static const uint64_t kWindowsShadowOffset32 = 3ULL << 28 ;
121
121
static const uint64_t kEmscriptenShadowOffset = 0 ;
122
+ static const uint64_t kAIXShadowOffset32 = 0x40000000 ;
123
+ // 64-BIT AIX is not yet ready.
124
+ static const uint64_t kAIXShadowOffset64 = 0x0a01000000000000ULL ;
122
125
123
126
// The shadow memory space is dynamically allocated.
124
127
static const uint64_t kWindowsShadowOffset64 = kDynamicShadowSentinel ;
@@ -128,6 +131,8 @@ static const size_t kMaxStackMallocSize = 1 << 16; // 64K
128
131
static const uintptr_t kCurrentStackFrameMagic = 0x41B58AB3 ;
129
132
static const uintptr_t kRetiredStackFrameMagic = 0x45E0360E ;
130
133
134
+ static const uint32_t kAIXHighBits = 6 ;
135
+
131
136
const char kAsanModuleCtorName [] = " asan.module_ctor" ;
132
137
const char kAsanModuleDtorName [] = " asan.module_dtor" ;
133
138
static const uint64_t kAsanCtorAndDtorPriority = 1 ;
@@ -463,11 +468,14 @@ namespace {
463
468
464
469
// / This struct defines the shadow mapping using the rule:
465
470
// / shadow = (mem >> Scale) ADD-or-OR Offset.
471
+ // / However, on 64-bit AIX, we use HighBits to reduce the mapped address space:
472
+ // / shadow = ((mem << HighBits) >> (HighBits + Scale)) + Offset
466
473
// / If InGlobal is true, then
467
474
// / extern char __asan_shadow[];
468
475
// / shadow = (mem >> Scale) + &__asan_shadow
469
476
struct ShadowMapping {
470
477
int Scale;
478
+ int HighBits;
471
479
uint64_t Offset;
472
480
bool OrShadowOffset;
473
481
bool InGlobal;
@@ -487,6 +495,7 @@ static ShadowMapping getShadowMapping(const Triple &TargetTriple, int LongSize,
487
495
bool IsLinux = TargetTriple.isOSLinux ();
488
496
bool IsPPC64 = TargetTriple.getArch () == Triple::ppc64 ||
489
497
TargetTriple.getArch () == Triple::ppc64le;
498
+ bool IsAIX = TargetTriple.isOSAIX ();
490
499
bool IsSystemZ = TargetTriple.getArch () == Triple::systemz;
491
500
bool IsX86_64 = TargetTriple.getArch () == Triple::x86_64;
492
501
bool IsMIPSN32ABI = TargetTriple.isABIN32 ();
@@ -526,14 +535,18 @@ static ShadowMapping getShadowMapping(const Triple &TargetTriple, int LongSize,
526
535
Mapping.Offset = kWindowsShadowOffset32 ;
527
536
else if (IsEmscripten)
528
537
Mapping.Offset = kEmscriptenShadowOffset ;
538
+ else if (IsAIX)
539
+ Mapping.Offset = kAIXShadowOffset32 ;
529
540
else
530
541
Mapping.Offset = kDefaultShadowOffset32 ;
531
542
} else { // LongSize == 64
532
543
// Fuchsia is always PIE, which means that the beginning of the address
533
544
// space is always available.
534
545
if (IsFuchsia)
535
546
Mapping.Offset = 0 ;
536
- else if (IsPPC64)
547
+ else if (IsAIX)
548
+ Mapping.Offset = kAIXShadowOffset64 ;
549
+ else if (IsPPC64 && !IsAIX)
537
550
Mapping.Offset = kPPC64_ShadowOffset64 ;
538
551
else if (IsSystemZ)
539
552
Mapping.Offset = kSystemZ_ShadowOffset64 ;
@@ -592,13 +605,16 @@ static ShadowMapping getShadowMapping(const Triple &TargetTriple, int LongSize,
592
605
// SystemZ, we could OR the constant in a single instruction, but it's more
593
606
// efficient to load it once and use indexed addressing.
594
607
Mapping.OrShadowOffset = !IsAArch64 && !IsPPC64 && !IsSystemZ && !IsPS &&
595
- !IsRISCV64 && !IsLoongArch64 &&
608
+ !IsRISCV64 && !IsLoongArch64 && !IsAIX &&
596
609
!(Mapping.Offset & (Mapping.Offset - 1 )) &&
597
610
Mapping.Offset != kDynamicShadowSentinel ;
598
611
bool IsAndroidWithIfuncSupport =
599
612
IsAndroid && !TargetTriple.isAndroidVersionLT (21 );
600
613
Mapping.InGlobal = ClWithIfunc && IsAndroidWithIfuncSupport && IsArmOrThumb;
601
614
615
+ if (IsAIX && LongSize == 64 )
616
+ Mapping.HighBits = kAIXHighBits ;
617
+
602
618
return Mapping;
603
619
}
604
620
@@ -1326,7 +1342,11 @@ static bool isUnsupportedAMDGPUAddrspace(Value *Addr) {
1326
1342
1327
1343
Value *AddressSanitizer::memToShadow (Value *Shadow, IRBuilder<> &IRB) {
1328
1344
// Shadow >> scale
1329
- Shadow = IRB.CreateLShr (Shadow, Mapping.Scale );
1345
+ if (TargetTriple.isOSAIX () && TargetTriple.getArch () == Triple::ppc64)
1346
+ Shadow = IRB.CreateLShr (IRB.CreateShl (Shadow, Mapping.HighBits ),
1347
+ Mapping.Scale + Mapping.HighBits );
1348
+ else
1349
+ Shadow = IRB.CreateLShr (Shadow, Mapping.Scale );
1330
1350
if (Mapping.Offset == 0 ) return Shadow;
1331
1351
// (Shadow >> scale) | offset
1332
1352
Value *ShadowBase;
0 commit comments