Revert "[PGO] Make emitted symbols hidden"
authorZequan Wu <zequanwu@google.com>
Fri, 14 Oct 2022 22:22:26 +0000 (15:22 -0700)
committerZequan Wu <zequanwu@google.com>
Fri, 14 Oct 2022 22:23:26 +0000 (15:23 -0700)
This reverts commit ecac223b0e4b05a65cf918f90824380db6b9ce64.

The commit causes instrprof-darwin-dead-strip.c to fail on mac.

17 files changed:
clang/lib/Driver/ToolChains/Darwin.cpp
clang/test/Driver/darwin-ld.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/filename.ll [deleted file]
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 021b291bb6c6b25943ab0fa5a22693e32539bef6..443c188cc20ece6f5f90b8a9c08726dbcd250780 100644 (file)
@@ -1353,11 +1353,16 @@ void Darwin::addProfileRTLibs(const ArgList &Args,
   // 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) && ForGCOV) {
-    addExportedSymbol(CmdArgs, "___gcov_dump");
-    addExportedSymbol(CmdArgs, "___gcov_reset");
-    addExportedSymbol(CmdArgs, "_writeout_fn_list");
-    addExportedSymbol(CmdArgs, "_reset_fn_list");
+  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");
+    }
   }
 
   // Align __llvm_prf_{cnts,data} sections to the maximum expected page
index 13ec69b2db1abc2fa3a304caaca78ec7afc473ad..5be119a545a634da2168588ba60980b7dd63fd12 100644 (file)
 // 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 eab1eab82ac2fc527298ffdd28cf7197c628fadc..9c04bcb8416f501d6e2cdb7bce43680408a65661 100644 (file)
@@ -1210,7 +1210,6 @@ void createProfileFileNameVar(Module &M, StringRef InstrProfileOutput) {
   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 d627c3eb5d803fd0032e4303b1cba5971acde1a6..1afb4b60a460ee15cde3e36082d385115d9afcc1 100644 (file)
@@ -380,7 +380,7 @@ static GlobalVariable *createIRLevelProfileFlagVar(Module &M, bool IsCS) {
   auto IRLevelVersionVariable = new GlobalVariable(
       M, IntTy64, true, GlobalValue::WeakAnyLinkage,
       Constant::getIntegerValue(IntTy64, APInt(64, ProfileVersion)), VarName);
-  IRLevelVersionVariable->setVisibility(GlobalValue::HiddenVisibility);
+  IRLevelVersionVariable->setVisibility(GlobalValue::DefaultVisibility);
   Triple TT(M.getTargetTriple());
   if (TT.supportsCOMDAT()) {
     IRLevelVersionVariable->setLinkage(GlobalValue::ExternalLinkage);
index 22c4fd5d3c10f85d7b981505936c5adf70adee05..7ec23d08ea5eb34ceafe85672e5656630b9c80cc 100644 (file)
@@ -14,7 +14,7 @@ target triple = "x86_64-unknown-linux-gnu"
 ; GEN-DARWIN-LINKONCE: target triple = "x86_64-apple-darwin"
 
 ; GEN-COMDAT: $__llvm_profile_raw_version = comdat any
-; GEN-COMDAT: @__llvm_profile_raw_version = hidden constant i64 {{[0-9]+}}, comdat
+; GEN-COMDAT: @__llvm_profile_raw_version = 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 82478e75cb2626a2d4bfd3457543602af7cd47c6..b65020d1557bfe6862bcc7e90b9ea0d8177c12dc 100644 (file)
@@ -9,7 +9,7 @@ target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16
 target triple = "x86_64-unknown-linux-gnu"
 
 ; GEN: $__llvm_profile_raw_version = comdat any
-; GEN: @__llvm_profile_raw_version = hidden constant i64 {{[0-9]+}}, comdat
+; GEN: @__llvm_profile_raw_version = 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 a1cf115f910ad75195f039a0bf328ed3a728df2d..64274a33999df007e7aa48aeb8416091651b0d33 100644 (file)
@@ -10,7 +10,7 @@ $foo = comdat any
 
 @bar = global ptr @foo, align 8
 
-; CHECK: @__llvm_profile_raw_version = hidden constant i64 {{[0-9]+}}, comdat
+; CHECK: @__llvm_profile_raw_version = 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 616d0fa3a4cf2a01ec0c4ebb972fe59c88376313..4264b03c23d12176aba7a01493ba52c6312cb11e 100644 (file)
@@ -9,7 +9,7 @@ target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16
 target triple = "x86_64-unknown-linux-gnu"
 
 ; GEN: $__llvm_profile_raw_version = comdat any
-; GEN: @__llvm_profile_raw_version = hidden constant i64 {{[0-9]+}}, comdat
+; GEN: @__llvm_profile_raw_version = 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"
 
diff --git a/llvm/test/Transforms/PGOProfile/filename.ll b/llvm/test/Transforms/PGOProfile/filename.ll
deleted file mode 100644 (file)
index 43bc4a5..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-; RUN: opt < %s -passes='thinlto-pre-link<O2>' --cs-profilegen-file=file -cspgo-kind=cspgo-instr-gen-pipeline -S | FileCheck %s
-
-; CHECK: $__llvm_profile_filename = comdat any
-; CHECK: @__llvm_profile_filename = hidden local_unnamed_addr constant [5 x i8] c"file\00", comdat
-
-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"
-
-define i32 @test() {
-  ret i32 0
-}
index ee088674e35e27f4da2cc508f9f8761e29c58357..e1380a0edf0e1ba9488d33a93f4fda81b27945c8 100644 (file)
@@ -7,7 +7,7 @@ target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16
 target triple = "x86_64-unknown-linux-gnu"
 
 ; GEN: $__llvm_profile_raw_version = comdat any
-; GEN: @__llvm_profile_raw_version = hidden constant i64 {{[0-9]+}}, comdat
+; GEN: @__llvm_profile_raw_version = 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 e16bad51227786940ca9a50e24c5790ec19b0795..1b2648fc2ff64a0ba29396c5f66e71f4e4d3f50e 100644 (file)
@@ -11,7 +11,7 @@ target triple = "x86_64-unknown-linux-gnu"
 @val = global i32 0, align 4
 @_ZTIi = external constant ptr
 ; GEN: $__llvm_profile_raw_version = comdat any
-; GEN: @__llvm_profile_raw_version = hidden constant i64 {{[0-9]+}}, comdat
+; GEN: @__llvm_profile_raw_version = 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 ece7ea21b8ee5af22e3960ad8242e16d8174f057..86029663bf8e1a2e7d2db3f020c3ab89f88bfad6 100644 (file)
@@ -9,7 +9,7 @@ target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16
 target triple = "x86_64-unknown-linux-gnu"
 
 ; GEN: $__llvm_profile_raw_version = comdat any
-; GEN: @__llvm_profile_raw_version = hidden constant i64 {{[0-9]+}}, comdat
+; GEN: @__llvm_profile_raw_version = 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 071f8a6d5ad5949f13f120d958627710bce32d1e..13725ec097546893e90266f1c4955750baa181be 100644 (file)
@@ -8,7 +8,7 @@ target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16
 target triple = "x86_64-unknown-linux-gnu"
 
 ; GEN: $__llvm_profile_raw_version = comdat any
-; GEN: @__llvm_profile_raw_version = hidden constant i64 {{[0-9]+}}, comdat
+; GEN: @__llvm_profile_raw_version = 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 19f68bf30c809ecd5d2d7608aefc5cb13892ed61..8ea2d3ccbfe07a741011e7e476c08badfa4c8534 100644 (file)
 ; 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 = hidden constant i64
+; IRPGOPRE: @__llvm_profile_raw_version = constant i64
 
 ;; Non-prevailing __llvm_profile_raw_version is discarded by LTO. Ensure the
 ;; declaration is retained.
-; IRPGOBE: @__llvm_profile_raw_version = external hidden constant i64
+; IRPGOBE: @__llvm_profile_raw_version = external 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 b6d85ed084018ffa96a8f4dc91805db4a50c3569..f60cbfe565e1994b16dd059574e716b046f6aa8d 100644 (file)
@@ -3,7 +3,7 @@ target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16
 target triple = "x86_64-unknown-linux-gnu"
 
 ; GEN: $__llvm_profile_raw_version = comdat any
-; GEN: @__llvm_profile_raw_version = hidden constant i64 {{[0-9]+}}, comdat
+; GEN: @__llvm_profile_raw_version = constant i64 {{[0-9]+}}, comdat
 ; GEN: @__profn_single_bb = private constant [9 x i8] c"single_bb"
 
 define i32 @single_bb() {
index b0b32182b5baa5bbbe6e831bd7cf269212602d6c..dac4347a729d0294949a301d2749dfe31d182a06 100644 (file)
@@ -8,7 +8,7 @@ target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16
 target triple = "x86_64-unknown-linux-gnu"
 
 ; GEN: $__llvm_profile_raw_version = comdat any
-; GEN: @__llvm_profile_raw_version = hidden constant i64 {{[0-9]+}}, comdat
+; GEN: @__llvm_profile_raw_version = constant i64 {{[0-9]+}}, comdat
 ; GEN: @__profn_test_switch = private constant [11 x i8] c"test_switch"
 
 define void @test_switch(i32 %i) {
index 266e2597a63a2268b9273be1c2c4aab8791f27b0..8a408fa842fb56309e96ef9d61f5d1bcbdc6d7a0 100644 (file)
 ; 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 = hidden constant i64
+; PREVAILING: @__llvm_profile_raw_version = constant i64
 
 ;; Non-prevailing __llvm_profile_raw_version is discarded by LTO. Ensure the
 ;; declaration is retained.
-; NOPREVAILING: @__llvm_profile_raw_version = external hidden constant i64
+; NOPREVAILING: @__llvm_profile_raw_version = external constant i64
 ; CSGEN: @__profc_
 ; CSGEN: @__profd_