Skip to content

Commit 8e2b330

Browse files
authored
[Docs][LTO] Updated HowToSubmitABug.rst for LTO crashes (#68389)
1 parent 33a6014 commit 8e2b330

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

llvm/docs/HowToSubmitABug.rst

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,62 @@ Please run this, then file a bug with the instructions and reduced .bc file
153153
that bugpoint emits. If something goes wrong with bugpoint, please submit
154154
the "foo.bc" file and the option that llc crashes with.
155155

156+
LTO bugs
157+
---------------------------
158+
159+
If you encounter a bug that leads to crashes in the LLVM LTO phase when using
160+
the ``-flto`` option, follow these steps to diagnose and report the issue:
161+
162+
Compile your source file to a ``.bc`` (Bitcode) file with the following options,
163+
in addition to your existing compilation options:
164+
165+
.. code-block:: bash
166+
167+
export CFLAGS="-flto -fuse-ld=lld" CXXFLAGS="-flto -fuse-ld=lld" LDFLAGS="-Wl,-plugin-opt=save-temps"
168+
169+
These options enable LTO and save temporary files generated during compilation
170+
for later analysis.
171+
172+
On Windows, you should be using lld-link as the linker. Adjust your compilation
173+
flags as follows:
174+
* Add ``/lldsavetemps`` to the linker flags.
175+
* When linking from the compiler driver, add ``/link /lldsavetemps`` in order to forward that flag to the linker.
176+
177+
Using the specified flags will generate four intermediate bytecode files:
178+
179+
#. a.out.0.0.preopt.bc (Before any link-time optimizations (LTO) are applied)
180+
#. a.out.0.2.internalize.bc (After initial optimizations are applied)
181+
#. a.out.0.4.opt.bc (After an extensive set of optimizations)
182+
#. a.out.0.5.precodegen.bc (After LTO but before translating into machine code)
183+
184+
Execute one of the following commands to identify the source of the problem:
185+
186+
#. ``opt "-passes=lto<O3>" a.out.0.2.internalize.bc``
187+
#. ``llc a.out.0.5.precodegen.bc``
188+
189+
If one of these do crash, you should be able to reduce
190+
this with :program:`llvm-reduce`
191+
command line (use the bc file corresponding to the command above that failed):
192+
193+
.. code-block:: bash
194+
195+
llvm-reduce --test reduce.sh a.out.0.2.internalize.bc
196+
197+
Example of reduce.sh script
198+
199+
.. code-block:: bash
200+
201+
$ cat reduce.sh
202+
#!/bin/bash -e
203+
204+
path/to/not --crash path/to/opt "-passes=lto<O3>" $1 -o temp.bc 2> err.log
205+
grep -q "It->second == &Insn" err.log
206+
207+
Here we have grepped the failed assert message.
208+
209+
Please run this, then file a bug with the instructions and reduced .bc file
210+
that llvm-reduce emits.
211+
156212
.. _miscompiling:
157213

158214
Miscompilations

0 commit comments

Comments
 (0)