Skip to content

Commit 814542e

Browse files
zondMartin Bruse
authored andcommitted
Bug 1941482 - Enable Clang 20 support for Firefox with Windows plugin fixes r=glandium
This change adds support for building Firefox with Clang 20, including critical fixes for the clang-plugin dynamic linking on Windows. Clang 20 introduced breaking changes that prevented the clang-plugin from building on Windows: 1. Clang is built with '/Zc:dllexportInlines-' which excludes inlined members like some methods of Attr classes from being dllexported. 2. The extract_symbols.py script became more aggressive in filtering symbols, blocking Registry<T> static data members (Head/Tail) that don't match function signature patterns. The fix consists of one change to the build configuration of clang-plugin, and one patch for the Clang 20 and trunk builds: - plugin-registry-symbols-llvm-pr-163391.patch: Make extract_symbols.py recognize and export Registry<T>::Head and ::Tail static members for any Registry instantiation. See llvm/llvm-project#163367 and llvm/llvm-project#163391. - Add '/Zc:dllexportInlines-' to the CXX flags when building clang-plugin, which will match the clang build configuration and inline the members instead of referencing the symbols. Differential Revision: https://phabricator.services.mozilla.com/D268255
1 parent 1a3b3e2 commit 814542e

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

build/build-clang/clang-20.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"llvmorg-22-init-4745-gbe179d069664.patch",
1414
"android-hardware-buffer-header-workaround.patch",
1515
"arm64e-hack.patch",
16-
"compiler-rt-rss-limit-heap-profile.patch"
16+
"compiler-rt-rss-limit-heap-profile.patch",
17+
"plugin-registry-symbols-llvm-pr-163391.patch"
1718
]
1819
}

build/build-clang/clang-trunk.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"revert-llvmorg-15-init-13446-g7524fe962e47.patch",
1111
"android-hardware-buffer-header-workaround_clang_21.patch",
1212
"arm64e-hack.patch",
13-
"compiler-rt-rss-limit-heap-profile.patch"
13+
"compiler-rt-rss-limit-heap-profile.patch",
14+
"plugin-registry-symbols-llvm-pr-163391.patch"
1415
]
1516
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Fix plugin registry symbols not exported in static builds with plugin support.
2+
3+
When building LLVM statically (without BUILD_SHARED_LIBS) on Windows with
4+
LLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON, external plugins cannot register through
5+
llvm::Registry<clang::PluginASTAction> because:
6+
7+
Static data members (Head, Tail) are filtered out during symbol export by
8+
extract_symbols.py because they don't match the function signature patterns
9+
that the script looks for.
10+
11+
This patch fixes the issue by adding pattern matching to extract_symbols.py
12+
to recognize and export Registry static data members.
13+
14+
Note: When both LLVM and the plugins are built with /Zc:dllexportInlines-,
15+
the static methods (add_node(), begin()) are inlined by the plugin at call
16+
sites, so only the data symbols need to be exported.
17+
18+
See https://github.com/llvm/llvm-project/issues/163367
19+
20+
diff --git a/llvm/utils/extract_symbols.py b/llvm/utils/extract_symbols.py
21+
index 388723421d66..72f992f560c7 100755
22+
--- a/llvm/utils/extract_symbols.py
23+
+++ b/llvm/utils/extract_symbols.py
24+
@@ -105,6 +105,11 @@ def should_keep_microsoft_symbol(symbol, calling_convention_decoration):
25+
# Skip X86GenMnemonicTables functions, they are not exposed from llvm/include/.
26+
elif re.match(r"\?is[A-Z0-9]*@X86@llvm", symbol):
27+
return None
28+
+ # Keep Registry<T>::Head and Registry<T>::Tail static members for plugin support.
29+
+ # Pattern matches: ?Head@?$Registry@<template_args>@llvm@@ or ?Tail@?$Registry@...
30+
+ elif ("?$Registry@" in symbol and "@llvm@@" in symbol and
31+
+ (symbol.startswith("?Head@") or symbol.startswith("?Tail@"))):
32+
+ return symbol
33+
# Keep mangled llvm:: and clang:: function symbols. How we detect these is a
34+
# bit of a mess and imprecise, but that avoids having to completely demangle
35+
# the symbol name. The outermost namespace is at the end of the identifier

build/clang-plugin/moz.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ if CONFIG["HOST_OS_ARCH"] == "WINNT":
134134
# but as of writing, it's not necessary for the plugin code, so enable
135135
# the escape hatch, at least until we generally upgrade to VS 2019.
136136
HOST_DEFINES["LLVM_FORCE_USE_OLD_TOOLCHAIN"] = True
137+
# Clang 20+ needs /Zc:dllexportInlines- to work around CLANG_ABI issues with inline methods
138+
if CONFIG["HOST_CC_VERSION"] and int(CONFIG["HOST_CC_VERSION"].split(".")[0]) >= 20:
139+
extra_cxxflags += ["/Zc:dllexportInlines-"]
137140
else:
138141
extra_cxxflags = ["-fno-rtti", "-fno-exceptions"]
139142

0 commit comments

Comments
 (0)