Commit 2ec8bc4
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 two patches for the Clang 20 build:
- plugin-registry-symbols_clang_20-llvm-pr-163391.patch:
Make extract_symbols.py recognize and export Registry<T>::Head and
::Tail static members for any Registry instantiation.
References Registry<PluginASTAction>::add_node() and ::begin() to force
the linker to include these symbols.
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 in Windows.
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 2ec8bc4
File tree
3 files changed
+95
-1
lines changed- build/build-clang
3 files changed
+95
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
Lines changed: 62 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 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
Lines changed: 30 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 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
0 commit comments