Index: ELF/CallGraphSort.cpp =================================================================== --- ELF/CallGraphSort.cpp +++ ELF/CallGraphSort.cpp @@ -96,11 +96,11 @@ typedef std::pair SectionPair; -// Take the edge list in Config->CallGraphProfile, resolve symbol names to +// Take the edge list in Config->CallGraphInfo, resolve symbol names to // Symbols, and generate a graph between InputSections with the provided // weights. CallGraphSort::CallGraphSort() { - MapVector &Profile = Config->CallGraphProfile; + MapVector &Profile = Config->CallGraphInfo; DenseMap SecToCluster; auto GetOrCreateNode = [&](const InputSectionBase *IS) -> int { Index: ELF/Config.h =================================================================== --- ELF/Config.h +++ ELF/Config.h @@ -118,7 +118,7 @@ std::vector BuildIdVector; llvm::MapVector, uint64_t> - CallGraphProfile; + CallGraphInfo; bool AllowMultipleDefinition; bool AndroidPackDynRelocs; bool ARMHasBlx = false; @@ -127,6 +127,7 @@ bool AsNeeded = false; bool Bsymbolic; bool BsymbolicFunctions; + bool CallGraphProfile; bool CheckSections; bool CompressDebugSections; bool Cref; Index: ELF/Driver.cpp =================================================================== --- ELF/Driver.cpp +++ ELF/Driver.cpp @@ -676,7 +676,7 @@ if (const InputSectionBase *FromSB = FindSection(Fields[0])) if (const InputSectionBase *ToSB = FindSection(Fields[1])) - Config->CallGraphProfile[std::make_pair(FromSB, ToSB)] += Count; + Config->CallGraphInfo[std::make_pair(FromSB, ToSB)] += Count; } } @@ -707,7 +707,7 @@ warnUnorderableSymbol(ToSym); } if (FromSec && ToSec) - Config->CallGraphProfile[{FromSec, ToSec}] += CGPE.cgp_weight; + Config->CallGraphInfo[{FromSec, ToSec}] += CGPE.cgp_weight; } } } @@ -786,6 +786,8 @@ Config->EhFrameHdr = Args.hasFlag(OPT_eh_frame_hdr, OPT_no_eh_frame_hdr, false); Config->EmitRelocs = Args.hasArg(OPT_emit_relocs); + Config->CallGraphProfile = + Args.hasFlag(OPT_call_graph_profile, OPT_no_call_graph_profile, true); Config->EnableNewDtags = Args.hasFlag(OPT_enable_new_dtags, OPT_disable_new_dtags, true); Config->Entry = Args.getLastArgValue(OPT_entry); @@ -1637,10 +1639,12 @@ } // Read the callgraph now that we know what was gced or icfed - if (auto *Arg = Args.getLastArg(OPT_call_graph_ordering_file)) - if (Optional Buffer = readFile(Arg->getValue())) - readCallGraph(*Buffer); - readCallGraphsFromObjectFiles(); + if (Config->CallGraphProfile) { + if (auto *Arg = Args.getLastArg(OPT_call_graph_ordering_file)) + if (Optional Buffer = readFile(Arg->getValue())) + readCallGraph(*Buffer); + readCallGraphsFromObjectFiles(); + } // Write the result to the file. writeResult(); Index: ELF/Options.td =================================================================== --- ELF/Options.td +++ ELF/Options.td @@ -74,6 +74,10 @@ defm call_graph_ordering_file: Eq<"call-graph-ordering-file", "Layout sections to optimize the given callgraph">; +defm call_graph_profile: B<"call-graph-profile", + "Reorder sections with .llvm.call-graph-profile profile (default)", + "Do not reorder sections with .llvm.call-graph-profile profile">; + // -chroot doesn't have a help text because it is an internal option. def chroot: Separate<["--", "-"], "chroot">; Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -1078,7 +1078,7 @@ static DenseMap buildSectionOrder() { DenseMap SectionOrder; // Use the rarely used option -call-graph-ordering-file to sort sections. - if (!Config->CallGraphProfile.empty()) + if (!Config->CallGraphInfo.empty()) return computeCallGraphProfileOrder(); if (Config->SymbolOrderingFile.empty()) Index: test/ELF/cgprofile-obj-warn.s =================================================================== --- test/ELF/cgprofile-obj-warn.s +++ test/ELF/cgprofile-obj-warn.s @@ -28,7 +28,10 @@ # CHECK: unable to order absolute symbol: B -# RUN: ld.lld %t -o /dev/null \ -# RUN: -noinhibit-exec -icf=all --no-warn-symbol-ordering 2>&1 \ -# RUN: | FileCheck %s --check-prefix=NOWARN +# No warnings if --no-call-graph-profile or --no-warn-symbol-ordering + +# RUN: ld.lld --no-warn-symbol-ordering %t -o /dev/null \ +# RUN: --noinhibit-exec --icf=all 2>&1 | FileCheck %s --check-prefix=NOWARN +# RUN: ld.lld --no-call-graph-profile %t -o /dev/null \ +# RUN: --noinhibit-exec --icf=all 2>&1 | FileCheck %s --check-prefix=NOWARN # NOWARN-NOT: unable to order