Skip to content

Commit 51fbd66

Browse files
[clang] Support ASan on WASI
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 39f51c7 commit 51fbd66

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
@@ -542,8 +542,13 @@ void WebAssembly::AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
542542
SanitizerMask WebAssembly::getSupportedSanitizers() const {
543543
SanitizerMask Res = ToolChain::getSupportedSanitizers();
544544
if (getTriple().isOSEmscripten()) {
545-
Res |= SanitizerKind::Vptr | SanitizerKind::Leak | SanitizerKind::Address;
545+
Res |= SanitizerKind::Vptr | SanitizerKind::Leak;
546546
}
547+
548+
if (getTriple().isOSEmscripten() || getTriple().isOSWASI()) {
549+
Res |= SanitizerKind::Address;
550+
}
551+
547552
// -fsanitize=function places two words before the function label, which are
548553
// -unsupported.
549554
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,8 +499,8 @@ 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();
503+
bool IsWasm = TargetTriple.isWasm();
504504

505505
ShadowMapping Mapping;
506506

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

0 commit comments

Comments
 (0)