Clang Plugins on Windows

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Clang Plugins on Windows

Renato Golin via cfe-dev
Good Afternoon All,

I have written a plugin for Clang which does additional type checking around format strings. It is currently running as a plugin on Linux and macOS machines.
We are hoping to also run it on our Windows builds, in order to boost our coverage, however I understand that the 'normal' way to use a clang plugin doesn't work on Windows. 

The plugin currently works via a RecursiveASTVisitor, and then having found an instance of a var-args function call runs the custom type checker.

This (https://stackoverflow.com/questions/25657586/how-to-enable-dll-building-for-windows-in-llvm) implies that it would be possible to alter something in the build system to compile in the plugin library statically. This would be ideal for our use case, because we are building clang from source already, and we are only using it with the plugin, never alone.
Unfortunately I can't find any information on how to go about statically linking the library into the main executable, or about other ways we could go about getting this working.

I am more than happy to modify the existing code to a new architecture if necessary, either on all 3 OSs or just on Windows,

Thanks very much for any help offered

Chris


_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Clang Plugins on Windows

Renato Golin via cfe-dev
On 30/09/2019 14:40, Christopher Baish via cfe-dev wrote:

> I have written a plugin for Clang which does additional type checking
> around format strings. It is currently running as a plugin on Linux and
> macOS machines.
> We are hoping to also run it on our Windows builds, in order to boost
> our coverage, however I understand that the 'normal' way to use a clang
> plugin doesn't work on Windows.
>
> The plugin currently works via a RecursiveASTVisitor, and then having
> found an instance of a var-args function call runs the custom type checker.
>
> This
> (https://stackoverflow.com/questions/25657586/how-to-enable-dll-building-for-windows-in-llvm)
> implies that it would be possible to alter something in the build system
> to compile in the plugin library statically. This would be ideal for our
> use case, because we are building clang from source already, and we are
> only using it with the plugin, never alone.
> Unfortunately I can't find any information on how to go about statically
> linking the library into the main executable, or about other ways we
> could go about getting this working.

We're using such a dynamic library plugin for LibreOffice.  I can't
remember all the details of how I got it working on Windows, but what
probably is relevant is building LLVM/Clang with
-DLLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON and maybe some of the options we
pass to cl.exe (aka $(COMPILER_PLUGINS_CXX) in our makefile) when
linking the plugin DLL at
<https://opengrok.libreoffice.org/xref/core/compilerplugins/Makefile-clang.mk?r=db123aba#202>.
  Maybe that helps a bit...

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Clang Plugins on Windows

Renato Golin via cfe-dev
Hi Chris,

This patch by Serge Guelton automates integration of static pass plugins:

https://reviews.llvm.org/D61446?id=221321

I'm not sure whether your plugin falls into similar category, but it's
definitely worth having a look.

-Andrzej

On 30/09/2019 14:12, Stephan Bergmann via cfe-dev wrote:

> On 30/09/2019 14:40, Christopher Baish via cfe-dev wrote:
>> I have written a plugin for Clang which does additional type checking
>> around format strings. It is currently running as a plugin on Linux
>> and macOS machines.
>> We are hoping to also run it on our Windows builds, in order to boost
>> our coverage, however I understand that the 'normal' way to use a
>> clang plugin doesn't work on Windows.
>>
>> The plugin currently works via a RecursiveASTVisitor, and then having
>> found an instance of a var-args function call runs the custom type
>> checker.
>>
>> This
>> (https://stackoverflow.com/questions/25657586/how-to-enable-dll-building-for-windows-in-llvm)
>> implies that it would be possible to alter something in the build
>> system to compile in the plugin library statically. This would be
>> ideal for our use case, because we are building clang from source
>> already, and we are only using it with the plugin, never alone.
>> Unfortunately I can't find any information on how to go about
>> statically linking the library into the main executable, or about
>> other ways we could go about getting this working.
>
> We're using such a dynamic library plugin for LibreOffice.  I can't
> remember all the details of how I got it working on Windows, but what
> probably is relevant is building LLVM/Clang with
> -DLLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON and maybe some of the options we
> pass to cl.exe (aka $(COMPILER_PLUGINS_CXX) in our makefile) when
> linking the plugin DLL at
> <https://opengrok.libreoffice.org/xref/core/compilerplugins/Makefile-clang.mk?r=db123aba#202>.
>   Maybe that helps a bit...
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Clang Plugins on Windows

Renato Golin via cfe-dev
In reply to this post by Renato Golin via cfe-dev
On Mon, Sep 30, 2019 at 2:41 PM Christopher Baish via cfe-dev
<[hidden email]> wrote:

>
> Good Afternoon All,
>
> I have written a plugin for Clang which does additional type checking around format strings. It is currently running as a plugin on Linux and macOS machines.
> We are hoping to also run it on our Windows builds, in order to boost our coverage, however I understand that the 'normal' way to use a clang plugin doesn't work on Windows.
>
> The plugin currently works via a RecursiveASTVisitor, and then having found an instance of a var-args function call runs the custom type checker.
>
> This (https://stackoverflow.com/questions/25657586/how-to-enable-dll-building-for-windows-in-llvm) implies that it would be possible to alter something in the build system to compile in the plugin library statically. This would be ideal for our use case, because we are building clang from source already, and we are only using it with the plugin, never alone.
> Unfortunately I can't find any information on how to go about statically linking the library into the main executable, or about other ways we could go about getting this working.
>
> I am more than happy to modify the existing code to a new architecture if necessary, either on all 3 OSs or just on Windows,
>
> Thanks very much for any help offered

In Chromium, we use a hack to add the plugin sources to the "clang"
CMake target, see
https://cs.chromium.org/chromium/src/tools/clang/blink_gc_plugin/CMakeLists.txt?sq=package:chromium&dr&g=0&l=31
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Clang Plugins on Windows

Renato Golin via cfe-dev
In reply to this post by Renato Golin via cfe-dev
Good Afternoon All,

Thank you very much for all of your help. A combination of these suggestions got it working for me.
For future reference:
Pass -DLLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON
Run the clang.exe binary, but pass "--driver-mode=cl" to it so that it took clang-cl style flags. This was because clang-cl wouldn't work with the plugin.

This was a summer internship for me, so this email address will become inactive. If anyone is trying to do anything similar in the future, my boss can be contacted at [hidden email] and is happy to answer questions.

Kind Regards

Chris Baish



From: Stephan Bergmann <[hidden email]>
Sent: 30 September 2019 14:12
To: [hidden email] <[hidden email]>
Cc: Christopher Baish <[hidden email]>
Subject: Re: [cfe-dev] Clang Plugins on Windows
 
On 30/09/2019 14:40, Christopher Baish via cfe-dev wrote:
> I have written a plugin for Clang which does additional type checking
> around format strings. It is currently running as a plugin on Linux and
> macOS machines.
> We are hoping to also run it on our Windows builds, in order to boost
> our coverage, however I understand that the 'normal' way to use a clang
> plugin doesn't work on Windows.
>
> The plugin currently works via a RecursiveASTVisitor, and then having
> found an instance of a var-args function call runs the custom type checker.
>
> This
> (https://stackoverflow.com/questions/25657586/how-to-enable-dll-building-for-windows-in-llvm)
> implies that it would be possible to alter something in the build system
> to compile in the plugin library statically. This would be ideal for our
> use case, because we are building clang from source already, and we are
> only using it with the plugin, never alone.
> Unfortunately I can't find any information on how to go about statically
> linking the library into the main executable, or about other ways we
> could go about getting this working.

We're using such a dynamic library plugin for LibreOffice.  I can't
remember all the details of how I got it working on Windows, but what
probably is relevant is building LLVM/Clang with
-DLLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON and maybe some of the options we
pass to cl.exe (aka $(COMPILER_PLUGINS_CXX) in our makefile) when
linking the plugin DLL at
<https://opengrok.libreoffice.org/xref/core/compilerplugins/Makefile-clang.mk?r=db123aba#202>.
  Maybe that helps a bit...


_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev