Skip to content

Commit 7d5c11f

Browse files
authored
[Windows] Adjust exported symbols in static builds with plugin support (#165946)
When building 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::<Class>::dump()` and `clang::<Class>::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.
1 parent 4d1f249 commit 7d5c11f

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

llvm/utils/extract_symbols.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ def should_keep_microsoft_symbol(symbol, calling_convention_decoration):
9797
# don't
9898
elif symbol.startswith("??_G") or symbol.startswith("??_E"):
9999
return None
100+
# Delete template instantiations. These start with ?$ and can be discarded
101+
# because they will be instantiated in the importing translation unit if
102+
# needed.
103+
elif symbol.startswith("??$"):
104+
return None
105+
# Delete lambda object constructors and operator() functions. These start
106+
# with ??R<lambda_ or ??0<lambda_ and can be discarded because lambdas are
107+
# usually local to a function.
108+
elif symbol.startswith("??R<lambda_") or symbol.startswith("??0<lambda_"):
109+
return None
100110
# An anonymous namespace is mangled as ?A(maybe hex number)@. Any symbol
101111
# that mentions an anonymous namespace can be discarded, as the anonymous
102112
# namespace doesn't exist outside of that translation unit.
@@ -131,7 +141,24 @@ def should_keep_microsoft_symbol(symbol, calling_convention_decoration):
131141
# ::= .+@ (list of types)
132142
# ::= .*Z (list of types, varargs)
133143
# <throw-spec> ::= exceptions are not allowed
134-
elif re.search(r"(llvm|clang)@@[A-Z][A-Z0-9_]*[A-JQ].+(X|.+@|.*Z)$", symbol):
144+
elif re.search(r"@(llvm|clang)@@[A-Z][A-Z0-9_]*[A-JQ].+(X|.+@|.*Z)$", symbol):
145+
# Remove llvm::<Class>::dump and clang::<Class>::dump methods because
146+
# they are used for debugging only.
147+
if symbol.startswith("?dump@"):
148+
return None
149+
return symbol
150+
# Keep mangled global variables and static class members in llvm:: namespace.
151+
# These have a type mangling that looks like (this is derived from
152+
# clang/lib/AST/MicrosoftMangle.cpp):
153+
# <type-encoding> ::= <storage-class> <variable-type>
154+
# <storage-class> ::= 0 # private static member
155+
# ::= 1 # protected static member
156+
# ::= 2 # public static member
157+
# ::= 3 # global
158+
# ::= 4 # static local
159+
# <variable-type> ::= <type> <cvr-qualifiers>
160+
# ::= <type> <pointee-cvr-qualifiers> # pointers, references
161+
elif re.search(r"@llvm@@[0-3].*$", symbol):
135162
return symbol
136163
return None
137164

0 commit comments

Comments
 (0)