summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRong Xu <xur@google.com>2016-05-09 21:03:06 +0000
committerRong Xu <xur@google.com>2016-05-09 21:03:06 +0000
commita12f6d3c7bb5d600371a6b25773a0096a0e801c4 (patch)
tree725a8a20ed8fb0ac7bf198017c7c6a388d03db2a
parentca9694ba2ccf2beee3ee0ed694e905d349e7bc80 (diff)
downloadbcm5719-llvm-a12f6d3c7bb5d600371a6b25773a0096a0e801c4.tar.gz
bcm5719-llvm-a12f6d3c7bb5d600371a6b25773a0096a0e801c4.zip
[PGO] Fix __llvm_profile_raw_version linkage in MACHO
IR instrumentation generates a COMDAT symbol __llvm_profile_raw_version to overwrite the same symbol in profile run-time to distinguish IR profiles from Clang generated profiles. In MACHO, LinkOnceODR linkage is used due to the lack of COMDAT support. But LinkOnceODR linkage might have .weak_def_can_be_hidden assembly directive, while the weak variable in run-time has a .weak_definition directive. Linker will not merge these two symbols even they have the same name. The end result is IR profiles are not properly flagged in MACHO. This patch changes the linkage for __llvm_profile_raw_version in each module to LinkOnceAny so that it has same .weak_definition directive as in the run-time. Differential Revision: http://reviews.llvm.org/D20078 llvm-svn: 268969
-rw-r--r--llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp2
-rw-r--r--llvm/test/Transforms/PGOProfile/macho.ll9
2 files changed, 10 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
index 90bbfa87944..5d52dc847d2 100644
--- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -776,7 +776,7 @@ static void createIRLevelProfileFlagVariable(Module &M) {
IRLevelVersionVariable->setVisibility(GlobalValue::DefaultVisibility);
Triple TT(M.getTargetTriple());
if (TT.isOSBinFormatMachO())
- IRLevelVersionVariable->setLinkage(GlobalValue::LinkOnceODRLinkage);
+ IRLevelVersionVariable->setLinkage(GlobalValue::LinkOnceAnyLinkage);
else
IRLevelVersionVariable->setComdat(M.getOrInsertComdat(
StringRef(INSTR_PROF_QUOTE(IR_LEVEL_PROF_VERSION_VAR))));
diff --git a/llvm/test/Transforms/PGOProfile/macho.ll b/llvm/test/Transforms/PGOProfile/macho.ll
new file mode 100644
index 00000000000..314442cb981
--- /dev/null
+++ b/llvm/test/Transforms/PGOProfile/macho.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -mtriple=x86_64-apple-macosx10.11.0 -pgo-instr-gen -instrprof -S | llc | FileCheck %s --check-prefix=MACHO-DIRECTIVE
+
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+
+; MACHO-DIRECTIVE: .weak_definition ___llvm_profile_raw_version
+define i32 @test_macho(i32 %i) {
+entry:
+ ret i32 %i
+}
OpenPOWER on IntegriCloud