Skip to content

Commit

Permalink
[LLD] Do not combine cg_profile from obj and ordering file (#121325)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
HaohaiWen authored Jan 5, 2025
1 parent 36dd421 commit 2d9d291
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
6 changes: 3 additions & 3 deletions lld/COFF/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2878,10 +2878,10 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> 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.
Expand Down
5 changes: 3 additions & 2 deletions lld/ELF/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3215,11 +3215,12 @@ template <class ELFT> 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<MemoryBufferRef> buffer =
readFile(ctx, arg->getValue()))
readCallGraph(ctx, *buffer);
readCallGraphsFromObjectFiles<ELFT>(ctx);
} else
readCallGraphsFromObjectFiles<ELFT>(ctx);
}

// Write the result to the file.
Expand Down
8 changes: 4 additions & 4 deletions lld/test/COFF/cgprofile-obj.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions lld/test/ELF/cgprofile-obj.s
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2d9d291

Please sign in to comment.