<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 - ThinLTO on windows produces invalid code."
   href="https://bugs.llvm.org/show_bug.cgi?id=34909">34909</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>ThinLTO on windows produces invalid code.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </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>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>zturner@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, llvm@inglorion.net, peter@pcc.me.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>1. Build an x86 Release version of clang using the standard MSVC compiler and
linker.

<span class="quote">> (From an x86 MSVC build environment)
> cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_ENABLE_PROJECTS=clang <llvm-source-dir>
> ninja clang</span >

2. Build an x64 Release version of lld using the standard MSVC compiler and
linker.
<span class="quote">> (From an x64 MSVC build environment)
> cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_ENABLE_PROJECTS=lld <llvm-source-dir>
> ninja lld</span >

Because clang-cl uses the default target triple based on its bitness, in order
to build and link an x86 binary with clang-cl + lld, the compiler has to be
built x86, and the linker has to be built x64 (or it runs out of memory).  This
is really lame and the compiler should detect the MSVC environment that is
configured, but that isn't the way it works today.

So, continuing...

3. Configure a third build directory that uses the compiler from step 1 and the
linker from step 2, and that uses -DLLVM_ENABLE_LTO=Thin.

<span class="quote">> (From an x86 MSVC build environment)
> cmake -G Ninja -DLLVM_ENABLE_LTO=Thin -DCMAKE_C_COMPILER=<path-to-clang-cl.exe-in-step-1> -DCMAKE_CXX_COMPILER=<path-to-clang-cl.exe-in-step-1> -DCMAKE_LINKER=<path-to-lld-link.exe-in-step-2> -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_ENABLE_PROJECTS="clang;lld" ..\..\..\..\llvm-mono\llvm</span >

4. Build your LTO'ed tblgen

<span class="quote">> ninja llvm-tblgen</span >

5. Run tblgen.
<span class="quote">> bin\llvm-tblgen.exe -gen-attrs -I D:/src/llvm-mono/llvm/include/llvm/IR -I D:/src/llvm-mono/llvm/include D:/src/llvm-mono/llvm/include/llvm/IR/Attributes.td -o include/llvm/IR/Attributes.gen.tmp -d include/llvm/IR/Attributes.gen.d</span >

6. Print the value of ERRORLEVEL
<span class="quote">> echo %ERRORLEVEL%</span >
-1073741819

This corresponds to 0xFFFFFFFFC0000005 which is access violation.</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>