From 2d9d291da0fb94c05b31de0b08ccb881dbead798 Mon Sep 17 00:00:00 2001 From: Haohai Wen Date: Sun, 5 Jan 2025 10:38:14 +0800 Subject: [PATCH] [LLD] Do not combine cg_profile from obj and ordering file (#121325) cg_profile in object is from CGProfilePass and it is often inaccurate. While call-graph-ordering-file is provided by user. It is weird to aggregate them together especially when call-graph-ordering-file is accurate enough. --- lld/COFF/Driver.cpp | 6 +++--- lld/ELF/Driver.cpp | 5 +++-- lld/test/COFF/cgprofile-obj.s | 8 ++++---- lld/test/ELF/cgprofile-obj.s | 8 ++++---- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp index 83d3f5d4cf99c..791382fd9bdd4 100644 --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -2878,10 +2878,10 @@ void LinkerDriver::linkerMain(ArrayRef argsArr) { // Handle /call-graph-ordering-file and /call-graph-profile-sort (default on). if (config->callGraphProfileSort) { llvm::TimeTraceScope timeScope("Call graph"); - if (auto *arg = args.getLastArg(OPT_call_graph_ordering_file)) { + if (auto *arg = args.getLastArg(OPT_call_graph_ordering_file)) parseCallGraphFile(arg->getValue()); - } - readCallGraphsFromObjectFiles(ctx); + else + readCallGraphsFromObjectFiles(ctx); } // Handle /print-symbol-order. diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index f573a8d3e19f3..e8e99fa874b5d 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -3215,11 +3215,12 @@ template void LinkerDriver::link(opt::InputArgList &args) { // Read the callgraph now that we know what was gced or icfed if (ctx.arg.callGraphProfileSort != CGProfileSortKind::None) { - if (auto *arg = args.getLastArg(OPT_call_graph_ordering_file)) + if (auto *arg = args.getLastArg(OPT_call_graph_ordering_file)) { if (std::optional buffer = readFile(ctx, arg->getValue())) readCallGraph(ctx, *buffer); - readCallGraphsFromObjectFiles(ctx); + } else + readCallGraphsFromObjectFiles(ctx); } // Write the result to the file. diff --git a/lld/test/COFF/cgprofile-obj.s b/lld/test/COFF/cgprofile-obj.s index 3cb16df80eb46..756279a8b5759 100644 --- a/lld/test/COFF/cgprofile-obj.s +++ b/lld/test/COFF/cgprofile-obj.s @@ -46,7 +46,7 @@ Aa: # NO-CG: 140001002 T B # NO-CG: 140001003 T A -# CG-OBJ-OF: 140001000 T C -# CG-OBJ-OF: 140001001 t D -# CG-OBJ-OF: 140001002 T A -# CG-OBJ-OF: 140001003 T B +# CG-OBJ-OF: 140001000 t D +# CG-OBJ-OF: 140001001 T A +# CG-OBJ-OF: 140001004 T C +# CG-OBJ-OF: 140001005 T B \ No newline at end of file diff --git a/lld/test/ELF/cgprofile-obj.s b/lld/test/ELF/cgprofile-obj.s index 82c5d035540a9..14016658707af 100644 --- a/lld/test/ELF/cgprofile-obj.s +++ b/lld/test/ELF/cgprofile-obj.s @@ -49,7 +49,7 @@ Aa: # NO-CG: 0000000000201122 T B # NO-CG: 0000000000201123 T A -# CG-OBJ-OF: 0000000000201121 t D -# CG-OBJ-OF: 0000000000201120 T C -# CG-OBJ-OF: 0000000000201123 T B -# CG-OBJ-OF: 0000000000201122 T A +# CG-OBJ-OF: 0000000000201120 t D +# CG-OBJ-OF: 0000000000201124 T C +# CG-OBJ-OF: 0000000000201125 T B +# CG-OBJ-OF: 0000000000201121 T A