[PATCH] D26164: [cfi] Fix missing !type annotation.

Evgeniy Stepanov via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 31 14:19:05 PDT 2016


eugenis created this revision.
eugenis added a reviewer: pcc.
eugenis added a subscriber: cfe-commits.
eugenis set the repository for this revision to rL LLVM.

CFI (only in the cross-dso mode) fails to set !type annotations when
a function is used before it is defined.


Repository:
  rL LLVM

https://reviews.llvm.org/D26164

Files:
  lib/CodeGen/CodeGenModule.cpp
  test/CodeGen/cfi-icall-cross-dso2.c


Index: test/CodeGen/cfi-icall-cross-dso2.c
===================================================================
--- /dev/null
+++ test/CodeGen/cfi-icall-cross-dso2.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -O1 \
+// RUN:   -fsanitize=cfi-icall -fsanitize-cfi-cross-dso \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: define void @f() {{.*}} !type !{{.*}} !type !{{.*}}
+void f(void);
+void (*pf)(void) = f;
+void f(void) { }
Index: lib/CodeGen/CodeGenModule.cpp
===================================================================
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -928,6 +928,10 @@
     if (F->getAlignment() < 2 && isa<CXXMethodDecl>(D))
       F->setAlignment(2);
   }
+
+  // In the cross-dso CFI mode, we want !type attributes on definitions only.
+  if (CodeGenOpts.SanitizeCfiCrossDso)
+    CreateFunctionTypeMetadata(dyn_cast<FunctionDecl>(D), F);
 }
 
 void CodeGenModule::SetCommonAttributes(const Decl *D,
@@ -1010,10 +1014,6 @@
 
   // Additionally, if building with cross-DSO support...
   if (CodeGenOpts.SanitizeCfiCrossDso) {
-    // Don't emit entries for function declarations. In cross-DSO mode these are
-    // handled with better precision at run time.
-    if (!FD->hasBody())
-      return;
     // Skip available_externally functions. They won't be codegen'ed in the
     // current module anyway.
     if (getContext().GetGVALinkageForFunction(FD) == GVA_AvailableExternally)
@@ -1086,7 +1086,10 @@
     if (MD->isVirtual())
       F->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
 
-  CreateFunctionTypeMetadata(FD, F);
+  // Don't emit entries for function declarations in the cross-DSO mode. This
+  // is handled with better precision by the receiving DSO.
+  if (!CodeGenOpts.SanitizeCfiCrossDso)
+    CreateFunctionTypeMetadata(FD, F);
 }
 
 void CodeGenModule::addUsedGlobal(llvm::GlobalValue *GV) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26164.76479.patch
Type: text/x-patch
Size: 1915 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161031/72a98a7e/attachment.bin>


More information about the cfe-commits mailing list