Skip to content

Conversation

@vmustya
Copy link
Contributor

@vmustya vmustya commented Oct 8, 2024

The SymbolTableListTraits template is explicitly instantiated for the
following types:

  • llvm/lib/IR/Function.cpp
    • BasicBlock
  • llvm/lib/IR/Module.cpp
    • Function
    • GlobalAlias
    • GlobalIFunc
    • GlobalVariable

When LLVM is built on Windows with the LLVM_EXPORT_SYMBOLS_FOR_PLUGINS
option enabled, the implicit instantiation of the template prevents the
SymbolTableListTraits template from being exported. This causes link
errors when the template or IR API is used in a plugin.

This change prevents the template being implicitly instantiated for
these types.

The `SymbolTableListTraits` template is explicitly instantiated for the
following types:
  * `llvm/lib/IR/Function.cpp`
    - `BasicBlock`
  * `llvm/lib/IR/Module.cpp`
    - `Function`
    - `GlobalAlias`
    - `GlobalIFunc`
    - `GlobalVariable`

When LLVM is built on Windows with the `LLVM_EXPORT_SYMBOLS_FOR_PLUGINS`
option enabled, the implicit instantiation of the template prevents the
`SymbolTableListTraits` template from being exported. This causes link
errors when the template or IR API is used in a plugin.

This change prevents the template being implicitly instantiated for
these types.
@llvmbot llvmbot added the llvm:ir label Oct 8, 2024
@llvmbot
Copy link
Member

llvmbot commented Oct 8, 2024

@llvm/pr-subscribers-llvm-ir

Author: Victor Mustya (vmustya)

Changes

The SymbolTableListTraits template is explicitly instantiated for the
following types:

  • llvm/lib/IR/Function.cpp
    • BasicBlock
  • llvm/lib/IR/Module.cpp
    • Function
    • GlobalAlias
    • GlobalIFunc
    • GlobalVariable

When LLVM is built on Windows with the LLVM_EXPORT_SYMBOLS_FOR_PLUGINS
option enabled, the implicit instantiation of the template prevents the
SymbolTableListTraits template from being exported. This causes link
errors when the template or IR API is used in a plugin.

This change prevents the template being implicitly instantiated for
these types.


Full diff: https://github.com/llvm/llvm-project/pull/111600.diff

1 Files Affected:

  • (modified) llvm/include/llvm/IR/SymbolTableListTraits.h (+9)
diff --git a/llvm/include/llvm/IR/SymbolTableListTraits.h b/llvm/include/llvm/IR/SymbolTableListTraits.h
index bd31fca5e525b6..fcf6f0fb152804 100644
--- a/llvm/include/llvm/IR/SymbolTableListTraits.h
+++ b/llvm/include/llvm/IR/SymbolTableListTraits.h
@@ -106,6 +106,15 @@ class SymbolTableListTraits : public ilist_alloc_traits<ValueSubClass> {
   static ValueSymbolTable *toPtr(ValueSymbolTable &R) { return &R; }
 };
 
+// The SymbolTableListTraits template is explicitly instantiated for the
+// following data types, so add extern template statements to prevent implicit
+// instantiation.
+extern template class SymbolTableListTraits<BasicBlock>;
+extern template class SymbolTableListTraits<Function>;
+extern template class SymbolTableListTraits<GlobalAlias>;
+extern template class SymbolTableListTraits<GlobalIFunc>;
+extern template class SymbolTableListTraits<GlobalVariable>;
+
 /// List that automatically updates parent links and symbol tables.
 ///
 /// When nodes are inserted into and removed from this list, the associated

@michalpaszkowski
Copy link
Member

@nikic Could you please take a look?

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@michalpaszkowski michalpaszkowski merged commit 15dc2d5 into llvm:main Oct 9, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants