<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Symbol ordering file is silently ignored with cgprofile generated with CGProfilePass"
href="https://bugs.llvm.org/show_bug.cgi?id=41804">41804</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Symbol ordering file is silently ignored with cgprofile generated with CGProfilePass
</td>
</tr>
<tr>
<th>Product</th>
<td>lld
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>ELF
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>tcwang@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, peter.smith@linaro.org
</td>
</tr></table>
<p>
<div>
<pre>I have found some problems in LLD dealing with the two flags
(--call-graph-order-file, and --symbol-ordering-file) that manipulates symbol
ordering. It might cause some confusions of precedence, especially if using new
pass manager.
Problem that I found:
In LLD, when we use a symbol ordering file (passed with
--symbol-ordering-file), we expect LLD to lay out symbols in the same order as
specified in the file. Also, there is another sort of ordering file: C3
ordering
(<a href="https://research.fb.com/wp-content/uploads/2017/01/cgo2017-hfsort-final1.pdf">https://research.fb.com/wp-content/uploads/2017/01/cgo2017-hfsort-final1.pdf</a>?).
It is implemented as a separate file passed with --call-graph-ordering-file. If
it's provided, LLD will order symbols using the call graph and do C3 stuff.
[With legacy pass manager] Currently in LLD, if both flags are provided,
--call-graph-ordering-file=<file> always takes precedence than
--symbol-ordering-file=<file>
(<a href="https://github.com/llvm/llvm-project/blob/master/lld/ELF/Writer.cpp#L1129">https://github.com/llvm/llvm-project/blob/master/lld/ELF/Writer.cpp#L1129</a>).
This itself might cause a problem and we should probably do the same assumption
as other flags: take whichever flags comes last.
[With new pass manager] After the introduction new CGProfilePass
(<a href="https://github.com/llvm/llvm-project/blob/2946cd701067404b99c39fb29dc9c74bd7193eb3/llvm/lib/Transforms/Instrumentation/CGProfile.cpp">https://github.com/llvm/llvm-project/blob/2946cd701067404b99c39fb29dc9c74bd7193eb3/llvm/lib/Transforms/Instrumentation/CGProfile.cpp</a>),
which is triggered by new pass manager by default, will construct a call graph
through either instrumentation profiles or sample profiles and save the
information into a special section in each object file. And then LLD will
construct a call graph from these sections in object files (unless
--no-call-graph-profile-sort is passed). With the call graph constructed in
LLD, LLD will do C3 ordering by default if profiles are provided. This will be
a problem if a user specify --symbol-ordering-file and it will be silently
ignored since call graph takes precedence. This will silently break many cases
where users start to try new pass manager with profiles (so cgprofile is
generated implicitly) but keep using symbol ordering file. (In this case, they
should remember to always pass --no-call-graph-profile-sort with
--symbol-ordering-file to avoid the problem)
Possible solution:
I plan to submit a patch later to fix this problem. Any suggestions are
welcome.
Our proposal is to take whichever flag is passed later, if both flags are
specified explicitly. If only --symbol-ordering-file is present, cgprofile must
be ignored because it means the user wants to use symbol ordering. If none of
the flags are specified, we should keep the current behavior: do c3 ordering by
default if profiles are provided and use new pass manager, or do nothing if
not.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>