Skip to content

Commit 46d1258

Browse files
committed
[llvm] Implement address sanitizer on AIX (2/3)
The PR includes llvm changes needed for the address sanitizer on AIX.
1 parent 8e6fa15 commit 46d1258

File tree

6 files changed

+34
-10
lines changed

6 files changed

+34
-10
lines changed

llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ DIGlobal SymbolizableObjectFile::symbolizeData(
331331
std::string FileName;
332332
getNameFromSymbolTable(ModuleOffset.Address, Res.Name, Res.Start, Res.Size,
333333
FileName);
334-
Res.DeclFile = FileName;
334+
Res.DeclFile = FileName.empty() ? Res.Name : FileName;
335335

336336
// Try and get a better filename:lineno pair from the debuginfo, if present.
337337
DILineInfo DL = DebugInfoContext->getLineInfoForDataAddress(ModuleOffset);

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ static const uint64_t kNetBSDKasan_ShadowOffset64 = 0xdfff900000000000;
119119
static const uint64_t kPS_ShadowOffset64 = 1ULL << 40;
120120
static const uint64_t kWindowsShadowOffset32 = 3ULL << 28;
121121
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;
122125

123126
// The shadow memory space is dynamically allocated.
124127
static const uint64_t kWindowsShadowOffset64 = kDynamicShadowSentinel;
@@ -128,6 +131,8 @@ static const size_t kMaxStackMallocSize = 1 << 16; // 64K
128131
static const uintptr_t kCurrentStackFrameMagic = 0x41B58AB3;
129132
static const uintptr_t kRetiredStackFrameMagic = 0x45E0360E;
130133

134+
static const uint32_t kAIXHighBits = 6;
135+
131136
const char kAsanModuleCtorName[] = "asan.module_ctor";
132137
const char kAsanModuleDtorName[] = "asan.module_dtor";
133138
static const uint64_t kAsanCtorAndDtorPriority = 1;
@@ -468,6 +473,7 @@ namespace {
468473
/// shadow = (mem >> Scale) + &__asan_shadow
469474
struct ShadowMapping {
470475
int Scale;
476+
int HighBits;
471477
uint64_t Offset;
472478
bool OrShadowOffset;
473479
bool InGlobal;
@@ -487,6 +493,7 @@ static ShadowMapping getShadowMapping(const Triple &TargetTriple, int LongSize,
487493
bool IsLinux = TargetTriple.isOSLinux();
488494
bool IsPPC64 = TargetTriple.getArch() == Triple::ppc64 ||
489495
TargetTriple.getArch() == Triple::ppc64le;
496+
bool IsAIX = TargetTriple.isOSAIX();
490497
bool IsSystemZ = TargetTriple.getArch() == Triple::systemz;
491498
bool IsX86_64 = TargetTriple.getArch() == Triple::x86_64;
492499
bool IsMIPSN32ABI = TargetTriple.isABIN32();
@@ -526,14 +533,18 @@ static ShadowMapping getShadowMapping(const Triple &TargetTriple, int LongSize,
526533
Mapping.Offset = kWindowsShadowOffset32;
527534
else if (IsEmscripten)
528535
Mapping.Offset = kEmscriptenShadowOffset;
536+
else if (IsAIX)
537+
Mapping.Offset = kAIXShadowOffset32;
529538
else
530539
Mapping.Offset = kDefaultShadowOffset32;
531540
} else { // LongSize == 64
532541
// Fuchsia is always PIE, which means that the beginning of the address
533542
// space is always available.
534543
if (IsFuchsia)
535544
Mapping.Offset = 0;
536-
else if (IsPPC64)
545+
else if (IsAIX)
546+
Mapping.Offset = kAIXShadowOffset64;
547+
else if (IsPPC64 && !IsAIX)
537548
Mapping.Offset = kPPC64_ShadowOffset64;
538549
else if (IsSystemZ)
539550
Mapping.Offset = kSystemZ_ShadowOffset64;
@@ -592,13 +603,16 @@ static ShadowMapping getShadowMapping(const Triple &TargetTriple, int LongSize,
592603
// SystemZ, we could OR the constant in a single instruction, but it's more
593604
// efficient to load it once and use indexed addressing.
594605
Mapping.OrShadowOffset = !IsAArch64 && !IsPPC64 && !IsSystemZ && !IsPS &&
595-
!IsRISCV64 && !IsLoongArch64 &&
606+
!IsRISCV64 && !IsLoongArch64 && !IsAIX &&
596607
!(Mapping.Offset & (Mapping.Offset - 1)) &&
597608
Mapping.Offset != kDynamicShadowSentinel;
598609
bool IsAndroidWithIfuncSupport =
599610
IsAndroid && !TargetTriple.isAndroidVersionLT(21);
600611
Mapping.InGlobal = ClWithIfunc && IsAndroidWithIfuncSupport && IsArmOrThumb;
601612

613+
if (IsAIX && LongSize == 64)
614+
Mapping.HighBits = kAIXHighBits;
615+
602616
return Mapping;
603617
}
604618

@@ -1326,7 +1340,11 @@ static bool isUnsupportedAMDGPUAddrspace(Value *Addr) {
13261340

13271341
Value *AddressSanitizer::memToShadow(Value *Shadow, IRBuilder<> &IRB) {
13281342
// Shadow >> scale
1329-
Shadow = IRB.CreateLShr(Shadow, Mapping.Scale);
1343+
if (TargetTriple.isOSAIX() && TargetTriple.getArch() == Triple::ppc64)
1344+
Shadow = IRB.CreateLShr(IRB.CreateShl(Shadow, Mapping.HighBits),
1345+
Mapping.Scale + Mapping.HighBits);
1346+
else
1347+
Shadow = IRB.CreateLShr(Shadow, Mapping.Scale);
13301348
if (Mapping.Offset == 0) return Shadow;
13311349
// (Shadow >> scale) | offset
13321350
Value *ShadowBase;

llvm/test/DebugInfo/Symbolize/ELF/data-command-symtab.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88
# CHECK: func
99
# CHECK-NEXT: 4096 1
10-
# CHECK-NEXT: ??:?
10+
# CHECK-NEXT: func:0
1111
# CHECK-EMPTY:
1212
# CHECK-NEXT: data
1313
# CHECK-NEXT: 8192 2
14-
# CHECK-NEXT: ??:?
14+
# CHECK-NEXT: data:0
1515
# CHECK-EMPTY:
1616
# CHECK-NEXT: notype
1717
# CHECK-NEXT: 8194 3
18-
# CHECK-NEXT: ??:?
18+
# CHECK-NEXT: notype:0
1919
# CHECK-EMPTY:
2020

2121
--- !ELF

llvm/test/DebugInfo/Symbolize/ELF/symtab-file2.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Symbols:
7474

7575
# CHECK3: code
7676
# CHECK3-NEXT: 4096 2
77-
# CHECK3-NEXT: ??:?
77+
# CHECK3-NEXT: code:0
7878
# CHECK3-EMPTY:
7979

8080
--- !ELF

llvm/test/tools/llvm-symbolizer/data.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
# CHECK: d1
99
# CHECK-NEXT: 0 8
10-
# CHECK-NEXT: ??:?
10+
# CHECK-NEXT: d1:0
1111
# CHECK-EMPTY:
1212
# CHECK-NEXT: d2
1313
# CHECK-NEXT: 8 4
14-
# CHECK-NEXT: ??:?
14+
# CHECK-NEXT: d2:0
1515
# CHECK-EMPTY:
1616

1717
d1:

llvm/tools/llvm-nm/llvm-nm.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,12 @@ static void printLineNumbers(symbolize::LLVMSymbolizer &Symbolizer,
697697
return;
698698
break;
699699
}
700+
case 'a':
701+
return;
702+
case 'd':
703+
return;
704+
case 'r':
705+
return;
700706
case 't':
701707
case 'T': {
702708
Expected<DILineInfo> ResOrErr = Symbolizer.symbolizeCode(*Obj, Address);

0 commit comments

Comments
 (0)