[PATCH] D44784: DataFlowSanitizer: do not allow wrapper functions with non-local linkage to have dso_local set.

Sam Kerner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 22 08:53:40 PDT 2018


skerner created this revision.
Herald added a subscriber: llvm-commits.

This patch resolves link errors when the address of a static function is taken, and that function is uninstrumented by DFSan.


Repository:
  rL LLVM

https://reviews.llvm.org/D44784

Files:
  include/llvm/IR/GlobalValue.h
  lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
  test/Instrumentation/DataFlowSanitizer/Inputs/abilist.txt
  test/Instrumentation/DataFlowSanitizer/uninstrumented_internal_function.ll


Index: test/Instrumentation/DataFlowSanitizer/uninstrumented_internal_function.ll
===================================================================
--- /dev/null
+++ test/Instrumentation/DataFlowSanitizer/uninstrumented_internal_function.ll
@@ -0,0 +1,16 @@
+; RUN: opt < %s -dfsan -dfsan-args-abi -dfsan-abilist=%S/Inputs/abilist.txt -S | FileCheck %s
+; RUN: opt < %s -dfsan                 -dfsan-abilist=%S/Inputs/abilist.txt -S | FileCheck %s
+
+target triple = "x86_64-unknown-linux-gnu"
+
+define internal i8 @uninstrumented_internal_fun(i8 %in) {
+  ret i8 %in
+}
+
+define i8 @call_uninstrumented_fun(i8 %in) {
+  %call = call i8 @uninstrumented_internal_fun(i8 %in)
+  ret i8 %call
+}
+
+; CHECK: define linkonce_odr {{(i8|{ i8, i16 })}} @"dfsw$uninstrumented_internal_fun"
+; CHECK-NOT: dso_local
Index: test/Instrumentation/DataFlowSanitizer/Inputs/abilist.txt
===================================================================
--- test/Instrumentation/DataFlowSanitizer/Inputs/abilist.txt
+++ test/Instrumentation/DataFlowSanitizer/Inputs/abilist.txt
@@ -6,3 +6,5 @@
 
 fun:custom*=uninstrumented
 fun:custom*=custom
+
+fun:uninstrumented*=uninstrumented
Index: lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
===================================================================
--- lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
+++ lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
@@ -653,6 +653,13 @@
       AttributeList::ReturnIndex,
       AttributeFuncs::typeIncompatible(NewFT->getReturnType()));
 
+  // If the function being created has non-local linkage, it should not have the
+  // dso_local attribute.  Explicitly remove dso_local, in case it was set when
+  // attributes were copied from F.
+  if (!NewF->hasLocalLinkage()) {
+    NewF->setDSOLocal(false);
+  }
+
   BasicBlock *BB = BasicBlock::Create(*Ctx, "entry", NewF);
   if (F->isVarArg()) {
     NewF->removeAttributes(AttributeList::FunctionIndex,
Index: include/llvm/IR/GlobalValue.h
===================================================================
--- include/llvm/IR/GlobalValue.h
+++ include/llvm/IR/GlobalValue.h
@@ -113,6 +113,7 @@
   friend class Constant;
 
   void maybeSetDsoLocal() {
+    // hasLocalLinkage => false
     if (hasLocalLinkage() ||
         (!hasDefaultVisibility() && !hasExternalWeakLinkage()))
       setDSOLocal(true);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44784.139450.patch
Type: text/x-patch
Size: 2357 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180322/e6240c90/attachment.bin>


More information about the llvm-commits mailing list