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 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()