[cfe-dev] Running LLVMHello Pass from Clang(-cl)

Andrzej Warzynski via cfe-dev cfe-dev at lists.llvm.org
Wed Nov 11 05:54:43 PST 2020


Hi Björn

On 11/11/2020 13:15, Gaier, Bjoern wrote:
> 
> 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 :)

> - Björn
> 
> -----Original Message-----
> From: cfe-dev <cfe-dev-bounces at lists.llvm.org> On Behalf Of Andrzej Warzynski via cfe-dev
> Sent: 11 November 2020 12:56
> To: cfe-dev at lists.llvm.org
> Subject: Re: [cfe-dev] Running LLVMHello Pass from Clang(-cl)
> 
> 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
> 
> On 11/11/2020 08:16, Gaier, Bjoern via cfe-dev wrote:
>> 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
>>
>> *From:*Eric Astor <eric.astor at gmail.com>
>> *Sent:* 10 November 2020 14:50
>> *To:* Gaier, Bjoern <Bjoern.Gaier at horiba.com>
>> *Cc:* Clang Dev <cfe-dev at lists.llvm.org>
>> *Subject:* Re: [cfe-dev] Running LLVMHello Pass from Clang(-cl)
>>
>> 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,
>>
>> - Eric
>>
>> On Tue, Nov 10, 2020 at 4:13 AM Gaier, Bjoern via cfe-dev
>> <cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>> wrote:
>>
>>      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
>>
>>      Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816,
>>      USt.ID-Nr. DE 114 165 789 Geschäftsführer: Dr. Hiroshi Nakamura, Dr.
>>      Robert Plank, Markus Bode, Takashi Nagano, Junichi Tajika, Ergin
>>      Cansiz.
>>
>>      _______________________________________________
>>      cfe-dev mailing list
>>      cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>
>>      https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>      <https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev>
>>
>> Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816,
>> USt.ID-Nr. DE 114 165 789 Geschäftsführer: Dr. Hiroshi Nakamura, Dr.
>> Robert Plank, Markus Bode, Takashi Nagano, Junichi Tajika, Ergin Cansiz.
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
> Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816, USt.ID-Nr. DE 114 165 789 Geschäftsführer: Dr. Hiroshi Nakamura, Dr. Robert Plank, Markus Bode, Takashi Nagano, Junichi Tajika, Ergin Cansiz.
> 


More information about the cfe-dev mailing list