Skip to content

Commit eb0a832

Browse files
LeszekSwirskitargos
andcommitted
build: disable ICF for mksnapshot
Refs: https://chromium-review.googlesource.com/c/v8/v8/+/5447267 Co-authored-by: Michaël Zasso <[email protected]>
1 parent 9068503 commit eb0a832

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

node.gyp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,12 @@
13691369
'tools/snapshot/node_mksnapshot.cc',
13701370
],
13711371

1372+
'msvs_settings': {
1373+
'VCLinkerTool': {
1374+
'EnableCOMDATFolding': '1', # /OPT:NOICF
1375+
},
1376+
},
1377+
13721378
'conditions': [
13731379
['node_write_snapshot_as_array_literals=="true"', {
13741380
'defines': [ 'NODE_MKSNAPSHOT_USE_ARRAY_LITERALS=1' ],

tools/v8_gypfiles/v8.gyp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,6 +1710,24 @@
17101710
'sources': [
17111711
'<!@pymod_do_main(GN-scraper "<(V8_ROOT)/BUILD.gn" "\\"mksnapshot.*?sources = ")',
17121712
],
1713+
'configurations': {
1714+
# We have to repeat the settings for each configuration because toochain.gypi
1715+
# defines the default EnableCOMDATFolding value in the configurations dicts.
1716+
'Debug': {
1717+
'msvs_settings': {
1718+
'VCLinkerTool': {
1719+
'EnableCOMDATFolding': '1', # /OPT:NOICF
1720+
},
1721+
},
1722+
},
1723+
'Release': {
1724+
'msvs_settings': {
1725+
'VCLinkerTool': {
1726+
'EnableCOMDATFolding': '1', # /OPT:NOICF
1727+
},
1728+
},
1729+
},
1730+
},
17131731
'conditions': [
17141732
['want_separate_host_toolset', {
17151733
'toolsets': ['host'],

unofficial.gni

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,30 @@ template("node_gn_build") {
234234
if (node_use_node_snapshot) {
235235
if (current_toolchain == v8_snapshot_toolchain) {
236236
executable("node_mksnapshot") {
237-
configs += [ ":node_internal_config" ]
237+
configs += [ ":node_internal_config", ":disable_icf" ]
238238
sources = [
239239
"src/node_snapshot_stub.cc",
240240
"tools/snapshot/node_mksnapshot.cc",
241241
]
242242
deps = [ ":libnode" ]
243243
}
244+
245+
# This config disables a link time optimization "ICF", which may merge
246+
# different functions into one if the function signature and body of them are
247+
# identical.
248+
#
249+
# ICF breaks 1:1 mappings of the external references for V8 snapshot, so we
250+
# disable it while taking a V8 snapshot.
251+
config("disable_icf") {
252+
visibility = [ ":*" ] # Only targets in this file can depend on this.
253+
if (is_win) {
254+
ldflags = [ "/OPT:NOICF" ] # link.exe, but also lld-link.exe.
255+
} else if (is_apple && !use_lld) {
256+
ldflags = [ "-Wl,-no_deduplicate" ] # ld64.
257+
} else if (use_gold || use_lld) {
258+
ldflags = [ "-Wl,--icf=none" ]
259+
}
260+
}
244261
}
245262

246263
action("run_node_mksnapshot") {

0 commit comments

Comments
 (0)