[PATCH] D95902: TSAN module_ctor symbol name can change with -funique-internal-linkage-names

Sriraman Tallam via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 2 15:24:36 PST 2021


tmsriram created this revision.
tmsriram added reviewers: dvyukov, vitalybuka.
Herald added a subscriber: hiraditya.
tmsriram requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

tsan.module_ctor symbol name can change with -funique-internal-linkage-names which is captured in this patch.

With option, -funique-internal-linkage-names, the name of tsan.module_ctor is actually tsan.module_ctor.__uniq.[0-9]+

The option -funique-internal-linkage-names adds a sufix (.__uniq.[0-9]+) to every internal linkage function to keep the name unique in the final binary.  tsan.module_ctor is one such function which has internal linkage.  This function name is checked in ThreadSanitizer.cpp to make sure we don't insturment it with __tsan_func_{entry,exit}.  This patch makes sure we even check the name when -funique-internal-linakge-names is used.


https://reviews.llvm.org/D95902

Files:
  llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
  llvm/test/Instrumentation/ThreadSanitizer/tsan_basic.ll


Index: llvm/test/Instrumentation/ThreadSanitizer/tsan_basic.ll
===================================================================
--- llvm/test/Instrumentation/ThreadSanitizer/tsan_basic.ll
+++ llvm/test/Instrumentation/ThreadSanitizer/tsan_basic.ll
@@ -1,5 +1,7 @@
 ; RUN: opt < %s -tsan -S -enable-new-pm=0 | FileCheck %s
+; RUN: opt < %s -tsan -unique-internal-linkage-names -S -enable-new-pm=0 | FileCheck %s
 ; RUN: opt < %s -passes='function(tsan),module(tsan-module)' -S | FileCheck %s
+; RUN: opt < %s -passes='function(tsan),module(tsan-module),unique-internal-linkage-names' -S | FileCheck %s
 
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
 target triple = "x86_64-unknown-linux-gnu"
@@ -91,5 +93,5 @@
 
 declare void @foo() nounwind
 
-; CHECK: define internal void @tsan.module_ctor()
+; CHECK: define internal void @tsan.module_ctor
 ; CHECK: call void @__tsan_init()
Index: llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
@@ -97,6 +97,8 @@
 STATISTIC(NumOmittedNonCaptured, "Number of accesses ignored due to capturing");
 
 const char kTsanModuleCtorName[] = "tsan.module_ctor";
+// This is the prefix when -funique-internal-linkage-names is used.
+const char kTsanModuleCtorNameUniq[] = "tsan.module_ctor.__uniq";
 const char kTsanInitName[] = "__tsan_init";
 
 namespace {
@@ -526,7 +528,8 @@
                                        const TargetLibraryInfo &TLI) {
   // This is required to prevent instrumenting call to __tsan_init from within
   // the module constructor.
-  if (F.getName() == kTsanModuleCtorName)
+  if (F.getName() == kTsanModuleCtorName
+      || F.getName().startswith(kTsanModuleCtorNameUniq))
     return false;
   // Naked functions can not have prologue/epilogue
   // (__tsan_func_entry/__tsan_func_exit) generated, so don't instrument them at


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95902.320928.patch
Type: text/x-patch
Size: 2106 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210202/48b0691d/attachment.bin>


More information about the llvm-commits mailing list