[lld] r345332 - [ELF] Add --{, no-}call-graph-profile-sort (enabled by default)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 25 16:15:23 PDT 2018


Author: maskray
Date: Thu Oct 25 16:15:23 2018
New Revision: 345332

URL: http://llvm.org/viewvc/llvm-project?rev=345332&view=rev
Log:
[ELF] Add --{,no-}call-graph-profile-sort (enabled by default)

Summary: Add an option to disable sorting sections with call graph profile

Reviewers: ruiu, Bigcheese, espindola

Reviewed By: Bigcheese

Subscribers: grimar, emaste, arichardson, llvm-commits

Differential Revision: https://reviews.llvm.org/D53683

Modified:
    lld/trunk/ELF/Config.h
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/Options.td
    lld/trunk/test/ELF/cgprofile-obj.s

Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=345332&r1=345331&r2=345332&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Thu Oct 25 16:15:23 2018
@@ -127,6 +127,7 @@ struct Configuration {
   bool AsNeeded = false;
   bool Bsymbolic;
   bool BsymbolicFunctions;
+  bool CallGraphProfileSort;
   bool CheckSections;
   bool CompressDebugSections;
   bool Cref;

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=345332&r1=345331&r2=345332&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Thu Oct 25 16:15:23 2018
@@ -770,6 +770,8 @@ void LinkerDriver::readConfigs(opt::Inpu
   Config->EhFrameHdr =
       Args.hasFlag(OPT_eh_frame_hdr, OPT_no_eh_frame_hdr, false);
   Config->EmitRelocs = Args.hasArg(OPT_emit_relocs);
+  Config->CallGraphProfileSort = Args.hasFlag(
+      OPT_call_graph_profile_sort, OPT_no_call_graph_profile_sort, true);
   Config->EnableNewDtags =
       Args.hasFlag(OPT_enable_new_dtags, OPT_disable_new_dtags, true);
   Config->Entry = Args.getLastArgValue(OPT_entry);
@@ -1621,10 +1623,12 @@ template <class ELFT> void LinkerDriver:
   }
 
   // Read the callgraph now that we know what was gced or icfed
-  if (auto *Arg = Args.getLastArg(OPT_call_graph_ordering_file))
-    if (Optional<MemoryBufferRef> Buffer = readFile(Arg->getValue()))
-      readCallGraph(*Buffer);
-  readCallGraphsFromObjectFiles<ELFT>();
+  if (Config->CallGraphProfileSort) {
+    if (auto *Arg = Args.getLastArg(OPT_call_graph_ordering_file))
+      if (Optional<MemoryBufferRef> Buffer = readFile(Arg->getValue()))
+        readCallGraph(*Buffer);
+    readCallGraphsFromObjectFiles<ELFT>();
+  }
 
   // Write the result to the file.
   writeResult<ELFT>();

Modified: lld/trunk/ELF/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Options.td?rev=345332&r1=345331&r2=345332&view=diff
==============================================================================
--- lld/trunk/ELF/Options.td (original)
+++ lld/trunk/ELF/Options.td Thu Oct 25 16:15:23 2018
@@ -74,6 +74,10 @@ defm as_needed: B<"as-needed",
 defm call_graph_ordering_file:
   Eq<"call-graph-ordering-file", "Layout sections to optimize the given callgraph">;
 
+defm call_graph_profile_sort: B<"call-graph-profile-sort",
+    "Reorder sections with call graph profile (default)",
+    "Do not reorder sections with call graph profile">;
+
 // -chroot doesn't have a help text because it is an internal option.
 def chroot: Separate<["--", "-"], "chroot">;
 

Modified: lld/trunk/test/ELF/cgprofile-obj.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/cgprofile-obj.s?rev=345332&r1=345331&r2=345332&view=diff
==============================================================================
--- lld/trunk/test/ELF/cgprofile-obj.s (original)
+++ lld/trunk/test/ELF/cgprofile-obj.s Thu Oct 25 16:15:23 2018
@@ -1,8 +1,10 @@
 # REQUIRES: x86
 
-# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
-# RUN: ld.lld -e A %t -o %t2
-# RUN: llvm-readobj -symbols %t2 | FileCheck %s
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: ld.lld -e A %t.o -o %t
+# RUN: llvm-nm --no-sort %t | FileCheck %s
+# RUN: ld.lld --no-call-graph-profile-sort -e A %t.o -o %t
+# RUN: llvm-nm --no-sort %t | FileCheck %s --check-prefix=NO-CG
 
     .section    .text.D,"ax", at progbits
 D:
@@ -31,11 +33,12 @@ Aa:
     .cg_profile B, C, 30
     .cg_profile C, D, 90
 
-# CHECK:          Name: D
-# CHECK-NEXT:     Value: 0x201003
-# CHECK:          Name: A
-# CHECK-NEXT:     Value: 0x201000
-# CHECK:          Name: B
-# CHECK-NEXT:     Value: 0x201001
-# CHECK:          Name: C
-# CHECK-NEXT:     Value: 0x201002
+# CHECK: 0000000000201003 t D
+# CHECK: 0000000000201000 T A
+# CHECK: 0000000000201001 T B
+# CHECK: 0000000000201002 T C
+
+# NO-CG: 0000000000201000 t D
+# NO-CG: 0000000000201003 T A
+# NO-CG: 0000000000201002 T B
+# NO-CG: 0000000000201001 T C




More information about the llvm-commits mailing list