[PATCH] D11502: [UBSan] Fix isDerivedFromAtOffset on iOS ARM64

Filipe Cabecinhas via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 6 12:42:44 PST 2016


filcab updated this revision to Diff 47094.
filcab added a comment.

Sorry, I totally forgot about this revision. Refreshing it, with a test.

I'm not sure how well the test will run on all platforms (no idea about Windows), especially on the ones that really need it (iOS ARM64 is impossible to test outside of Apple, AFAICT).


http://reviews.llvm.org/D11502

Files:
  lib/sanitizer_common/sanitizer_platform.h
  lib/ubsan/ubsan_type_hash_itanium.cc
  test/ubsan/TestCases/TypeCheck/Helpers/lit.local.cfg
  test/ubsan/TestCases/TypeCheck/Helpers/vptr-non-unique-typeinfo-lib.cpp
  test/ubsan/TestCases/TypeCheck/Helpers/vptr-non-unique-typeinfo-lib.h
  test/ubsan/TestCases/TypeCheck/vptr-non-unique-typeinfo.cpp

Index: test/ubsan/TestCases/TypeCheck/vptr-non-unique-typeinfo.cpp
===================================================================
--- /dev/null
+++ test/ubsan/TestCases/TypeCheck/vptr-non-unique-typeinfo.cpp
@@ -0,0 +1,10 @@
+// RUN: %clangxx -frtti -fsanitize=vptr -fno-sanitize-recover=vptr -I%p/Helpers %p/Helpers/vptr-non-unique-typeinfo-lib.cpp -fPIC -shared -o %t-lib.so
+// RUN: %clangxx -frtti -fsanitize=vptr -fno-sanitize-recover=vptr -I%p/Helpers -g %s -O3 -o %t %t-lib.so
+// RUN: %run %t
+
+#include "vptr-non-unique-typeinfo-lib.h"
+
+int main() {
+  X *px = libCall();
+  delete px;
+}
Index: test/ubsan/TestCases/TypeCheck/Helpers/vptr-non-unique-typeinfo-lib.h
===================================================================
--- /dev/null
+++ test/ubsan/TestCases/TypeCheck/Helpers/vptr-non-unique-typeinfo-lib.h
@@ -0,0 +1,4 @@
+struct X {
+  virtual ~X() {}
+};
+X *libCall();
Index: test/ubsan/TestCases/TypeCheck/Helpers/vptr-non-unique-typeinfo-lib.cpp
===================================================================
--- /dev/null
+++ test/ubsan/TestCases/TypeCheck/Helpers/vptr-non-unique-typeinfo-lib.cpp
@@ -0,0 +1,5 @@
+#include "vptr-non-unique-typeinfo-lib.h"
+
+X *libCall() {
+  return new X;
+}
Index: test/ubsan/TestCases/TypeCheck/Helpers/lit.local.cfg
===================================================================
--- /dev/null
+++ test/ubsan/TestCases/TypeCheck/Helpers/lit.local.cfg
@@ -0,0 +1,3 @@
+# Sources in this directory are helper files for tests which test functionality
+# involving multiple translation units.
+config.suffixes = []
Index: lib/ubsan/ubsan_type_hash_itanium.cc
===================================================================
--- lib/ubsan/ubsan_type_hash_itanium.cc
+++ lib/ubsan/ubsan_type_hash_itanium.cc
@@ -115,7 +115,9 @@
 static bool isDerivedFromAtOffset(const abi::__class_type_info *Derived,
                                   const abi::__class_type_info *Base,
                                   sptr Offset) {
-  if (Derived->__type_name == Base->__type_name)
+  if (Derived->__type_name == Base->__type_name ||
+      (SANITIZER_NON_UNIQUE_TYPEINFO &&
+       !internal_strcmp(Derived->__type_name, Base->__type_name)))
     return Offset == 0;
 
   if (const abi::__si_class_type_info *SI =
Index: lib/sanitizer_common/sanitizer_platform.h
===================================================================
--- lib/sanitizer_common/sanitizer_platform.h
+++ lib/sanitizer_common/sanitizer_platform.h
@@ -162,4 +162,10 @@
 # define MSC_PREREQ(version) 0
 #endif
 
+#if defined(__arm64__) && SANITIZER_IOS
+# define SANITIZER_NON_UNIQUE_TYPEINFO 1
+#else
+# define SANITIZER_NON_UNIQUE_TYPEINFO 0
+#endif
+
 #endif // SANITIZER_PLATFORM_H


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11502.47094.patch
Type: text/x-patch
Size: 2736 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160206/3ca34693/attachment.bin>


More information about the llvm-commits mailing list