abrachet updated this revision to Diff 468425.
abrachet added a comment.

The error @zequanwu ran into happens only on MacOS because it this Darwin-only 
test happens to be the only one that tests instrprof with no code. 
`__llvm_profile_filename` doesn't get emitted in this case so it ends up 
pulling in the one in libprofile.a which is not hidden. I've changed this to 
make `__llvm_profile_filename` hidden, as well as `__llvm_profile_raw_version` 
even though that symbol is always emitted.

@cishida, to verify, the comment in InstrProfilingVersionVar.c said that 
`__llvm_profile_raw_version` was not hidden on Apple platforms because of TAPI, 
it should be ok to mark this as hidden in libprofile.a, right? I'm guessing 
this should be no different than when the symbol is emitted by llvm.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135340/new/

https://reviews.llvm.org/D135340

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/darwin-ld.c
  compiler-rt/lib/profile/InstrProfilingNameVar.c
  compiler-rt/lib/profile/InstrProfilingVersionVar.c
  llvm/lib/ProfileData/InstrProf.cpp
  llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
  llvm/test/Transforms/PGOProfile/branch1.ll
  llvm/test/Transforms/PGOProfile/branch2.ll
  llvm/test/Transforms/PGOProfile/comdat_internal.ll
  llvm/test/Transforms/PGOProfile/criticaledge.ll
  llvm/test/Transforms/PGOProfile/instr_entry_bb.ll
  llvm/test/Transforms/PGOProfile/landingpad.ll
  llvm/test/Transforms/PGOProfile/loop1.ll
  llvm/test/Transforms/PGOProfile/loop2.ll
  llvm/test/Transforms/PGOProfile/lto_cspgo_gen.ll
  llvm/test/Transforms/PGOProfile/single_bb.ll
  llvm/test/Transforms/PGOProfile/switch.ll
  llvm/test/Transforms/PGOProfile/thinlto_cspgo_gen.ll

Index: llvm/test/Transforms/PGOProfile/thinlto_cspgo_gen.ll
===================================================================
--- llvm/test/Transforms/PGOProfile/thinlto_cspgo_gen.ll
+++ llvm/test/Transforms/PGOProfile/thinlto_cspgo_gen.ll
@@ -17,11 +17,11 @@
 ; RUN: llvm-dis %t.2.4.opt.bc -o - | FileCheck %s --check-prefixes=CSGEN,NOPREVAILING
 
 ;; Prevailing __llvm_profile_raw_version is kept by LTO.
-; PREVAILING: @__llvm_profile_raw_version = constant i64
+; PREVAILING: @__llvm_profile_raw_version = hidden constant i64
 
 ;; Non-prevailing __llvm_profile_raw_version is discarded by LTO. Ensure the
 ;; declaration is retained.
-; NOPREVAILING: @__llvm_profile_raw_version = external constant i64
+; NOPREVAILING: @__llvm_profile_raw_version = external hidden constant i64
 ; CSGEN: @__profc_
 ; CSGEN: @__profd_
 
Index: llvm/test/Transforms/PGOProfile/switch.ll
===================================================================
--- llvm/test/Transforms/PGOProfile/switch.ll
+++ llvm/test/Transforms/PGOProfile/switch.ll
@@ -8,7 +8,7 @@
 target triple = "x86_64-unknown-linux-gnu"
 
 ; GEN: $__llvm_profile_raw_version = comdat any
-; GEN: @__llvm_profile_raw_version = constant i64 {{[0-9]+}}, comdat
+; GEN: @__llvm_profile_raw_version = hidden constant i64 {{[0-9]+}}, comdat
 ; GEN: @__profn_test_switch = private constant [11 x i8] c"test_switch"
 
 define void @test_switch(i32 %i) {
Index: llvm/test/Transforms/PGOProfile/single_bb.ll
===================================================================
--- llvm/test/Transforms/PGOProfile/single_bb.ll
+++ llvm/test/Transforms/PGOProfile/single_bb.ll
@@ -3,7 +3,7 @@
 target triple = "x86_64-unknown-linux-gnu"
 
 ; GEN: $__llvm_profile_raw_version = comdat any
-; GEN: @__llvm_profile_raw_version = constant i64 {{[0-9]+}}, comdat
+; GEN: @__llvm_profile_raw_version = hidden constant i64 {{[0-9]+}}, comdat
 ; GEN: @__profn_single_bb = private constant [9 x i8] c"single_bb"
 
 define i32 @single_bb() {
Index: llvm/test/Transforms/PGOProfile/lto_cspgo_gen.ll
===================================================================
--- llvm/test/Transforms/PGOProfile/lto_cspgo_gen.ll
+++ llvm/test/Transforms/PGOProfile/lto_cspgo_gen.ll
@@ -11,11 +11,11 @@
 ; RUN: llvm-dis %t.0.0.preopt.bc -o - | FileCheck %s --check-prefix=IRPGOBE
 
 ;; Before LTO, we should have the __llvm_profile_raw_version definition.
-; IRPGOPRE: @__llvm_profile_raw_version = constant i64
+; IRPGOPRE: @__llvm_profile_raw_version = hidden constant i64
 
 ;; Non-prevailing __llvm_profile_raw_version is discarded by LTO. Ensure the
 ;; declaration is retained.
-; IRPGOBE: @__llvm_profile_raw_version = external constant i64
+; IRPGOBE: @__llvm_profile_raw_version = external hidden constant i64
 
 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"
Index: llvm/test/Transforms/PGOProfile/loop2.ll
===================================================================
--- llvm/test/Transforms/PGOProfile/loop2.ll
+++ llvm/test/Transforms/PGOProfile/loop2.ll
@@ -8,7 +8,7 @@
 target triple = "x86_64-unknown-linux-gnu"
 
 ; GEN: $__llvm_profile_raw_version = comdat any
-; GEN: @__llvm_profile_raw_version = constant i64 {{[0-9]+}}, comdat
+; GEN: @__llvm_profile_raw_version = hidden constant i64 {{[0-9]+}}, comdat
 ; GEN: @__profn_test_nested_for = private constant [15 x i8] c"test_nested_for"
 
 define i32 @test_nested_for(i32 %r, i32 %s) {
Index: llvm/test/Transforms/PGOProfile/loop1.ll
===================================================================
--- llvm/test/Transforms/PGOProfile/loop1.ll
+++ llvm/test/Transforms/PGOProfile/loop1.ll
@@ -9,7 +9,7 @@
 target triple = "x86_64-unknown-linux-gnu"
 
 ; GEN: $__llvm_profile_raw_version = comdat any
-; GEN: @__llvm_profile_raw_version = constant i64 {{[0-9]+}}, comdat
+; GEN: @__llvm_profile_raw_version = hidden constant i64 {{[0-9]+}}, comdat
 ; GEN: @__profn_test_simple_for = private constant [15 x i8] c"test_simple_for"
 
 define i32 @test_simple_for(i32 %n) {
Index: llvm/test/Transforms/PGOProfile/landingpad.ll
===================================================================
--- llvm/test/Transforms/PGOProfile/landingpad.ll
+++ llvm/test/Transforms/PGOProfile/landingpad.ll
@@ -11,7 +11,7 @@
 @val = global i32 0, align 4
 @_ZTIi = external constant ptr
 ; GEN: $__llvm_profile_raw_version = comdat any
-; GEN: @__llvm_profile_raw_version = constant i64 {{[0-9]+}}, comdat
+; GEN: @__llvm_profile_raw_version = hidden constant i64 {{[0-9]+}}, comdat
 ; GEN: @__profn_bar = private constant [3 x i8] c"bar"
 ; GEN: @__profn_foo = private constant [3 x i8] c"foo"
 
Index: llvm/test/Transforms/PGOProfile/instr_entry_bb.ll
===================================================================
--- llvm/test/Transforms/PGOProfile/instr_entry_bb.ll
+++ llvm/test/Transforms/PGOProfile/instr_entry_bb.ll
@@ -7,7 +7,7 @@
 target triple = "x86_64-unknown-linux-gnu"
 
 ; GEN: $__llvm_profile_raw_version = comdat any
-; GEN: @__llvm_profile_raw_version = constant i64 {{[0-9]+}}, comdat
+; GEN: @__llvm_profile_raw_version = hidden constant i64 {{[0-9]+}}, comdat
 ; GEN: @__profn_test_br_2 = private constant [9 x i8] c"test_br_2"
 
 define i32 @test_br_2(i32 %i) {
Index: llvm/test/Transforms/PGOProfile/criticaledge.ll
===================================================================
--- llvm/test/Transforms/PGOProfile/criticaledge.ll
+++ llvm/test/Transforms/PGOProfile/criticaledge.ll
@@ -9,7 +9,7 @@
 target triple = "x86_64-unknown-linux-gnu"
 
 ; GEN: $__llvm_profile_raw_version = comdat any
-; GEN: @__llvm_profile_raw_version = constant i64 {{[0-9]+}}, comdat
+; GEN: @__llvm_profile_raw_version = hidden constant i64 {{[0-9]+}}, comdat
 ; GEN: @__profn_test_criticalEdge = private constant [17 x i8] c"test_criticalEdge"
 ; GEN: @__profn__stdin__bar = private constant [11 x i8] c"<stdin>:bar"
 
Index: llvm/test/Transforms/PGOProfile/comdat_internal.ll
===================================================================
--- llvm/test/Transforms/PGOProfile/comdat_internal.ll
+++ llvm/test/Transforms/PGOProfile/comdat_internal.ll
@@ -10,7 +10,7 @@
 
 @bar = global ptr @foo, align 8
 
-; CHECK: @__llvm_profile_raw_version = constant i64 {{[0-9]+}}, comdat
+; CHECK: @__llvm_profile_raw_version = hidden constant i64 {{[0-9]+}}, comdat
 ; CHECK-NOT: __profn__stdin__foo
 ; CHECK: @__profc__stdin__foo.[[#FOO_HASH]] = private global [1 x i64] zeroinitializer, section "__llvm_prf_cnts", comdat, align 8
 ; CHECK: @__profd__stdin__foo.[[#FOO_HASH]] = private global { i64, i64, i64, ptr, ptr, i32, [2 x i16] } { i64 -5640069336071256030, i64 [[#FOO_HASH]], i64 sub (i64 ptrtoint (ptr @__profc__stdin__foo.742261418966908927 to i64), i64 ptrtoint (ptr @__profd__stdin__foo.742261418966908927 to i64)), ptr null
Index: llvm/test/Transforms/PGOProfile/branch2.ll
===================================================================
--- llvm/test/Transforms/PGOProfile/branch2.ll
+++ llvm/test/Transforms/PGOProfile/branch2.ll
@@ -9,7 +9,7 @@
 target triple = "x86_64-unknown-linux-gnu"
 
 ; GEN: $__llvm_profile_raw_version = comdat any
-; GEN: @__llvm_profile_raw_version = constant i64 {{[0-9]+}}, comdat
+; GEN: @__llvm_profile_raw_version = hidden constant i64 {{[0-9]+}}, comdat
 ; GEN: @__profn_test_br_2 = private constant [9 x i8] c"test_br_2"
 
 define i32 @test_br_2(i32 %i) {
Index: llvm/test/Transforms/PGOProfile/branch1.ll
===================================================================
--- llvm/test/Transforms/PGOProfile/branch1.ll
+++ llvm/test/Transforms/PGOProfile/branch1.ll
@@ -14,7 +14,7 @@
 ; GEN-DARWIN-LINKONCE: target triple = "x86_64-apple-darwin"
 
 ; GEN-COMDAT: $__llvm_profile_raw_version = comdat any
-; GEN-COMDAT: @__llvm_profile_raw_version = constant i64 {{[0-9]+}}, comdat
+; GEN-COMDAT: @__llvm_profile_raw_version = hidden constant i64 {{[0-9]+}}, comdat
 ; GEN-LINKONCE: @__llvm_profile_raw_version = linkonce constant i64 {{[0-9]+}}
 ; GEN: @__profn_test_br_1 = private constant [9 x i8] c"test_br_1"
 
Index: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -380,7 +380,7 @@
   auto IRLevelVersionVariable = new GlobalVariable(
       M, IntTy64, true, GlobalValue::WeakAnyLinkage,
       Constant::getIntegerValue(IntTy64, APInt(64, ProfileVersion)), VarName);
-  IRLevelVersionVariable->setVisibility(GlobalValue::DefaultVisibility);
+  IRLevelVersionVariable->setVisibility(GlobalValue::HiddenVisibility);
   Triple TT(M.getTargetTriple());
   if (TT.supportsCOMDAT()) {
     IRLevelVersionVariable->setLinkage(GlobalValue::ExternalLinkage);
Index: llvm/lib/ProfileData/InstrProf.cpp
===================================================================
--- llvm/lib/ProfileData/InstrProf.cpp
+++ llvm/lib/ProfileData/InstrProf.cpp
@@ -1210,6 +1210,7 @@
   GlobalVariable *ProfileNameVar = new GlobalVariable(
       M, ProfileNameConst->getType(), true, GlobalValue::WeakAnyLinkage,
       ProfileNameConst, INSTR_PROF_QUOTE(INSTR_PROF_PROFILE_NAME_VAR));
+  ProfileNameVar->setVisibility(GlobalValue::HiddenVisibility);
   Triple TT(M.getTargetTriple());
   if (TT.supportsCOMDAT()) {
     ProfileNameVar->setLinkage(GlobalValue::ExternalLinkage);
Index: compiler-rt/lib/profile/InstrProfilingVersionVar.c
===================================================================
--- compiler-rt/lib/profile/InstrProfilingVersionVar.c
+++ compiler-rt/lib/profile/InstrProfilingVersionVar.c
@@ -13,14 +13,6 @@
  * The runtime should only provide its own definition of this symbol when the
  * user has not specified one. Set this up by moving the runtime's copy of this
  * symbol to an object file within the archive.
- *
- * Hide this symbol everywhere except Apple platforms, where its presence is
- * checked by the TAPI tool.
  */
-#if !defined(__APPLE__)
-#define VERSION_VAR_VISIBILITY COMPILER_RT_VISIBILITY
-#else
-#define VERSION_VAR_VISIBILITY
-#endif
-VERSION_VAR_VISIBILITY COMPILER_RT_WEAK uint64_t INSTR_PROF_RAW_VERSION_VAR =
+COMPILER_RT_VISIBILITY COMPILER_RT_WEAK uint64_t INSTR_PROF_RAW_VERSION_VAR =
     INSTR_PROF_RAW_VERSION;
Index: compiler-rt/lib/profile/InstrProfilingNameVar.c
===================================================================
--- compiler-rt/lib/profile/InstrProfilingNameVar.c
+++ compiler-rt/lib/profile/InstrProfilingNameVar.c
@@ -14,4 +14,4 @@
  * user has not specified one. Set this up by moving the runtime's copy of this
  * symbol to an object file within the archive.
  */
-COMPILER_RT_WEAK char INSTR_PROF_PROFILE_NAME_VAR[1] = {0};
+COMPILER_RT_WEAK COMPILER_RT_VISIBILITY char INSTR_PROF_PROFILE_NAME_VAR[1] = {0};
Index: clang/test/Driver/darwin-ld.c
===================================================================
--- clang/test/Driver/darwin-ld.c
+++ clang/test/Driver/darwin-ld.c
@@ -338,18 +338,6 @@
 // RUN: FileCheck -check-prefix=PROFILE_SECTALIGN %s < %t.log
 // PROFILE_SECTALIGN: "-sectalign" "__DATA" "__llvm_prf_cnts" "0x4000" "-sectalign" "__DATA" "__llvm_prf_data" "0x4000"
 
-// RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate -exported_symbols_list /dev/null -### %t.o 2> %t.log
-// RUN: FileCheck -check-prefix=PROFILE_EXPORT %s < %t.log
-// RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate -Wl,-exported_symbols_list,/dev/null -### %t.o 2> %t.log
-// RUN: FileCheck -check-prefix=PROFILE_EXPORT %s < %t.log
-// RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate -Wl,-exported_symbol,foo -### %t.o 2> %t.log
-// RUN: FileCheck -check-prefix=PROFILE_EXPORT %s < %t.log
-// RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate -Xlinker -exported_symbol -Xlinker foo -### %t.o 2> %t.log
-// RUN: FileCheck -check-prefix=PROFILE_EXPORT %s < %t.log
-// RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate -Xlinker -exported_symbols_list -Xlinker /dev/null -### %t.o 2> %t.log
-// RUN: FileCheck -check-prefix=PROFILE_EXPORT %s < %t.log
-// PROFILE_EXPORT: "-exported_symbol" "___llvm_profile_filename" "-exported_symbol" "___llvm_profile_raw_version"
-//
 // RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate --coverage -### %t.o 2> %t.log
 // RUN: FileCheck -check-prefix=NO_PROFILE_EXPORT %s < %t.log
 // NO_PROFILE_EXPORT-NOT: "-exported_symbol"
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1353,16 +1353,11 @@
   // If we have a symbol export directive and we're linking in the profile
   // runtime, automatically export symbols necessary to implement some of the
   // runtime's functionality.
-  if (hasExportSymbolDirective(Args)) {
-    if (ForGCOV) {
-      addExportedSymbol(CmdArgs, "___gcov_dump");
-      addExportedSymbol(CmdArgs, "___gcov_reset");
-      addExportedSymbol(CmdArgs, "_writeout_fn_list");
-      addExportedSymbol(CmdArgs, "_reset_fn_list");
-    } else {
-      addExportedSymbol(CmdArgs, "___llvm_profile_filename");
-      addExportedSymbol(CmdArgs, "___llvm_profile_raw_version");
-    }
+  if (hasExportSymbolDirective(Args) && ForGCOV) {
+    addExportedSymbol(CmdArgs, "___gcov_dump");
+    addExportedSymbol(CmdArgs, "___gcov_reset");
+    addExportedSymbol(CmdArgs, "_writeout_fn_list");
+    addExportedSymbol(CmdArgs, "_reset_fn_list");
   }
 
   // Align __llvm_prf_{cnts,data} sections to the maximum expected page
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to