Commit 5e9eab6
committed
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 two breaking changes that prevented the clang-plugin
from loading on Windows:
1. The CLANG_ABI macro was added to Attr classes, causing inline methods
like classof() and getAnnotation() to generate dllimport references.
This fails because these methods are defined inline in headers, not
exported from the DLL.
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 three patches for the Clang 20 build:
- add-plugin-symbols_clang_20.patch: Adds pattern matching to
extract_symbols.py to recognize and export Registry<T>::Head and
::Tail static members for any Registry instantiation. This replaces
the need for hardcoded symbol whitelists and works across different
plugin types.
See llvm/llvm-project#163367 and
llvm/llvm-project#163391.
- force-plugin-symbols_clang_20.patch: Adds C++ code to driver.cpp that
references Registry<PluginASTAction>::add_node() and ::begin() to force
the linker to include these symbols. This replaces hardcoded mangled
symbol names with type-safe references that work across compiler versions.
See llvm/llvm-project#163367 and
llvm/llvm-project#163391.
- remove-clang-abi-from-attrs_clang_20.patch: Removes the CLANG_ABI
macro from Attr class generation to prevent dllimport issues with
inline methods.
See llvm/llvm-project#163349.
To test this locally:
- Install the current clang-20 inside the firefox checkout:
`./mach artifact toolchain --from-build win64-clang-20`
- Install libxml2 (necessary for clang-mt.exe):
`./mach artifact toolchain --from-build win64-libxml2`
- Install wasm32-wasi-compiler-rt-20 (necessary for WASM compilation?):
`./mach artifact toolchain --from-build wasm32-wasi-compiler-rt-20`
- Check out llvm 20.1.8 in a directory alongside the firefox checkout.
- Try to build llvm, and fail when the wasi lib is missing:
`MOZ_FETCHES_DIR=../firefox python3 ../firefox/build/build-clang/build-clang.py -c ../firefox/build/build-clang/use-clang-cl-artifact.json -c ../firefox/build/build-clang/win64.json -c ../firefox/build/build-clang/clang-20.json -c ../firefox/build/build-clang/2stages.json`
- Copy the missing wasi lib to the stage2 build directory:
```
mkdir build/stage2/clang/lib/clang/20/lib/wasm32-unknown-wasi
cp ../firefox/compiler-rt-wasm32-wasi/lib/wasi/libclang_rt.builtins-wasm32.a build/stage2/clang/lib/clang/20/lib/wasm32-unknown-wasi/libclang_rt.builtins.a
```
- Try to build llvm again and succeed:
`MOZ_FETCHES_DIR=../firefox python3 ../firefox/build/build-clang/build-clang.py -c ../firefox/build/build-clang/use-clang-cl-artifact.json -c ../firefox/build/build-clang/win64.json -c ../firefox/build/build-clang/clang-20.json -c ../firefox/build/build-clang/2stages.json`
- Update the mozconfig in the firefox checkout to turn on the clang
plugin and use the right compiler:
```
export CC=[THE LLVM CHECKOUT DIRECTORY]/build/stage2/clang/bin/clang-cl.exe
ac_add_options --enable-clang-plugin
```
- Build firefox:
`./mach clobber && ./mach configure --enable-bootstrap=no-update && ./mach build`
Differential Revision: https://phabricator.services.mozilla.com/D2682551 parent 77c24e7 commit 5e9eab6
File tree
4 files changed
+80
-1
lines changed- build/build-clang
4 files changed
+80
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
16 | 19 | | |
17 | 20 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
Lines changed: 19 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
0 commit comments