Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

ThinLTO on windows produces invalid code. #33882

Open Quuxplusone opened 6 years ago

Quuxplusone commented 6 years ago
Bugzilla Link PR34909
Status NEW
Importance P enhancement
Reported by Zachary Turner (zturner@google.com)
Reported on 2017-10-10 17:05:01 -0700
Last modified on 2018-03-27 10:15:02 -0700
Version unspecified
Hardware PC Windows NT
CC llvm-bugs@lists.llvm.org, llvm@inglorion.net, peter@pcc.me.uk
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
1. Build an x86 Release version of clang using the standard MSVC compiler and
linker.

> (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

2. Build an x64 Release version of lld using the standard MSVC compiler and
linker.
> (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

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.

> (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

4. Build your LTO'ed tblgen

> ninja llvm-tblgen

5. Run tblgen.
> 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

6. Print the value of ERRORLEVEL
> echo %ERRORLEVEL%
-1073741819

This corresponds to 0xFFFFFFFFC0000005 which is access violation.
Quuxplusone commented 6 years ago

If this only happens on 32-bit, it could be the same issue as PR34306. Does it help if you patch in the fix linked from that bug?

Quuxplusone commented 6 years ago

Was just about to post that I just tested x64 clang + lld and that doesn't exhibit the same problem. I will test out the suggested fix tomorrow, thanks!

Quuxplusone commented 6 years ago

Zachary, does this work as desired now?