[llvm] [Docs][LTO] Updated HowToSubmitABug.rst for LTO crashes (PR #68389)
Shivam Gupta via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 2 23:40:03 PDT 2023
https://github.com/xgupta updated https://github.com/llvm/llvm-project/pull/68389
>From 71388c8b276a2942f97efe27d8d6c483b828206c Mon Sep 17 00:00:00 2001
From: Shivam Gupta <shivam98.tkg at gmail.com>
Date: Fri, 6 Oct 2023 12:32:24 +0530
Subject: [PATCH 1/7] [Docs][LTO] Update HowToSubmitABug.rst for LTO crashes
---
llvm/docs/HowToSubmitABug.rst | 51 +++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/llvm/docs/HowToSubmitABug.rst b/llvm/docs/HowToSubmitABug.rst
index 733dae6c928d098..88f9af44add7c64 100644
--- a/llvm/docs/HowToSubmitABug.rst
+++ b/llvm/docs/HowToSubmitABug.rst
@@ -153,6 +153,57 @@ Please run this, then file a bug with the instructions and reduced .bc file
that bugpoint emits. If something goes wrong with bugpoint, please submit
the "foo.bc" file and the option that llc crashes with.
+.. _lto-crash:
+
+LTO bugs
+---------------------------
+
+If you find a bug that crashes llvm in LTO phase (by using -flto option),
+compile your source file to a .bc file by passing
+"``-flto -fuse-ld=lld -Wl,-plugin-opt=save-temps``"
+to clang (in addition to the options you already pass). If you are building
+a project, pass the appropriate CFLAGS, CXXFLAGS and LDFLAGS for example -
+
+.. code-block:: bash
+
+ export CFLAGS="-flto -fuse-ld=lld" CXXFLAGS="-flto -fuse-ld=lld" LDFLAGS="-Wl,-plugin-opt=save-temps"
+
+This will generate four intermediate bytecode files:
+
+1. a.out.0.0.preopt.bc (Before any link-time optimizations (LTO) are applied)
+2. a.out.0.2.internalize.bc (After initial optimizations applied)
+3. a.out.0.4.opt.bc (After the more extensive set of optimizations has been applied)
+4. a.out.0.5.precodegen.bc (After LTO but before it's translated into machine code)
+
+Once you have these, one of the following commands should fail:
+
+#. ``opt "-passes=lto<O3>" a.out.0.0.preopt.bc``
+#. ``opt "-passes=lto<O3>" a.out.0.2.internalize.bc``
+#. ``opt "-passes=lto<O3>" a.out.0.4.opt.bc``
+#. ``llc a.out.0.5.precodegen.bc``
+
+If one of these do crash, you should be able to reduce
+this with :program:`llvm-reduce`
+command line (use the bc file corresponding to the command above that failed):
+
+#. ``llvm-reduce --test llvm-reduce.sh a.out.0.2.internalize.bc``
+
+An example of ``llvm-reduce.sh`` script
+
+.. code-block:: bash
+
+ $ cat llvm-reduce.sh
+ #!/usr/bin/env bash
+
+ $HOME/llvm/llvm-project/build/bin/opt "-passes=lto<O3>" $1 -o temp.bc 2>&1 | tee err.log
+ grep "It->second == &Insn" err.log
+ exit $?
+
+Here we have grepped the failed assert message.
+
+Please run this, then file a bug with the instructions and reduced .bc file
+that llvm-reduce emits.
+
.. _miscompiling:
Miscompilations
>From 6938d92537fe32e93d105b9eaaa978f7a8941338 Mon Sep 17 00:00:00 2001
From: Shivam Gupta <shivam98.tkg at gmail.com>
Date: Thu, 19 Oct 2023 10:57:25 +0530
Subject: [PATCH 2/7] address review comment
---
llvm/docs/HowToSubmitABug.rst | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/llvm/docs/HowToSubmitABug.rst b/llvm/docs/HowToSubmitABug.rst
index 88f9af44add7c64..197ed3e0fde6893 100644
--- a/llvm/docs/HowToSubmitABug.rst
+++ b/llvm/docs/HowToSubmitABug.rst
@@ -168,6 +168,12 @@ a project, pass the appropriate CFLAGS, CXXFLAGS and LDFLAGS for example -
export CFLAGS="-flto -fuse-ld=lld" CXXFLAGS="-flto -fuse-ld=lld" LDFLAGS="-Wl,-plugin-opt=save-temps"
+On Windows, you should use lld-link as the linker.
+
+.. code-block:: bash
+
+ export CFLAGS="-flto -fuse-ld=lld-link" CXXFLAGS="-flto -fuse-ld=lld-link" LDFLAGS="-Wl,-plugin-opt=save-temps"
+
This will generate four intermediate bytecode files:
1. a.out.0.0.preopt.bc (Before any link-time optimizations (LTO) are applied)
>From 1d4f16317b7b6f8c683285df9cafe071dd894d7d Mon Sep 17 00:00:00 2001
From: Shivam Gupta <shivam98.tkg at gmail.com>
Date: Thu, 19 Oct 2023 12:29:23 +0530
Subject: [PATCH 3/7] rebase and improve some wording
---
llvm/docs/HowToSubmitABug.rst | 36 ++++++++++++++++++++---------------
1 file changed, 21 insertions(+), 15 deletions(-)
diff --git a/llvm/docs/HowToSubmitABug.rst b/llvm/docs/HowToSubmitABug.rst
index 197ed3e0fde6893..7e9ac089a0f70a1 100644
--- a/llvm/docs/HowToSubmitABug.rst
+++ b/llvm/docs/HowToSubmitABug.rst
@@ -158,30 +158,34 @@ the "foo.bc" file and the option that llc crashes with.
LTO bugs
---------------------------
-If you find a bug that crashes llvm in LTO phase (by using -flto option),
-compile your source file to a .bc file by passing
-"``-flto -fuse-ld=lld -Wl,-plugin-opt=save-temps``"
-to clang (in addition to the options you already pass). If you are building
-a project, pass the appropriate CFLAGS, CXXFLAGS and LDFLAGS for example -
+If you encounter a bug that leads to crashes in the LLVM LTO phase when using
+the `-flto` option, follow these steps to diagnose and report the issue:
+
+Compile your source file to a .bc (Bitcode) file with the following flags,
+in addition to your existing compilation options:
.. code-block:: bash
export CFLAGS="-flto -fuse-ld=lld" CXXFLAGS="-flto -fuse-ld=lld" LDFLAGS="-Wl,-plugin-opt=save-temps"
-On Windows, you should use lld-link as the linker.
+These flags enable LTO and save temporary files generated during compilation
+for later analysis.
+
+On Windows, you should use lld-link as the linker. Adjust your compilation
+flags as follows:
.. code-block:: bash
export CFLAGS="-flto -fuse-ld=lld-link" CXXFLAGS="-flto -fuse-ld=lld-link" LDFLAGS="-Wl,-plugin-opt=save-temps"
-This will generate four intermediate bytecode files:
+Using the specified flags will generate four intermediate bytecode files:
-1. a.out.0.0.preopt.bc (Before any link-time optimizations (LTO) are applied)
-2. a.out.0.2.internalize.bc (After initial optimizations applied)
-3. a.out.0.4.opt.bc (After the more extensive set of optimizations has been applied)
-4. a.out.0.5.precodegen.bc (After LTO but before it's translated into machine code)
+#. a.out.0.0.preopt.bc (Before any link-time optimizations (LTO) are applied)
+#. a.out.0.2.internalize.bc (After initial optimizations are applied)
+#. a.out.0.4.opt.bc (After an extensive set of optimizations)
+#. a.out.0.5.precodegen.bc (After LTO but before translating into machine code)
-Once you have these, one of the following commands should fail:
+Execute one of the following commands to identify the source of the problem:
#. ``opt "-passes=lto<O3>" a.out.0.0.preopt.bc``
#. ``opt "-passes=lto<O3>" a.out.0.2.internalize.bc``
@@ -192,13 +196,15 @@ If one of these do crash, you should be able to reduce
this with :program:`llvm-reduce`
command line (use the bc file corresponding to the command above that failed):
-#. ``llvm-reduce --test llvm-reduce.sh a.out.0.2.internalize.bc``
+.. code-block:: bash
+
+ llvm-reduce --test reduce.sh a.out.0.2.internalize.bc
-An example of ``llvm-reduce.sh`` script
+Example of reduce.sh Script
.. code-block:: bash
- $ cat llvm-reduce.sh
+ $ cat reduce.sh
#!/usr/bin/env bash
$HOME/llvm/llvm-project/build/bin/opt "-passes=lto<O3>" $1 -o temp.bc 2>&1 | tee err.log
>From a29850a29af669bf95b2a1307ca39dda9290f40b Mon Sep 17 00:00:00 2001
From: Shivam Gupta <shivam98.tkg at gmail.com>
Date: Thu, 19 Oct 2023 13:24:40 +0530
Subject: [PATCH 4/7] minor change
---
llvm/docs/HowToSubmitABug.rst | 2 --
1 file changed, 2 deletions(-)
diff --git a/llvm/docs/HowToSubmitABug.rst b/llvm/docs/HowToSubmitABug.rst
index 7e9ac089a0f70a1..95fd6ca62a762be 100644
--- a/llvm/docs/HowToSubmitABug.rst
+++ b/llvm/docs/HowToSubmitABug.rst
@@ -153,8 +153,6 @@ Please run this, then file a bug with the instructions and reduced .bc file
that bugpoint emits. If something goes wrong with bugpoint, please submit
the "foo.bc" file and the option that llc crashes with.
-.. _lto-crash:
-
LTO bugs
---------------------------
>From ea9b899a43ead30b13d9c9c9b304e32937ed9d0e Mon Sep 17 00:00:00 2001
From: Shivam Gupta <shivam98.tkg at gmail.com>
Date: Thu, 26 Oct 2023 12:56:54 +0530
Subject: [PATCH 5/7] committed suggestion
Co-authored-by: Matheus Izvekov <mizvekov at gmail.com>
---
llvm/docs/HowToSubmitABug.rst | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/llvm/docs/HowToSubmitABug.rst b/llvm/docs/HowToSubmitABug.rst
index 95fd6ca62a762be..effba8a1c27ce77 100644
--- a/llvm/docs/HowToSubmitABug.rst
+++ b/llvm/docs/HowToSubmitABug.rst
@@ -169,12 +169,10 @@ in addition to your existing compilation options:
These flags enable LTO and save temporary files generated during compilation
for later analysis.
-On Windows, you should use lld-link as the linker. Adjust your compilation
+On Windows, you should be using lld-link as the linker. Adjust your compilation
flags as follows:
-
-.. code-block:: bash
-
- export CFLAGS="-flto -fuse-ld=lld-link" CXXFLAGS="-flto -fuse-ld=lld-link" LDFLAGS="-Wl,-plugin-opt=save-temps"
+* Add `/lldsavetemps` to the linker flags.
+* When linking from the compiler driver, add `/link /lldsavetemps` in order to forward that flag to the linker.
Using the specified flags will generate four intermediate bytecode files:
>From 2eba86180f79f57e736b1425adf79097538ba0f4 Mon Sep 17 00:00:00 2001
From: Shivam Gupta <shivam98.tkg at gmail.com>
Date: Sun, 29 Oct 2023 17:14:18 +0530
Subject: [PATCH 6/7] Address comments
---
llvm/docs/HowToSubmitABug.rst | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/llvm/docs/HowToSubmitABug.rst b/llvm/docs/HowToSubmitABug.rst
index effba8a1c27ce77..e99ac60805d24b1 100644
--- a/llvm/docs/HowToSubmitABug.rst
+++ b/llvm/docs/HowToSubmitABug.rst
@@ -183,9 +183,7 @@ Using the specified flags will generate four intermediate bytecode files:
Execute one of the following commands to identify the source of the problem:
-#. ``opt "-passes=lto<O3>" a.out.0.0.preopt.bc``
#. ``opt "-passes=lto<O3>" a.out.0.2.internalize.bc``
-#. ``opt "-passes=lto<O3>" a.out.0.4.opt.bc``
#. ``llc a.out.0.5.precodegen.bc``
If one of these do crash, you should be able to reduce
@@ -204,8 +202,7 @@ Example of reduce.sh Script
#!/usr/bin/env bash
$HOME/llvm/llvm-project/build/bin/opt "-passes=lto<O3>" $1 -o temp.bc 2>&1 | tee err.log
- grep "It->second == &Insn" err.log
- exit $?
+ grep -q "It->second == &Insn" err.log
Here we have grepped the failed assert message.
>From a69f41ec89579ea3deecad0e67b81db2be6e94b2 Mon Sep 17 00:00:00 2001
From: Shivam Gupta <shivam98.tkg at gmail.com>
Date: Fri, 3 Nov 2023 12:08:55 +0530
Subject: [PATCH 7/7] addressed comments
---
llvm/docs/HowToSubmitABug.rst | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/llvm/docs/HowToSubmitABug.rst b/llvm/docs/HowToSubmitABug.rst
index e99ac60805d24b1..caa9a20129c05a2 100644
--- a/llvm/docs/HowToSubmitABug.rst
+++ b/llvm/docs/HowToSubmitABug.rst
@@ -157,22 +157,22 @@ LTO bugs
---------------------------
If you encounter a bug that leads to crashes in the LLVM LTO phase when using
-the `-flto` option, follow these steps to diagnose and report the issue:
+the ``-flto`` option, follow these steps to diagnose and report the issue:
-Compile your source file to a .bc (Bitcode) file with the following flags,
+Compile your source file to a ``.bc`` (Bitcode) file with the following options,
in addition to your existing compilation options:
.. code-block:: bash
export CFLAGS="-flto -fuse-ld=lld" CXXFLAGS="-flto -fuse-ld=lld" LDFLAGS="-Wl,-plugin-opt=save-temps"
-These flags enable LTO and save temporary files generated during compilation
+These options enable LTO and save temporary files generated during compilation
for later analysis.
On Windows, you should be using lld-link as the linker. Adjust your compilation
flags as follows:
-* Add `/lldsavetemps` to the linker flags.
-* When linking from the compiler driver, add `/link /lldsavetemps` in order to forward that flag to the linker.
+* Add ``/lldsavetemps`` to the linker flags.
+* When linking from the compiler driver, add ``/link /lldsavetemps`` in order to forward that flag to the linker.
Using the specified flags will generate four intermediate bytecode files:
@@ -199,9 +199,9 @@ Example of reduce.sh Script
.. code-block:: bash
$ cat reduce.sh
- #!/usr/bin/env bash
+ #!/bin/bash -e
- $HOME/llvm/llvm-project/build/bin/opt "-passes=lto<O3>" $1 -o temp.bc 2>&1 | tee err.log
+ path/to/not --crash path/to/opt "-passes=lto<O3>" $1 -o temp.bc 2> err.log
grep -q "It->second == &Insn" err.log
Here we have grepped the failed assert message.
More information about the llvm-commits
mailing list