llvm-project
bc6c76a4 - [Windows] Export Registry<T> members and accessors for plugins again (#221296)

Commit
71 days ago
[Windows] Export Registry<T> members and accessors for plugins again (#221296) Since #185141 reworked `llvm::Registry`, the registered-node list lives behind the explicitly specialized `llvm::detail::getRegistryLinkListInstance<R>()` accessor defined by `LLVM_DEFINE_REGISTRY`, and the `Head`/`Tail` static data members that used to be referenced across objects are gone (#163391 had special-cased those). `extract_symbols.py` handles neither. The accessor is a `??$` function template specialization, which the script drops on the assumption that it can be instantiated in the importing translation unit; here it cannot, it is defined once by `LLVM_DEFINE_REGISTRY`. And `Registry<T>` members are only exported when some object references the `Registry` template, which nothing does anymore because every use goes through the accessor. On a static clang.exe built with `LLVM_EXPORT_SYMBOLS_FOR_PLUGINS`, the export table went from 11 `Registry<clang::PluginASTAction>` symbols on 22.1.8 to zero on 23.1.0, and linking a plugin fails: ``` lld-link: error: undefined symbol: __declspec(dllimport) public: static void __cdecl llvm::Registry<class clang::PluginASTAction>::add_node(class llvm::Registry<class clang::PluginASTAction>::node *) >>> referenced by host_Registration.obj:(_GLOBAL__sub_I_Registration.cpp) ``` Keep the accessor specializations, and treat a reference to an accessor as a reference to the `Registry` template so its explicitly instantiated members are exported as they were before. Verified on the 23.1.0 static libraries: `Registry<PluginASTAction>::add_node`, the node/iterator members and the accessor come back for every registry (PluginASTAction, PragmaHandler, GCStrategy, GCMetadataPrinter, ...), 141 symbols in total in the Itanium run over the clang libraries. The `Head`/`Tail` rule from #163391 no longer matches anything and is dropped. Related: #163367 / #163391 (the previous Registry export fix), #87865. --- **AI tool use disclosure** (per the [LLVM AI Tool Use Policy](https://llvm.org/docs/AIToolPolicy.html)): this change was developed with Claude Code assisting in the analysis and drafting. The root cause was established against real 23.1.0 binaries and libraries, and the fix was verified by running extract_symbols.py over the 23.1.0 clang static libraries (the Registry members and accessors come back) and against MSVC-mangled test objects; Firefox's Windows clang-plugin and mozsearch builds link and run against a clang.exe built with it. `llvm/test/tools/extract_symbols/` adds lit coverage for both manglings. The author reviewed the change and is accountable for and able to answer questions about it. Commits carry an `Assisted-by:` trailer.
Author
Parents
Loading