From: Guanzhong Chen Date: Wed, 26 Jun 2019 20:16:14 +0000 (+0000) Subject: [WebAssembly] Implement Address Sanitizer for Emscripten X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a057056821e096990964f3416835c8477eb1b6bf;p=clang [WebAssembly] Implement Address Sanitizer for Emscripten Summary: This diff enables address sanitizer on Emscripten. On Emscripten, real memory starts at the value passed to --global-base. All memory before this is used as shadow memory, and thus the shadow mapping function is simply dividing by 8. Reviewers: tlively, aheejin, sbc100 Reviewed By: sbc100 Subscribers: dschuff, sbc100, jgravelle-google, hiraditya, sunfish, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D63742 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@364468 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Driver/ToolChains/WebAssembly.cpp b/lib/Driver/ToolChains/WebAssembly.cpp index a6a881873e..648e5b3a94 100644 --- a/lib/Driver/ToolChains/WebAssembly.cpp +++ b/lib/Driver/ToolChains/WebAssembly.cpp @@ -238,7 +238,7 @@ void WebAssembly::AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, SanitizerMask WebAssembly::getSupportedSanitizers() const { SanitizerMask Res = ToolChain::getSupportedSanitizers(); if (getTriple().isOSEmscripten()) { - Res |= SanitizerKind::Vptr | SanitizerKind::Leak; + Res |= SanitizerKind::Vptr | SanitizerKind::Leak | SanitizerKind::Address; } return Res; } diff --git a/test/Driver/wasm-toolchain.c b/test/Driver/wasm-toolchain.c index 2ed94cee9b..910de4bd59 100644 --- a/test/Driver/wasm-toolchain.c +++ b/test/Driver/wasm-toolchain.c @@ -60,3 +60,7 @@ // RUN: --sysroot=/foo %s -pthread -mno-atomics 2>&1 \ // RUN: | FileCheck -check-prefix=PTHREAD_NO_ATOMICS %s // PTHREAD_NO_ATOMICS: invalid argument '-pthread' not allowed with '-mno-atomics' + +// RUN: %clang %s -### -fsanitize=address -target wasm32-unknown-emscripten 2>&1 | FileCheck -check-prefix=CHECK-ASAN-EMSCRIPTEN %s +// CHECK-ASAN-EMSCRIPTEN: "-fsanitize=address" +// CHECK-ASAN-EMSCRIPTEN: "-fsanitize-address-globals-dead-stripping"