[lld] r361190 - [ELF][Driver] Fix precedence of symbol ordering file and CGProfile

Tiancong Wang via llvm-commits llvm-commits at lists.llvm.org
Mon May 20 12:13:35 PDT 2019


Author: tcwang
Date: Mon May 20 12:13:34 2019
New Revision: 361190

URL: http://llvm.org/viewvc/llvm-project?rev=361190&view=rev
Log:
[ELF][Driver] Fix precedence of symbol ordering file and CGProfile

This patch is a fix for https://bugs.llvm.org/show_bug.cgi?id=41804.
We try to solve the precedence of user-specified symbol ordering file and C3 ordering provided as call graph. It deals with two case:
(1) When both --symbol-ordering-file=<file> and --call-graph-order-file=<file> are present, whichever flag comes later will take precedence.
(2) When only --symbol-ordering-file=<file> is present, it takes precedence over implicit call graph (CGProfile) generated by CGProfilePass enabled in new pass manager.

Added:
    lld/trunk/test/ELF/symbol-ordering-file-cgprofile-conflicts.s
Modified:
    lld/trunk/ELF/Driver.cpp

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=361190&r1=361189&r2=361190&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Mon May 20 12:13:34 2019
@@ -975,9 +975,17 @@ static void readConfigs(opt::InputArgLis
   std::tie(Config->AndroidPackDynRelocs, Config->RelrPackDynRelocs) =
       getPackDynRelocs(Args);
 
-  if (auto *Arg = Args.getLastArg(OPT_symbol_ordering_file))
-    if (Optional<MemoryBufferRef> Buffer = readFile(Arg->getValue()))
+  if (auto *Arg = Args.getLastArg(OPT_symbol_ordering_file)){
+    if (Args.hasArg(OPT_call_graph_ordering_file))
+      error("--symbol-ordering-file and --call-graph-order-file "
+            "may not be used together");
+    if (Optional<MemoryBufferRef> Buffer = readFile(Arg->getValue())){
       Config->SymbolOrderingFile = getSymbolOrderingFile(*Buffer);
+      // Also need to disable CallGraphProfileSort to prevent
+      // LLD order symbols with CGProfile
+      Config->CallGraphProfileSort = false;
+    }
+  }
 
   // If --retain-symbol-file is used, we'll keep only the symbols listed in
   // the file and discard all others.
@@ -1727,7 +1735,6 @@ template <class ELFT> void LinkerDriver:
     readCallGraphsFromObjectFiles<ELFT>();
   }
 
-
   // Write the result to the file.
   writeResult<ELFT>();
 }

Added: lld/trunk/test/ELF/symbol-ordering-file-cgprofile-conflicts.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/symbol-ordering-file-cgprofile-conflicts.s?rev=361190&view=auto
==============================================================================
--- lld/trunk/test/ELF/symbol-ordering-file-cgprofile-conflicts.s (added)
+++ lld/trunk/test/ELF/symbol-ordering-file-cgprofile-conflicts.s Mon May 20 12:13:34 2019
@@ -0,0 +1,66 @@
+// REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+// RUN: ld.lld -e A %t.o --no-call-graph-profile-sort -o %t
+// RUN: llvm-nm --numeric-sort %t | FileCheck %s --check-prefix=NO_ORDERING
+// NO_ORDERING:         0000000000201000 t D
+// NO_ORDERING-NEXT:    0000000000201001 T C
+// NO_ORDERING-NEXT:    0000000000201002 T B
+// NO_ORDERING-NEXT:    0000000000201003 T A
+
+// RUN: ld.lld -e A %t.o -o %t
+// RUN: llvm-nm --numeric-sort %t | FileCheck %s --check-prefix=CALL_GRAPH
+// CALL_GRAPH:		0000000000201000 T A
+// CALL_GRAPH-NEXT:	0000000000201000 t Aa
+// CALL_GRAPH-NEXT:	0000000000201001 T B
+// CALL_GRAPH-NEXT:	0000000000201002 T C
+// CALL_GRAPH-NEXT:	0000000000201003 t D
+
+// RUN: rm -f %t.symbol_order
+// RUN: echo "C" >> %t.symbol_order
+// RUN: echo "B" >> %t.symbol_order
+// RUN: echo "D" >> %t.symbol_order
+// RUN: echo "A" >> %t.symbol_order
+
+// RUN: ld.lld -e A %t.o --symbol-ordering-file %t.symbol_order -o %t
+// RUN: llvm-nm --numeric-sort %t | FileCheck %s --check-prefix=SYMBOL_ORDER
+// SYMBOL_ORDER:	0000000000201000 T C
+// SYMBOL_ORDER-NEXT:	0000000000201001 T B
+// SYMBOL_ORDER-NEXT:	0000000000201002 t D
+// SYMBOL_ORDER-NEXT:	0000000000201003 T A
+
+// RUN: rm -f %t.call_graph
+// RUN: echo "A B 5" > %t.call_graph
+// RUN: echo "B C 50" >> %t.call_graph
+// RUN: echo "C D 40" >> %t.call_graph
+// RUN: echo "D B 10" >> %t.call_graph
+
+// RUN: not ld.lld -e A %t.o --symbol-ordering-file %t.symbol_order --call-graph-ordering-file %t.call_graph -o %t 2>&1 | FileCheck %s
+// RUN: not ld.lld -e A %t.o --call-graph-ordering-file %t.call_graph --symbol-ordering-file %t.symbol_order -o %t 2>&1 | FileCheck %s
+// CHECK: error: --symbol-ordering-file and --call-graph-order-file may not be used together
+
+    .section    .text.D,"ax", at progbits
+D:
+    retq
+
+    .section    .text.C,"ax", at progbits
+    .globl  C
+C:
+    retq
+
+    .section    .text.B,"ax", at progbits
+    .globl  B
+B:
+    retq
+
+    .section    .text.A,"ax", at progbits
+    .globl  A
+A:
+Aa:
+    retq
+
+    .cg_profile A, B, 10
+    .cg_profile A, B, 10
+    .cg_profile Aa, B, 80
+    .cg_profile A, C, 40
+    .cg_profile B, C, 30
+    .cg_profile C, D, 90




More information about the llvm-commits mailing list