ClazyClangTidy plugin not working
Description / Steps to reproduce the issue
When running the following command, no checks are listed:
clang-tidy -checks=-*,clazy-* -list-checks -load ClazyClangTidy.dll
The issue seems related to how the plugin links against libclangTidy. The mingw-w64-clazy/001-fix-linking.patch patch links the ClazyClangTidy plugin with the static clangTidy library, but clang-tidy plugins actually require certain symbols to be exported from clang-tidy.exe itself.
Expected behavior
When running the following command, should print clazy serials checks:
clang-tidy -checks=-*,clazy-* -list-checks -load ClazyClangTidy.dll
Enabled checks:
clazy-assert-with-side-effects
clazy-auto-unexpected-qstringbuilder
clazy-base-class-event
clazy-child-event-qobject-cast
clazy-connect-3arg-lambda
clazy-connect-by-name
clazy-connect-non-signal
clazy-connect-not-normalized
clazy-const-signal-or-slot
clazy-container-anti-pattern
clazy-container-inside-loop
clazy-copyable-polymorphic
clazy-ctor-missing-parent-argument
clazy-detaching-member
clazy-detaching-temporary
clazy-empty-qstringliteral
clazy-foreach
clazy-fully-qualified-moc-types
clazy-function-args-by-ref
clazy-function-args-by-value
clazy-global-const-char-pointer
clazy-heap-allocated-small-trivial-type
clazy-ifndef-define-typo
clazy-implicit-casts
clazy-incorrect-emit
clazy-install-event-filter
clazy-isempty-vs-count
clazy-jni-signatures
clazy-lambda-in-connect
clazy-lambda-unique-connection
clazy-lowercase-qml-type-name
clazy-missing-qobject-macro
clazy-missing-typeinfo
clazy-mutable-container-key
clazy-no-module-include
clazy-non-pod-global-static
clazy-old-style-connect
clazy-overloaded-signal
clazy-overridden-signal
clazy-post-event
clazy-qbytearray-conversion-to-c-style
clazy-qcolor-from-literal
clazy-qdatetime-utc
clazy-qdeleteall
clazy-qenums
clazy-qfileinfo-exists
clazy-qgetenv
clazy-qhash-namespace
clazy-qhash-with-char-pointer-key
clazy-qlatin1string-non-ascii
clazy-qmap-with-pointer-key
clazy-qproperty-type-mismatch
clazy-qproperty-without-notify
clazy-qrequiredresult-candidates
clazy-qstring-allocations
clazy-qstring-arg
clazy-qstring-comparison-to-implicit-char
clazy-qstring-insensitive-allocation
clazy-qstring-left
clazy-qstring-ref
clazy-qstring-varargs
clazy-qt-keyword-emit
clazy-qt-keywords
clazy-qt-macros
clazy-qvariant-template-instantiation
clazy-range-loop-detach
clazy-range-loop-reference
clazy-raw-environment-function
clazy-readlock-detaching
clazy-reserve-candidates
clazy-returning-data-from-temporary
clazy-returning-void-expression
clazy-rule-of-three
clazy-rule-of-two-soft
clazy-sanitize-inline-keyword
clazy-signal-with-return-value
clazy-skipped-base-method
clazy-static-pmf
clazy-strict-iterators
clazy-temporary-iterator
clazy-thread-with-slots
clazy-tr-non-literal
clazy-unexpected-flag-enumerator-value
clazy-unneeded-cast
clazy-unused-non-trivial-variable
clazy-unused-result-check
clazy-use-arrow-operator-instead-of-data
clazy-use-chrono-in-qtimer
clazy-use-static-qregularexpression
clazy-used-qunused-variable
clazy-virtual-call-ctor
clazy-virtual-signal
clazy-writing-to-temporary
clazy-wrong-qevent-cast
clazy-wrong-qglobalstatic
Actual behavior
When running the following command, no checks are listed:
clang-tidy -checks=-*,clazy-* -list-checks -load ClazyClangTidy.dll
Verification
- [x] I have verified that my MSYS2 is up-to-date before submitting the report (see https://www.msys2.org/docs/updating/)
Windows Version
MINGW64_NT-10.0-26200
MINGW environments affected
- [ ] MINGW64
- [ ] MINGW32
- [ ] UCRT64
- [x] CLANG64
- [ ] CLANGARM64
Are you willing to submit a PR?
No response
@SquallATF without this patch it not linking at all. You can try provide better solution
Normally, when building Clazy on Windows, LLVM must be compiled with the CMake option -DLLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON so that the necessary plugin symbols are exported from the executable.
But LLVM_LINK_LLVM_DYLIB and LLVM_EXPORT_SYMBOLS_FOR_PLUGINS are incompatible, it’s not possible to both link against the shared LLVM library and also export plugin symbols from the executable at the same time.
One possible workaround is to:
- Build
clangTidylibrary as a shared library might be the best solution. I haven’t tested it yet, but exporting symbols from an executable feels a bit odd, or - Follow the logic in AddLLVM.cmake#L1388-L1399 and AddLLVM.cmake#L140-L166 to generate a
.deffile fromlibclangTidy.aand makeclang-tidy.exeexport the corresponding symbols. However, the generated.deffile has some issues:
it doesn’t correctly mark which exported symbols are DATA, which causes runtime errors.
To make theClazyClangTidy.dllplugin work properly, the following symbols must be manually marked asDATA:
...
_ZN4llvm8RegistryIN5clang4tidy15ClangTidyModuleEE4HeadE DATA
_ZN4llvm8RegistryIN5clang4tidy15ClangTidyModuleEE4TailE DATA
...
_ZN5clang4tidy24ClangTidyOptionsProvider30OptionsSourceTypeDefaultBinaryE DATA
_ZN5clang4tidy24ClangTidyOptionsProvider39OptionsSourceTypeCheckCommandLineOptionE DATA
_ZN5clang4tidy24ClangTidyOptionsProvider40OptionsSourceTypeConfigCommandLineOptionE DATA
...
Otherwise, the plugin will fail to load at runtime. or 3. can simply disable this plugin for now, as the currently compiled version doesn’t work correctly anyway.