Skip to content

Commit af13d1d

Browse files
kateinoigakukunsivan-shani
authored andcommitted
[clang] Support ASan on WASI (llvm#139014)
I'm working on porting ASan to Wasm/WASI targets, and this is the first part of the change sets. I'll post runtime changes separately. This change makes `-fsanitize=address` available for WASI target by replicating what we do for Emscripten because they share the same memory model.
1 parent 8dfaa6e commit af13d1d

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

clang/lib/Driver/ToolChains/WebAssembly.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,13 @@ void WebAssembly::AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
545545
SanitizerMask WebAssembly::getSupportedSanitizers() const {
546546
SanitizerMask Res = ToolChain::getSupportedSanitizers();
547547
if (getTriple().isOSEmscripten()) {
548-
Res |= SanitizerKind::Vptr | SanitizerKind::Leak | SanitizerKind::Address;
548+
Res |= SanitizerKind::Vptr | SanitizerKind::Leak;
549549
}
550+
551+
if (getTriple().isOSEmscripten() || getTriple().isOSWASI()) {
552+
Res |= SanitizerKind::Address;
553+
}
554+
550555
// -fsanitize=function places two words before the function label, which are
551556
// -unsupported.
552557
Res &= ~SanitizerKind::Function;

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static const uint64_t kNetBSD_ShadowOffset64 = 1ULL << 46;
118118
static const uint64_t kNetBSDKasan_ShadowOffset64 = 0xdfff900000000000;
119119
static const uint64_t kPS_ShadowOffset64 = 1ULL << 40;
120120
static const uint64_t kWindowsShadowOffset32 = 3ULL << 28;
121-
static const uint64_t kEmscriptenShadowOffset = 0;
121+
static const uint64_t kWebAssemblyShadowOffset = 0;
122122

123123
// The shadow memory space is dynamically allocated.
124124
static const uint64_t kWindowsShadowOffset64 = kDynamicShadowSentinel;
@@ -499,9 +499,9 @@ static ShadowMapping getShadowMapping(const Triple &TargetTriple, int LongSize,
499499
bool IsRISCV64 = TargetTriple.getArch() == Triple::riscv64;
500500
bool IsWindows = TargetTriple.isOSWindows();
501501
bool IsFuchsia = TargetTriple.isOSFuchsia();
502-
bool IsEmscripten = TargetTriple.isOSEmscripten();
503502
bool IsAMDGPU = TargetTriple.isAMDGPU();
504503
bool IsHaiku = TargetTriple.isOSHaiku();
504+
bool IsWasm = TargetTriple.isWasm();
505505

506506
ShadowMapping Mapping;
507507

@@ -525,8 +525,8 @@ static ShadowMapping getShadowMapping(const Triple &TargetTriple, int LongSize,
525525
Mapping.Offset = kDynamicShadowSentinel;
526526
else if (IsWindows)
527527
Mapping.Offset = kWindowsShadowOffset32;
528-
else if (IsEmscripten)
529-
Mapping.Offset = kEmscriptenShadowOffset;
528+
else if (IsWasm)
529+
Mapping.Offset = kWebAssemblyShadowOffset;
530530
else
531531
Mapping.Offset = kDefaultShadowOffset32;
532532
} else { // LongSize == 64

0 commit comments

Comments
 (0)