[PATCH] D53683: [ELF] Add --{, no-}call-graph-profile (disabled by default)

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 24 17:06:22 PDT 2018


MaskRay created this revision.
MaskRay added reviewers: ruiu, Bigcheese.
Herald added subscribers: llvm-commits, arichardson, emaste.
Herald added a reviewer: espindola.

Currently .llvm.call-graph-profile is read unconditionally to reorder sections. This is very intrusive. --icf=safe functionality is enabled by an explicit option. We should do the same thing for .llvm.call-graph-profile


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D53683

Files:
  ELF/Config.h
  ELF/Driver.cpp
  ELF/Options.td
  test/ELF/cgprofile-obj-warn.s
  test/ELF/cgprofile-obj.s


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", at progbits
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", at progbits
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: 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<MemoryBufferRef> Buffer = readFile(Arg->getValue()))
-      readCallGraph(*Buffer);
-  readCallGraphsFromObjectFiles<ELFT>();
+  if (Config->EnableCallGraphProfile) {
+    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>();
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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53683.171027.patch
Type: text/x-patch
Size: 3023 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181025/4f2f8abb/attachment.bin>


More information about the llvm-commits mailing list