[cfe-dev] Clang Plugin for Msys2's mingw x86_64-w64-windows
mark via cfe-dev
cfe-dev at lists.llvm.org
Mon May 25 14:42:34 PDT 2020
Hello there,
I am trying to create a simple Clang plugin and test it on my Windows host
with Msys2's mingw x86_64-w64-windows toolchain. The issue is that clang is
failing to "find" the plugin after loading windows plugin dll. Can you
please help me to figure out what is wrong here? I am very new to clang and
the plugin framework. Thank you for any suggestion, Mark
1. creating plugin dll:
$ make -f makefile.mk
clang++ -c -std=c++14 -fno-exceptions -fno-rtti -D_FILE_OFFSET_BITS=64
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I.
-Ic:/msys64/mingw64/include example_plugin_clang.cpp -o
example_plugin_clang.o
clang++ -shared example_plugin_clang.o -static -o
*example-plugin-clang.dll* -Lc:/msys64/mingw64/lib
c:/msys64/mingw64/lib/*libclang-cpp.dll.a* c:/msys64/mingw64/lib/
*libLLVM.dll.a*
2. test run:
$ make -f makefile.mk test
clang++ -Xclang -load -Xclang <CURDIR> /*example-plugin-clang.dll* -Xclang
-add-plugin -Xclang example-plugin-clang -c -std=c++11 example_cpp_class.cc
-o example_cpp_class.o
error: unable to find plugin 'example-plugin-clang'
1 error generated.
mingw32-make: *** [makefile.mk:86: example_cpp_class.o] Error 1
...
$ nm example-plugin-clang.dll | grep example
00000000701c1cb0 t _GLOBAL__sub_I_example_plugin_clang.cpp
00000000701e9020 b _ZL26_example_plugin_clang_node
per example_plugin_clang.cpp:
static FrontendPluginRegistry::Add<FindDependenciesAction>
_example_plugin_clang_node(/*plugin Name=*/ "example-plugin-clang",
/*plugin Description=*/ "Print out header
dependencies");
$ ntldd example-plugin-clang.dll
libclang-cpp.dll => C:\msys64\mingw64\bin\libclang-cpp.dll
(0x0000000000e10000)
KERNEL32.dll => C:\WINDOWS\SYSTEM32\KERNEL32.dll
(0x0000000005690000)
msvcrt.dll => C:\WINDOWS\SYSTEM32\msvcrt.dll (0x00000000006d0000)
***
I tried an example for GCC plugin with the Msys2 GCC toolchain and this
works:
$ make -f makefile.mk
g++ -c -std=c++11 -Wno-literal-suffix -fno-exceptions -fno-rtti -I.
-Ic:/msys64/mingw64/include
-Ic:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/9.3.0/plugin/include
example_plugin_gcc.cpp -o example_plugin_gcc.o
g++ -shared example_plugin_gcc.o -static -o example-plugin-gcc.dll
c:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/9.3.0/plugin/*cc1plus.exe.a*
$ make -f makefile.mk test
g++ -fplugin=C:/Users/msx/demo/plugin/*example-plugin-gcc.dll* -c
-std=c++11 example_cpp_class.cc -o example_cpp_class.o
Plugin info
===========
Base name: example-plugin-gcc
Full name: C:/Users/msx/demo/plugin/example-plugin-gcc.dll
Number of arguments of this plugin:0
Version info
============
Base version: 9.3.0
Date stamp: 20200312
Dev phase:
Revision:
Configuration arguments: ../gcc-9.3.0/configure --prefix=/mingw64
--with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32
--host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32
--with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include
--libexecdir=/mingw64/lib --enable-bootstrap --with-arch=x86-64
--with-tune=generic --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++
--enable-shared --enable-static --enable-libatomic --enable-threads=posix
--enable-graphite --enable-fully-dynamic-string
--enable-libstdcxx-filesystem-ts=yes --enable-libstdcxx-time=yes
--disable-libstdcxx-pch --disable-libstdcxx-debug
--disable-isl-version-check --enable-lto --enable-libgomp
--disable-multilib --enable-checking=release --disable-rpath
--disable-win32-registry --disable-nls --disable-werror --disable-symvers
--enable-plugin --with-libiconv --with-system-zlib --with-gmp=/mingw64
--with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64
--with-pkgversion='Rev2, Built by MSYS2 project' --with-bugurl=
https://sourceforge.net/projects/msys2 --with-gnu-as --with-gnu-ld
Plugin successfully initialized
*** Other relevant info for clang plugin build ***
$ ldd example-plugin-clang.dll
ntdll.dll => /c/WINDOWS/SYSTEM32/ntdll.dll (0x7fff6fb30000)
KERNEL32.DLL => /c/WINDOWS/System32/KERNEL32.DLL (0x7fff6f890000)
KERNELBASE.dll => /c/WINDOWS/System32/KERNELBASE.dll
(0x7fff6c610000)
msvcrt.dll => /c/WINDOWS/System32/msvcrt.dll (0x7fff6d540000)
libclang-cpp.dll => /c/msys64/mingw64/bin/libclang-cpp.dll
(0x67400000)
ADVAPI32.dll => /c/WINDOWS/System32/ADVAPI32.dll (0x7fff6d020000)
sechost.dll => /c/WINDOWS/System32/sechost.dll (0x7fff6e2c0000)
zlib1.dll => /mingw64/bin/zlib1.dll (0x62e80000)
RPCRT4.dll => /c/WINDOWS/System32/RPCRT4.dll (0x7fff6cec0000)
ole32.dll => /c/WINDOWS/System32/ole32.dll (0x7fff6d300000)
combase.dll => /c/WINDOWS/System32/combase.dll (0x7fff6de50000)
ucrtbase.dll => /c/WINDOWS/System32/ucrtbase.dll (0x7fff6c970000)
bcryptPrimitives.dll => /c/WINDOWS/System32/bcryptPrimitives.dll
(0x7fff6c4e0000)
GDI32.dll => /c/WINDOWS/System32/GDI32.dll (0x7fff6e360000)
gdi32full.dll => /c/WINDOWS/System32/gdi32full.dll (0x7fff6bbf0000)
msvcp_win.dll => /c/WINDOWS/System32/msvcp_win.dll (0x7fff6c8d0000)
USER32.dll => /c/WINDOWS/System32/USER32.dll (0x7fff6dcb0000)
win32u.dll => /c/WINDOWS/System32/win32u.dll (0x7fff6ca70000)
SHELL32.dll => /c/WINDOWS/System32/SHELL32.dll (0x7fff6e390000)
cfgmgr32.dll => /c/WINDOWS/System32/cfgmgr32.dll (0x7fff6c560000)
shcore.dll => /c/WINDOWS/System32/shcore.dll (0x7fff6db80000)
libwinpthread-1.dll => /mingw64/bin/libwinpthread-1.dll (0x64940000)
windows.storage.dll => /c/WINDOWS/System32/windows.storage.dll
(0x7fff6bd90000)
profapi.dll => /c/WINDOWS/System32/profapi.dll (0x7fff6bb40000)
powrprof.dll => /c/WINDOWS/System32/powrprof.dll (0x7fff6bb70000)
shlwapi.dll => /c/WINDOWS/System32/shlwapi.dll (0x7fff6d2a0000)
kernel.appcore.dll => /c/WINDOWS/System32/kernel.appcore.dll
(0x7fff6bbd0000)
cryptsp.dll => /c/WINDOWS/System32/cryptsp.dll (0x7fff6c8b0000)
VERSION.dll => /c/WINDOWS/SYSTEM32/VERSION.dll (0x7fff60a40000)
libstdc++-6.dll => /mingw64/bin/libstdc++-6.dll (0x6fc40000)
libgcc_s_seh-1.dll => /mingw64/bin/libgcc_s_seh-1.dll (0x61440000)
libz3.dll => /c/msys64/mingw64/bin/libz3.dll (0xcf0000)
libz3.dll => /c/msys64/mingw64/bin/libz3.dll (0xcf0000)
- Tools -
Compiler:
$ clang++ --version
clang version 10.0.0 (https://github.com/msys2/MINGW-packages.git
3f880aaba91a3d9cdfb222dc270274731a2119a9)
Target: x86_64-w64-windows-gnu
Thread model: posix
InstalledDir: C:\msys64\mingw64\bin
w/
$ llvm-config --version
10.0.0
Linker:
$ /c/msys64/mingw64/bin/ld --version
GNU ld (GNU Binutils) 2.34
Copyright (C) 2020 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later
version.
This program has absolutely no warranty.
Make:
$ mingw32-make --version
GNU Make 4.3
Built for Windows32
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200525/ebba2687/attachment-0001.html>
More information about the cfe-dev
mailing list