From a25b5bf51429b81c09fef230105bbe17fd9688a4 Mon Sep 17 00:00:00 2001 From: Victor Mustya Date: Fri, 31 Oct 2025 17:50:12 -0700 Subject: [PATCH] [Windows] Adjust exported symbols in static builds with plugin support When buildint LLVM and Clang on Windows with plugin support enabled, some symbols are redundantly exported due to template instantiations and lambda functions. These symbols are not needed in the importing translation units and can be safely removed. In the meantime, the global variables and static data members are needed for correct linking and runtime behavior, so they are added to the export list. Also, the `llvm::::dump()` and `clang::::dump()` methods are not needed for linking in importing translation units, because they are only available in debug builds and should be only used for debugging purposes. Therefore, these methods are removed from the export list. --- llvm/utils/extract_symbols.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/llvm/utils/extract_symbols.py b/llvm/utils/extract_symbols.py index 0cbfd2e2910e1..5254d16e410d5 100755 --- a/llvm/utils/extract_symbols.py +++ b/llvm/utils/extract_symbols.py @@ -97,6 +97,16 @@ def should_keep_microsoft_symbol(symbol, calling_convention_decoration): # don't elif symbol.startswith("??_G") or symbol.startswith("??_E"): return None + # Delete template instantiations. These start with ?$ and can be discarded + # because they will be instantiated in the importing translation unit if + # needed. + elif symbol.startswith("??$"): + return None + # Delete lambda object constructors and operator() functions. These start + # with ??R ::= exceptions are not allowed - elif re.search(r"(llvm|clang)@@[A-Z][A-Z0-9_]*[A-JQ].+(X|.+@|.*Z)$", symbol): + elif re.search(r"@(llvm|clang)@@[A-Z][A-Z0-9_]*[A-JQ].+(X|.+@|.*Z)$", symbol): + # Remove llvm::::dump and clang::::dump methods because + # they are used for debugging only. + if symbol.startswith("?dump@"): + return None + return symbol + # Keep mangled global variables and static class members in llvm:: namespace. + # These have a type mangling that looks like (this is derived from + # clang/lib/AST/MicrosoftMangle.cpp): + # ::= + # ::= 0 # private static member + # ::= 1 # protected static member + # ::= 2 # public static member + # ::= 3 # global + # ::= 4 # static local + # ::= + # ::= # pointers, references + elif re.search(r"@llvm@@[0-3].*$", symbol): return symbol return None