r362004 - [WebAssembly] Support VPtr sanitizer for Emscripten

Thomas Lively via cfe-commits cfe-commits at lists.llvm.org
Wed May 29 11:31:50 PDT 2019


Author: tlively
Date: Wed May 29 11:31:50 2019
New Revision: 362004

URL: http://llvm.org/viewvc/llvm-project?rev=362004&view=rev
Log:
[WebAssembly] Support VPtr sanitizer for Emscripten

Summary:
After https://github.com/emscripten-core/emscripten/pull/8651, Emscripten
supports the full UBSan runtime. This includes the VPtr sanitizer.

This diff allows clang to generate code that uses the VPtr sanitizer for
Emscripten.

Patch by Guanzhong Chen

Reviewers: tlively, aheejin

Reviewed By: aheejin

Subscribers: dschuff, sbc100, jgravelle-google, sunfish, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D62559

Added:
    cfe/trunk/test/CodeGenCXX/wasm-sanitize-vptr.cpp
Modified:
    cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
    cfe/trunk/lib/Driver/ToolChains/WebAssembly.h

Modified: cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp?rev=362004&r1=362003&r2=362004&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp Wed May 29 11:31:50 2019
@@ -208,6 +208,14 @@ void WebAssembly::AddCXXStdlibLibArgs(co
   }
 }
 
+SanitizerMask WebAssembly::getSupportedSanitizers() const {
+  SanitizerMask Res = ToolChain::getSupportedSanitizers();
+  if (getTriple().isOSEmscripten()) {
+    Res |= SanitizerKind::Vptr;
+  }
+  return Res;
+}
+
 Tool *WebAssembly::buildLinker() const {
   return new tools::wasm::Linker(*this);
 }

Modified: cfe/trunk/lib/Driver/ToolChains/WebAssembly.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/WebAssembly.h?rev=362004&r1=362003&r2=362004&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/WebAssembly.h (original)
+++ cfe/trunk/lib/Driver/ToolChains/WebAssembly.h Wed May 29 11:31:50 2019
@@ -66,6 +66,7 @@ private:
       llvm::opt::ArgStringList &CC1Args) const override;
   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
                            llvm::opt::ArgStringList &CmdArgs) const override;
+  SanitizerMask getSupportedSanitizers() const override;
 
   const char *getDefaultLinker() const override { return "wasm-ld"; }
 

Added: cfe/trunk/test/CodeGenCXX/wasm-sanitize-vptr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/wasm-sanitize-vptr.cpp?rev=362004&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/wasm-sanitize-vptr.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/wasm-sanitize-vptr.cpp Wed May 29 11:31:50 2019
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -std=c++11 -fsanitize=vptr -emit-llvm %s -o - -triple wasm32-unknown-emscripten | FileCheck %s
+
+struct S {
+  virtual ~S() {}
+  int a;
+};
+
+struct T : S {
+  int b;
+};
+
+// CHECK-LABEL: @_Z15bad_static_castv
+void bad_static_cast() {
+  S s;
+  // CHECK: br i1 %[[NONNULL:.*]], label %[[CONT:.*]], label %[[MISS:.*]], !prof
+  // CHECK: [[MISS]]:
+  // CHECK: call void @__ubsan_handle_dynamic_type_cache_miss_abort
+  // CHECK: [[CONT]]:
+  T &r = static_cast<T &>(s);
+}




More information about the cfe-commits mailing list