Hello everyone,
I build and run the LLVM (and clang) under Windows. I wanted to dive into the LLVM passes because I see a huge benefit in them for our project. So I made sure to configurate CMAKE with “CLANG_PLUGIN_SUPPORT”, “LLVM_ENABLE_PLUGINS” and “LLVM_EXPORT_SYMBOLS_FOR_PLUGINS”.
Except one project, everything build fine and I was able to execute “opt.exe” with the LLVMHello.dll – everything worked as expected!
However, then I tried using the DLL with Clang-Cl because this would be the way how to integrate it to our system. So I used:
clang-cl.exe -Xclang -load -Xclang LLVMHello.dll Test.cpp
However, this failed with:
clang-cl: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 12.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: D:\Program Files\LLVM_orc_removal\bin
clang-cl: note: diagnostic msg: Error generating preprocessed source(s).
If I remove the loading of LLVMHello.dll it works correctly again. I feel like, that LLVMHello.dll is not finding all the symbols needed. So I linked LLVMHello.dll with “clang.lib” instead of “opt.lib” - but with no success.
I also read that there are ways to include those passes directly into the source code of Clang, but I hoped to use this dynamic approach instead.
Any comments, ideas or something about this?
Kind greetings
Björn
This line seems critical:
clang-cl: error: clang frontend command failed due to signal (use -v to see invocation)
Have you tried rerunning with -v? The full invocation might be informative.
Best,
Hello Eric,
I got this now:
D:\Program Files\LLVM_orc_removal\bin>clang-cl.exe -v -Xclang -load -Xclang LLVMHello.dll Test.cpp
clang version 12.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: D:\Program Files\LLVM_orc_removal\bin
“D:\Program Files\LLVM_orc_removal\bin\clang-cl.exe” -cc1 -triple x86_64-pc-windows-msvc19.27.29111 -emit-obj -mrelax-all -mincremental-linker-compatible --mrelax-relocations -disable-free -main-file-name Test.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=none -relaxed-aliasing -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -mllvm -x86-asm-syntax=intel -tune-cpu generic -D_MT -flto-visibility-public-std --dependent-lib=libcmt --dependent-lib=oldnames -stack-protector 2 -fms-volatile -fdiagnostics-format msvc -v -resource-dir “D:\Program Files\LLVM_orc_removal\lib\clang\12.0.0” -internal-isystem “D:\Program Files\LLVM_orc_removal\lib\clang\12.0.0\include” -internal-isystem “D:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.27.29110\include” -internal-isystem “D:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.27.29110\atlmfc\include” -internal-isystem “C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt” -internal-isystem “C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared” -internal-isystem "C:
\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um" -internal-isystem “C:\Program Files (x86)\WindowsKits\10\include\10.0.18362.0\winrt” -fdeprecated-macro -fdebug-compilation-dir “D:\Program Files\LLVM_orc_removal\bin” -ferror-limit 19 -fmessage-length=120 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.27.29111 -std=c++14 -fdelayed-template-parsing -fcolor-diagnostics -load LLVMHello.dll -faddrsig -o “C:\Users\h16020\AppData\Local\Temp\Test-f1a523.obj” -x c++ Test.cpp
clang-cl: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 12.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: D:\Program Files\LLVM_orc_removal\bin
clang-cl: note: diagnostic msg: Error generating preprocessed source(s).
And here with -Xclang
D:\Program Files\LLVM_orc_removal\bin>clang-cl.exe -Xclang -v -Xclang -load -Xclang LLVMHello.dll Test.cpp
clang-cl: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 12.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: D:\Program Files\LLVM_orc_removal\bin
clang-cl: note: diagnostic msg: Error generating preprocessed source(s).
Didn’t told me much óò
Kind greetings
Björn
Hello Gaier,
This might indicate the root cause:
clang-cl: note: diagnostic msg: Error generating preprocessed source(s).
However, I have no better suggestion other than investigating with a debugger 
Btw, have you tried on Linux? Dynamically loaded plugins are not really supported on Windows. Yes, sometimes stuff works, but your mileage will vary. If you test this on Linux and it still fails then at least you will be confident that it's not related to Windows-specific limitations.
-Andrzej
Hey Andrzej,
Sadly I can not run it under Linux and also don't have debug symbols enabled (because of disk space issues...)
I'm really confused by this, because the plugin works with opt causing no issues. So.... what is opt doing differently then Clang? >o<
- Björn
The “Error generating preprocessed source(s)” message here is from a generic error trap:
https://github.com/llvm/llvm-project/blob/ba71a0746f31a2f5f9af992f569a9418133a9a38/clang/lib/Driver/Driver.cpp#L1385
I’ve found instances of this online that were resolved by increasing the heap size, so it can be caused by just about anything. The underlying command line doesn’t include a smoking gun for me either.
As Andrzej mentioned, I don’t know that dynamic plugins are actually well-supported on Windows, so this might be hard to track down without the ability to run a debugger. If you can’t build with debug symbols, can you write a step-by-step reproduction procedure so someone else can try, including all the code necessary?
Björn,
Can you try adding -fno-integrated-cc1 to the command-line, see if you get more infos?
Envoyé : November 11, 2020 8:39 AM
cc the proper mailing list.
Hi Björn
I'm really confused by this, because the plugin works with opt causing no issues. So.... what is opt doing differently then Clang? >o<
Short answer - a lot 
Long answer: Clang is a complete compiler. It will normally run the preprocessor, code-gen, middlend, backend/assembler. It consumes a lot of various input file types (C, C++, Objective-C, Objective-C++, assembly files, LLVM IR files ...) and can generate almost as many. It has its own, very complex compiler driver.
Opt is just the middlend. It consumes LLVM IR and generates LLVM IR. It's much _much_ more basic than Clang. It has it's own basic driver (i.e. main entry point, command-line options definitions and processing). It's stand-alone tool independent of Clang.
In terms of the middlend, both Clang and Opt will use similar LLVM libraries, but will drive them differently. In theory they should behave similarly, but reality is a bit more complex and nuanced 
In particular, from your error message it's clear that something goes wrong within the frontend. However, when using `opt` you completely bypass the frontend.
I hope that this helps. Sadly this doesn't solve our problem.
-Andrzej
P.S. Apologies for addressing you with your surname earlier. That was before my morning coffee 
Hey guys,
Thank you all for your answers – I try to answer you all in this mail. Big sorry if this causes spam…
@Eric:
Luckily there is no code from me involved to reproduce it, because I was starting to learn it. So to reproduce: