[llvm] r268969 - [PGO] Fix __llvm_profile_raw_version linkage in MACHO

Rong Xu via llvm-commits llvm-commits at lists.llvm.org
Mon May 9 14:03:06 PDT 2016


Author: xur
Date: Mon May  9 16:03:06 2016
New Revision: 268969

URL: http://llvm.org/viewvc/llvm-project?rev=268969&view=rev
Log:
[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

Added:
    llvm/trunk/test/Transforms/PGOProfile/macho.ll
Modified:
    llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp

Modified: llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp?rev=268969&r1=268968&r2=268969&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp Mon May  9 16:03:06 2016
@@ -776,7 +776,7 @@ static void createIRLevelProfileFlagVari
   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))));

Added: llvm/trunk/test/Transforms/PGOProfile/macho.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/PGOProfile/macho.ll?rev=268969&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/PGOProfile/macho.ll (added)
+++ llvm/trunk/test/Transforms/PGOProfile/macho.ll Mon May  9 16:03:06 2016
@@ -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
+}




More information about the llvm-commits mailing list