Skip to content

Commit f553d5d

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 <targos@protonmail.com>
1 parent 8d34ef7 commit f553d5d

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
@@ -1376,6 +1376,12 @@
13761376
'tools/snapshot/node_mksnapshot.cc',
13771377
],
13781378

1379+
'msvs_settings': {
1380+
'VCLinkerTool': {
1381+
'EnableCOMDATFolding': '1', # /OPT:NOICF
1382+
},
1383+
},
1384+
13791385
'conditions': [
13801386
['node_write_snapshot_as_array_literals=="true"', {
13811387
'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
@@ -1708,6 +1708,24 @@
17081708
'sources': [
17091709
'<!@pymod_do_main(GN-scraper "<(V8_ROOT)/BUILD.gn" "\\"mksnapshot.*?sources = ")',
17101710
],
1711+
'configurations': {
1712+
# We have to repeat the settings for each configuration because toochain.gypi
1713+
# defines the default EnableCOMDATFolding value in the configurations dicts.
1714+
'Debug': {
1715+
'msvs_settings': {
1716+
'VCLinkerTool': {
1717+
'EnableCOMDATFolding': '1', # /OPT:NOICF
1718+
},
1719+
},
1720+
},
1721+
'Release': {
1722+
'msvs_settings': {
1723+
'VCLinkerTool': {
1724+
'EnableCOMDATFolding': '1', # /OPT:NOICF
1725+
},
1726+
},
1727+
},
1728+
},
17111729
'conditions': [
17121730
['want_separate_host_toolset', {
17131731
'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)