[clang] [Docs][LTO] Updated HowToSubmitABug.rst for LTO crashes (PR #68389)

2023-10-26 Thread Shivam Gupta via cfe-commits

https://github.com/xgupta updated 
https://github.com/llvm/llvm-project/pull/68389

>From bdf991f4563e3aa840bec35b1678ad4fe8f9fbb6 Mon Sep 17 00:00:00 2001
From: Shivam Gupta 
Date: Fri, 6 Oct 2023 12:32:24 +0530
Subject: [PATCH 1/5] [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, CXXFLAG​S 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" a.out.0.0.preopt.bc``
+#. ``opt "-passes=lto" a.out.0.2.internalize.bc``
+#. ``opt "-passes=lto" 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" $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 1823285171ddbefc49065c4995e9c33bee7b952a Mon Sep 17 00:00:00 2001
From: Shivam Gupta 
Date: Thu, 19 Oct 2023 10:57:25 +0530
Subject: [PATCH 2/5] 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, CXXFLAG​S 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 0e19d37bf4eb9a312b4989fe941837e285f92a97 Mon Sep 17 00:00:00 2001
From: Shivam Gupta 
Date: Thu, 19 Oct 2023 12:29:23 +0530
Subject: [PATCH 3/5] 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, CXXFLAG​S 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=

[clang] [Docs][LTO] Updated HowToSubmitABug.rst for LTO crashes (PR #68389)

2023-10-23 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov edited 
https://github.com/llvm/llvm-project/pull/68389
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Docs][LTO] Updated HowToSubmitABug.rst for LTO crashes (PR #68389)

2023-10-23 Thread Matheus Izvekov via cfe-commits


@@ -153,6 +153,67 @@ 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 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:
+
+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"
+
+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"

mizvekov wrote:

```suggestion
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.

https://github.com/llvm/llvm-project/pull/68389
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Docs][LTO] Updated HowToSubmitABug.rst for LTO crashes (PR #68389)

2023-10-23 Thread Matheus Izvekov via cfe-commits


@@ -153,6 +153,67 @@ 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 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:
+
+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"
+
+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"

mizvekov wrote:

Well, I never mind the bash syntax, as that could be justified as exposition 
only.
And really all combinations are possible here, as bash is available on windows, 
powershell is available on linux, and clang-cl can be used from a linux host as 
well.

Roughly, however you choose to expose this, these are the options the user 
needs to pass:
* The user needs to be using lld-link obviously.
  * On simple cases where the linker is being called from the compiler driver, 
as is the norm on GCC-based compiler drivers, we would already be expecting the 
user to be passing `-fuse-ld=lld-link`, the flag is spelled the same there.
  * However, unlike on GCC world, on MSVC it's normal / expected that the user 
will be calling the linker directly.
* The linker flag that performs save-temps is `/lldsavetemps` as I explained 
earlier.
* Forwarding linker options from the clang-cl driver needs `/link`, like so: 
`/link /lldsavetemps`.

https://github.com/llvm/llvm-project/pull/68389
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Docs][LTO] Updated HowToSubmitABug.rst for LTO crashes (PR #68389)

2023-10-19 Thread Shivam Gupta via cfe-commits

https://github.com/xgupta updated 
https://github.com/llvm/llvm-project/pull/68389

>From bdf991f4563e3aa840bec35b1678ad4fe8f9fbb6 Mon Sep 17 00:00:00 2001
From: Shivam Gupta 
Date: Fri, 6 Oct 2023 12:32:24 +0530
Subject: [PATCH 1/2] [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, CXXFLAG​S 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" a.out.0.0.preopt.bc``
+#. ``opt "-passes=lto" a.out.0.2.internalize.bc``
+#. ``opt "-passes=lto" 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" $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 1823285171ddbefc49065c4995e9c33bee7b952a Mon Sep 17 00:00:00 2001
From: Shivam Gupta 
Date: Thu, 19 Oct 2023 10:57:25 +0530
Subject: [PATCH 2/2] 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, CXXFLAG​S 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)

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits