Skip to content

Commit 2449be6

Browse files
committed
Use lto patch for node for wasm backend
1 parent baab5d0 commit 2449be6

File tree

4 files changed

+317
-2
lines changed

4 files changed

+317
-2
lines changed

compiler/ghc/default.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ haskell-nix.haskellLib.makeCompilerDeps (stdenv.mkDerivation (rec {
594594
--replace-fail \
595595
"node --disable-warning=ExperimentalWarning --experimental-wasm-type-reflection --no-turbo-fast-api-calls --wasm-lazy-validation" \
596596
"${buildPackages.writeShellScriptBin "node" ''
597-
exec ${buildPackages.nodejs_24}/bin/node \
597+
exec ${buildPackages.nodejs-with-lto}/bin/node \
598598
--disable-warning=ExperimentalWarning \
599599
--experimental-wasm-type-reflection \
600600
--no-turbo-fast-api-calls \
@@ -619,7 +619,7 @@ haskell-nix.haskellLib.makeCompilerDeps (stdenv.mkDerivation (rec {
619619
ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour
620620
] ++ lib.optional (patches != []) autoreconfHook
621621
++ lib.optional useLdLld llvmPackages.bintools
622-
++ lib.optional (targetPlatform.isWasm) buildPackages.nodejs_24;
622+
++ lib.optional (targetPlatform.isWasm) buildPackages.nodejs-with-lto;
623623

624624
# For building runtime libs
625625
depsBuildTarget = toolsForTarget;

overlays/default.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ let
9797
lazy-inputs = import ../lazy-inputs;
9898
rcodesign = import ./rcodesign.nix;
9999
wasm = import ./wasm.nix;
100+
node-lto = import ./node-lto.nix;
100101
};
101102

102103
composeExtensions = f: g: final: prev:
@@ -132,6 +133,7 @@ let
132133
gobject-introspection
133134
hix
134135
wasm
136+
node-lto
135137
# Restore nixpkgs haskell and haskellPackages
136138
(_: prev: { inherit (prev.haskell-nix-prev) haskell haskellPackages; })
137139
cacheCompilerDeps

overlays/node-lto.nix

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
final: prev: {
2+
nodejs-with-lto = prev.pkgsStatic.nodejs_24.overrideAttrs (attrs: {
3+
LDFLAGS="-Wl,-z,stack-size=8388608";
4+
VARIATION="static";
5+
patches = attrs.patches or [] ++ [./patches/node-lto.patch];
6+
configureFlags = ["--enable-lto" "--fully-static"];
7+
});
8+
}

overlays/patches/node-lto.patch

Lines changed: 305 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,305 @@
1+
diff --git a/common.gypi b/common.gypi
2+
index a6a79adc..160b6eb6 100644
3+
--- a/common.gypi
4+
+++ b/common.gypi
5+
@@ -185,9 +185,9 @@
6+
'MSVC_runtimeType': 2 # MultiThreadedDLL (/MD)
7+
}],
8+
['clang==1', {
9+
- 'lto': ' -flto ', # Clang
10+
+ 'lto': ' -flto=thin ', # Clang
11+
}, {
12+
- 'lto': ' -flto=4 -fuse-linker-plugin -ffat-lto-objects ', # GCC
13+
+ 'lto': ' -flto=auto -fuse-linker-plugin -fno-fat-lto-objects ', # GCC
14+
}],
15+
],
16+
},
17+
diff --git a/deps/cares/configure b/deps/cares/configure
18+
index d02f117d..468461f7 100755
19+
--- a/deps/cares/configure
20+
+++ b/deps/cares/configure
21+
@@ -16139,11 +16139,6 @@ _LT_EOF
22+
23+
24+
_lt_libdeps_save_CFLAGS=$CFLAGS
25+
-case "$CC $CFLAGS " in #(
26+
-*\ -flto*\ *) CFLAGS="$CFLAGS -fno-lto" ;;
27+
-*\ -fwhopr*\ *) CFLAGS="$CFLAGS -fno-whopr" ;;
28+
-*\ -fuse-linker-plugin*\ *) CFLAGS="$CFLAGS -fno-use-linker-plugin" ;;
29+
-esac
30+
31+
if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
32+
(eval $ac_compile) 2>&5
33+
diff --git a/deps/cares/m4/libtool.m4 b/deps/cares/m4/libtool.m4
34+
index c4c02946..9f3d3662 100755
35+
--- a/deps/cares/m4/libtool.m4
36+
+++ b/deps/cares/m4/libtool.m4
37+
@@ -7537,11 +7537,6 @@ _LT_EOF
38+
])
39+
40+
_lt_libdeps_save_CFLAGS=$CFLAGS
41+
-case "$CC $CFLAGS " in #(
42+
-*\ -flto*\ *) CFLAGS="$CFLAGS -fno-lto" ;;
43+
-*\ -fwhopr*\ *) CFLAGS="$CFLAGS -fno-whopr" ;;
44+
-*\ -fuse-linker-plugin*\ *) CFLAGS="$CFLAGS -fno-use-linker-plugin" ;;
45+
-esac
46+
47+
dnl Parse the compiler output and extract the necessary
48+
dnl objects, libraries and library flags.
49+
diff --git a/deps/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py b/deps/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py
50+
index 5f2c097f..42dad126 100644
51+
--- a/deps/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py
52+
+++ b/deps/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py
53+
@@ -638,7 +638,7 @@ class XcodeSettings:
54+
# if the system clang isn't used, DYLD_LIBRARY_PATH needs to contain the
55+
# path to the libLTO.dylib that matches the used clang.
56+
if self._Test("LLVM_LTO", "YES", default="NO"):
57+
- cflags.append("-flto")
58+
+ cflags.append("-flto=thin")
59+
60+
self._AppendPlatformVersionMinFlags(cflags)
61+
62+
@@ -1101,7 +1101,7 @@ class XcodeSettings:
63+
# For static libraries, no dSYMs are created.
64+
result = []
65+
if (
66+
- self._Test("GCC_GENERATE_DEBUGGING_SYMBOLS", "YES", default="YES")
67+
+ self._Test("GCC_GENERATE_DEBUGGING_SYMBOLS", "YES", default="NO")
68+
and self._Test(
69+
"DEBUG_INFORMATION_FORMAT", "dwarf-with-dsym", default="dwarf"
70+
)
71+
diff --git a/deps/openssl/openssl-cli.gypi b/deps/openssl/openssl-cli.gypi
72+
index b4c278b4..79cafd6b 100644
73+
--- a/deps/openssl/openssl-cli.gypi
74+
+++ b/deps/openssl/openssl-cli.gypi
75+
@@ -23,7 +23,7 @@
76+
}],
77+
# Avoid excessive LTO
78+
['enable_lto=="true"', {
79+
- 'ldflags': [ '-fno-lto' ],
80+
+ 'ldflags': [],
81+
}],
82+
],
83+
}
84+
diff --git a/deps/openssl/openssl.gyp b/deps/openssl/openssl.gyp
85+
index ea3a2dc0..ea3780f7 100644
86+
--- a/deps/openssl/openssl.gyp
87+
+++ b/deps/openssl/openssl.gyp
88+
@@ -75,7 +75,7 @@
89+
}],
90+
# Avoid excessive LTO
91+
['enable_lto=="true"', {
92+
- 'ldflags': [ '-fno-lto' ],
93+
+ 'ldflags': [],
94+
}],
95+
]
96+
}, {
97+
diff --git a/node.gyp b/node.gyp
98+
index a3688b8e..d320299f 100644
99+
--- a/node.gyp
100+
+++ b/node.gyp
101+
@@ -1069,7 +1069,7 @@
102+
}],
103+
# Avoid excessive LTO
104+
['enable_lto=="true"', {
105+
- 'ldflags': [ '-fno-lto' ],
106+
+ 'ldflags': [],
107+
}],
108+
],
109+
}, # fuzz_env
110+
@@ -1112,7 +1112,7 @@
111+
}],
112+
# Avoid excessive LTO
113+
['enable_lto=="true"', {
114+
- 'ldflags': [ '-fno-lto' ],
115+
+ 'ldflags': [],
116+
}],
117+
],
118+
}, # fuzz_ClientHelloParser.cc
119+
@@ -1157,7 +1157,7 @@
120+
}],
121+
# Avoid excessive LTO
122+
['enable_lto=="true"', {
123+
- 'ldflags': [ '-fno-lto' ],
124+
+ 'ldflags': [],
125+
}],
126+
],
127+
}, # fuzz_strings
128+
@@ -1235,7 +1235,7 @@
129+
}],
130+
# Avoid excessive LTO
131+
['enable_lto=="true"', {
132+
- 'ldflags': [ '-fno-lto' ],
133+
+ 'ldflags': [],
134+
}],
135+
],
136+
}, # cctest
137+
@@ -1291,7 +1291,7 @@
138+
}],
139+
# Avoid excessive LTO
140+
['enable_lto=="true"', {
141+
- 'ldflags': [ '-fno-lto' ],
142+
+ 'ldflags': [],
143+
}],
144+
],
145+
}, # embedtest
146+
@@ -1333,7 +1333,7 @@
147+
}],
148+
# Avoid excessive LTO
149+
['enable_lto=="true"', {
150+
- 'ldflags': [ '-fno-lto' ],
151+
+ 'ldflags': [],
152+
}],
153+
]
154+
}, # overlapped-checker
155+
@@ -1439,7 +1439,7 @@
156+
}],
157+
# Avoid excessive LTO
158+
['enable_lto=="true"', {
159+
- 'ldflags': [ '-fno-lto' ],
160+
+ 'ldflags': [],
161+
}],
162+
],
163+
}, # node_mksnapshot
164+
diff --git a/tools/gyp/pylib/gyp/xcode_emulation.py b/tools/gyp/pylib/gyp/xcode_emulation.py
165+
index aee1a542..162881d1 100644
166+
--- a/tools/gyp/pylib/gyp/xcode_emulation.py
167+
+++ b/tools/gyp/pylib/gyp/xcode_emulation.py
168+
@@ -638,7 +638,7 @@ class XcodeSettings:
169+
# if the system clang isn't used, DYLD_LIBRARY_PATH needs to contain the
170+
# path to the libLTO.dylib that matches the used clang.
171+
if self._Test("LLVM_LTO", "YES", default="NO"):
172+
- cflags.append("-flto")
173+
+ cflags.append("-flto=thin")
174+
175+
self._AppendPlatformVersionMinFlags(cflags)
176+
177+
@@ -1101,7 +1101,7 @@ class XcodeSettings:
178+
# For static libraries, no dSYMs are created.
179+
result = []
180+
if (
181+
- self._Test("GCC_GENERATE_DEBUGGING_SYMBOLS", "YES", default="YES")
182+
+ self._Test("GCC_GENERATE_DEBUGGING_SYMBOLS", "YES", default="NO")
183+
and self._Test(
184+
"DEBUG_INFORMATION_FORMAT", "dwarf-with-dsym", default="dwarf"
185+
)
186+
diff --git a/tools/icu/icu-generic.gyp b/tools/icu/icu-generic.gyp
187+
index f007c652..ac69a873 100644
188+
--- a/tools/icu/icu-generic.gyp
189+
+++ b/tools/icu/icu-generic.gyp
190+
@@ -454,7 +454,7 @@
191+
'conditions': [
192+
# Avoid excessive LTO
193+
['enable_lto=="true"', {
194+
- 'ldflags': [ '-fno-lto' ],
195+
+ 'ldflags': [],
196+
}],
197+
],
198+
},
199+
@@ -471,7 +471,7 @@
200+
'conditions': [
201+
# Avoid excessive LTO
202+
['enable_lto=="true"', {
203+
- 'ldflags': [ '-fno-lto' ],
204+
+ 'ldflags': [],
205+
}],
206+
],
207+
},
208+
@@ -489,7 +489,7 @@
209+
'conditions': [
210+
# Avoid excessive LTO
211+
['enable_lto=="true"', {
212+
- 'ldflags': [ '-fno-lto' ],
213+
+ 'ldflags': [],
214+
}],
215+
],
216+
},
217+
@@ -506,7 +506,7 @@
218+
'conditions': [
219+
# Avoid excessive LTO
220+
['enable_lto=="true"', {
221+
- 'ldflags': [ '-fno-lto' ],
222+
+ 'ldflags': [],
223+
}],
224+
],
225+
},
226+
diff --git a/tools/v8_gypfiles/d8.gyp b/tools/v8_gypfiles/d8.gyp
227+
index 4dd98972..27165061 100644
228+
--- a/tools/v8_gypfiles/d8.gyp
229+
+++ b/tools/v8_gypfiles/d8.gyp
230+
@@ -65,7 +65,7 @@
231+
}],
232+
# Avoid excessive LTO
233+
['enable_lto=="true"', {
234+
- 'ldflags': [ '-fno-lto' ],
235+
+ 'ldflags': [],
236+
}],
237+
],
238+
},
239+
diff --git a/tools/v8_gypfiles/v8.gyp b/tools/v8_gypfiles/v8.gyp
240+
index 88c1297b..a640a7ff 100644
241+
--- a/tools/v8_gypfiles/v8.gyp
242+
+++ b/tools/v8_gypfiles/v8.gyp
243+
@@ -1690,7 +1690,7 @@
244+
}],
245+
# Avoid excessive LTO
246+
['enable_lto=="true"', {
247+
- 'ldflags': [ '-fno-lto' ],
248+
+ 'ldflags': [],
249+
}],
250+
],
251+
'defines!': [
252+
@@ -1752,7 +1752,7 @@
253+
}],
254+
# Avoid excessive LTO
255+
['enable_lto=="true"', {
256+
- 'ldflags': [ '-fno-lto' ],
257+
+ 'ldflags': [],
258+
}],
259+
],
260+
}, # mksnapshot
261+
@@ -1769,7 +1769,7 @@
262+
}],
263+
# Avoid excessive LTO
264+
['enable_lto=="true"', {
265+
- 'ldflags': [ '-fno-lto' ],
266+
+ 'ldflags': [],
267+
}],
268+
],
269+
'defines!': [
270+
@@ -1807,7 +1807,7 @@
271+
}],
272+
# Avoid excessive LTO
273+
['enable_lto=="true"', {
274+
- 'ldflags': [ '-fno-lto' ],
275+
+ 'ldflags': [],
276+
}],
277+
],
278+
'dependencies': [
279+
@@ -1843,7 +1843,7 @@
280+
}],
281+
# Avoid excessive LTO
282+
['enable_lto=="true"', {
283+
- 'ldflags': [ '-fno-lto' ],
284+
+ 'ldflags': [],
285+
}],
286+
],
287+
'sources': [
288+
@@ -1863,7 +1863,7 @@
289+
}],
290+
# Avoid excessive LTO
291+
['enable_lto=="true"', {
292+
- 'ldflags': [ '-fno-lto' ],
293+
+ 'ldflags': [],
294+
}],
295+
],
296+
'actions': [
297+
@@ -1931,7 +1931,7 @@
298+
],
299+
'conditions': [
300+
['enable_lto=="true"', {
301+
- 'cflags_cc': [ '-fno-lto' ],
302+
+ 'cflags_cc': [],
303+
}],
304+
# Changes in push_registers_asm.cc in V8 v12.8 requires using
305+
# push_registers_masm on Windows even with ClangCL on x64

0 commit comments

Comments
 (0)