]> granicus.if.org Git - clang/commitdiff
[cfi] Do not emit bit set entry for available_externally vtables.
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Sat, 23 Jan 2016 01:20:18 +0000 (01:20 +0000)
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Sat, 23 Jan 2016 01:20:18 +0000 (01:20 +0000)
In the Itanium ABI, vtable may be emitted speculatively as an
available_externally global. Such vtable may not be present at the
link time and should not have a corresponding CFI bit set entry.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@258596 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/ItaniumCXXABI.cpp
test/CodeGenCXX/cfi-speculative-vtable.cpp [new file with mode: 0644]

index 8b6322a4b755ed5528f09541271e33e879ea3320..e2106342922971b0191ca55e357b960955c9f8d8 100644 (file)
@@ -1496,7 +1496,8 @@ void ItaniumCXXABI::emitVTableDefinitions(CodeGenVTables &CGVT,
       DC->getParent()->isTranslationUnit())
     EmitFundamentalRTTIDescriptors();
 
-  CGM.EmitVTableBitSetEntries(VTable, VTLayout);
+  if (!VTable->isDeclarationForLinker())
+    CGM.EmitVTableBitSetEntries(VTable, VTLayout);
 }
 
 bool ItaniumCXXABI::isVirtualOffsetNeededForVTableField(
diff --git a/test/CodeGenCXX/cfi-speculative-vtable.cpp b/test/CodeGenCXX/cfi-speculative-vtable.cpp
new file mode 100644 (file)
index 0000000..490190c
--- /dev/null
@@ -0,0 +1,14 @@
+// Test that we don't emit a bit set entry for a speculative (available_externally) vtable.
+// This does not happen in the Microsoft ABI.
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -O1 -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -emit-llvm -o - %s | FileCheck  %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -O1 -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -fsanitize-cfi-cross-dso -emit-llvm -o - %s | FileCheck  %s
+
+class A {
+ public:
+  virtual ~A();
+};
+
+A a;
+
+// CHECK: @_ZTV1A ={{.*}} available_externally
+// CHECK-NOT: !{{.*}} = !{!{{.*}}, [4 x i8*]* @_ZTV1A, i64 16}