Index: ELF/Config.h =================================================================== --- ELF/Config.h +++ ELF/Config.h @@ -135,6 +135,7 @@ bool DisableVerify; bool EhFrameHdr; bool EmitRelocs; + bool EnableCallGraphProfile; bool EnableNewDtags; bool ExecuteOnly; bool ExportDynamic; Index: ELF/Driver.cpp =================================================================== --- ELF/Driver.cpp +++ ELF/Driver.cpp @@ -786,6 +786,9 @@ Config->EhFrameHdr = Args.hasFlag(OPT_eh_frame_hdr, OPT_no_eh_frame_hdr, false); Config->EmitRelocs = Args.hasArg(OPT_emit_relocs); + Config->EnableCallGraphProfile = + Args.hasFlag(OPT_call_graph_profile, OPT_no_call_graph_profile, + Args.hasArg(OPT_call_graph_ordering_file)); Config->EnableNewDtags = Args.hasFlag(OPT_enable_new_dtags, OPT_disable_new_dtags, true); Config->Entry = Args.getLastArgValue(OPT_entry); @@ -1637,10 +1640,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->EnableCallGraphProfile) { + 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", + "Do not reorder sections with .llvm.call-graph-profile profile (default)">; + // -chroot doesn't have a help text because it is an internal option. def chroot: Separate<["--", "-"], "chroot">; Index: test/ELF/cgprofile-obj-warn.s =================================================================== --- test/ELF/cgprofile-obj-warn.s +++ test/ELF/cgprofile-obj-warn.s @@ -2,7 +2,7 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: ld.lld -e A %t -o /dev/null \ +# RUN: ld.lld --call-graph-profile -e A %t -o /dev/null \ # RUN: -noinhibit-exec -icf=all 2>&1 | FileCheck %s .section .text.C,"ax",@progbits @@ -28,7 +28,11 @@ # CHECK: unable to order absolute symbol: B -# RUN: ld.lld %t -o /dev/null \ +# No warnings if --call-graph-profile is not enabled or --no-warn-symbol-ordering + +# RUN: ld.lld --call-graph-profile %t -o /dev/null \ # RUN: -noinhibit-exec -icf=all --no-warn-symbol-ordering 2>&1 \ # RUN: | FileCheck %s --check-prefix=NOWARN +# RUN: ld.lld %t -o /dev/null -noinhibit-exec -icf=all 2>&1 \ +# RUN: | FileCheck %s --check-prefix=NOWARN # NOWARN-NOT: unable to order Index: test/ELF/cgprofile-obj.s =================================================================== --- test/ELF/cgprofile-obj.s +++ test/ELF/cgprofile-obj.s @@ -1,7 +1,7 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: ld.lld -e A %t -o %t2 +# RUN: ld.lld --call-graph-profile -e A %t -o %t2 # RUN: llvm-readobj -symbols %t2 | FileCheck %s .section .text.D,"ax",@progbits Index: test/ELF/cgprofile-shared-warn.s =================================================================== --- test/ELF/cgprofile-shared-warn.s +++ test/ELF/cgprofile-shared-warn.s @@ -2,13 +2,13 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o # RUN: ld.lld --shared %t.o -o /dev/null 2>&1 | count 0 -# RUN: ld.lld -e A --unresolved-symbols=ignore-all %t.o -o /dev/null 2>&1 | count 0 +# RUN: ld.lld --call-graph-profile -e A --unresolved-symbols=ignore-all %t.o -o /dev/null 2>&1 | count 0 # RUN: echo '.globl B; B: ret' | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %t1.o # RUN: ld.lld --shared %t1.o -o %t1.so -# RUN: ld.lld -e A %t.o %t1.so -o /dev/null 2>&1 | count 0 +# RUN: ld.lld --call-graph-profile -e A %t.o %t1.so -o /dev/null 2>&1 | count 0 -# RUN: ld.lld --gc-sections %t.o %t1.so -o /dev/null 2>&1 | count 0 +# RUN: ld.lld --call-graph-profile --gc-sections %t.o %t1.so -o /dev/null 2>&1 | count 0 .globl _start _start: ret