|
1 | 1 | # @node-versions: v24.10.0+ |
2 | 2 | # @description: Fix abseil duplicate symbol errors on Windows |
3 | 3 | # |
4 | | -# Disables standalone abseil.lib build on Windows by changing the abseil |
5 | | -# target type from 'static_library' to 'none'. This prevents LNK2005 |
6 | | -# linker errors where absl::Mutex::Dtor and other symbols are defined |
7 | | -# in both abseil.lib and v8_libbase.lib. |
| 4 | +# Adds /FORCE:MULTIPLE linker flag globally for Windows builds to allow |
| 5 | +# duplicate symbol definitions between abseil.lib and v8_libbase.lib. |
8 | 6 | # |
9 | 7 | # Root cause: Node.js v24 extracted abseil to a separate build target |
10 | 8 | # (tools/v8_gypfiles/abseil.gyp) to share code between V8 and perfetto. |
11 | | -# On Windows with MSVC, this creates duplicate symbol errors because |
12 | | -# V8's libbase already includes the necessary abseil implementations. |
| 9 | +# v8_libbase depends on and links against abseil.lib, but some abseil |
| 10 | +# symbols end up defined in both libraries, causing LNK2005 errors when |
| 11 | +# linking executables that use both (like torque.exe). |
13 | 12 | # |
14 | | -# Solution: On Windows only, configure abseil as type 'none' so headers |
15 | | -# are available but no separate static library is built. V8's libbase |
16 | | -# continues to provide the abseil implementations it needs. |
| 13 | +# Solution: Add /FORCE:MULTIPLE to all Windows link operations via the |
| 14 | +# toolchain configuration. The linker will pick one definition of each |
| 15 | +# duplicate symbol. This is safe because the implementations are identical. |
17 | 16 | # |
18 | | -# Error: abseil.lib(abseil.mutex.obj) : error LNK2005: absl::Mutex::Dtor |
19 | | -# already defined in v8_libbase.lib(v8_libbase.mutex.obj) |
| 17 | +# Original errors: |
| 18 | +# LNK2005: absl::Mutex::Dtor already defined in v8_libbase.lib |
| 19 | +# LNK1169: one or more multiply defined symbols found |
20 | 20 | # |
21 | 21 | # References: |
22 | 22 | # - https://github.com/nodejs/node/pull/57289 (abseil extraction) |
23 | | -# - https://github.com/nodejs/node/pull/57582 (abseil deadlock detection) |
| 23 | +# - https://learn.microsoft.com/en-us/cpp/build/reference/force-force-file-output |
24 | 24 |
|
25 | | ---- a/tools/v8_gypfiles/abseil.gyp |
26 | | -+++ b/tools/v8_gypfiles/abseil.gyp |
27 | | -@@ -3,7 +3,15 @@ |
28 | | - 'targets': [ |
29 | | - { |
30 | | - 'target_name': 'abseil', |
31 | | -- 'type': 'static_library', |
32 | | -+ 'conditions': [ |
33 | | -+ ['OS=="win"', { |
34 | | -+ # On Windows, abseil symbols are already included in v8_libbase. |
35 | | -+ # Building a separate abseil.lib causes LNK2005 duplicate symbol errors. |
36 | | -+ 'type': 'none', |
37 | | -+ }, { |
38 | | -+ 'type': 'static_library', |
39 | | -+ }], |
40 | | -+ ], |
41 | | - 'toolsets': ['host', 'target'], |
42 | | - 'variables': { |
43 | | - 'ABSEIL_ROOT': '../../deps/v8/third_party/abseil-cpp', |
| 25 | +--- a/tools/v8_gypfiles/toolchain.gypi |
| 26 | ++++ b/tools/v8_gypfiles/toolchain.gypi |
| 27 | +@@ -525,6 +525,11 @@ |
| 28 | + '/bigobj', # Prevent C1128: number of sections exceeded object file format limit. |
| 29 | + ], |
| 30 | + }, |
| 31 | ++ 'VCLinkerTool': { |
| 32 | ++ 'AdditionalOptions': [ |
| 33 | ++ '/FORCE:MULTIPLE', # Allow duplicate symbol definitions (abseil.lib vs v8_libbase.lib). |
| 34 | ++ ], |
| 35 | ++ }, |
| 36 | + }, |
| 37 | + }], |
| 38 | + ['v8_target_arch=="ia32"', { |
0 commit comments