From adec83dd181fade1d2d889a5dc965d9a1df9fa5c Mon Sep 17 00:00:00 2001 From: Leszek Swirski Date: Mon, 15 Apr 2024 09:46:53 +0200 Subject: [PATCH] Disable ICF for node_mksnapshot (#176) --- unofficial.gni | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/unofficial.gni b/unofficial.gni index 721144093222a1..6f0ac4a523e18d 100644 --- a/unofficial.gni +++ b/unofficial.gni @@ -234,13 +234,30 @@ template("node_gn_build") { if (node_use_node_snapshot) { if (current_toolchain == v8_snapshot_toolchain) { executable("node_mksnapshot") { - configs += [ ":node_internal_config" ] + configs += [ ":node_internal_config", ":disable_icf" ] sources = [ "src/node_snapshot_stub.cc", "tools/snapshot/node_mksnapshot.cc", ] deps = [ ":libnode" ] } + + # This config disables a link time optimization "ICF", which may merge + # different functions into one if the function signature and body of them are + # identical. + # + # ICF breaks 1:1 mappings of the external references for V8 snapshot, so we + # disable it while taking a V8 snapshot. + config("disable_icf") { + visibility = [ ":*" ] # Only targets in this file can depend on this. + if (is_win) { + ldflags = [ "/OPT:NOICF" ] # link.exe, but also lld-link.exe. + } else if (is_apple && !use_lld) { + ldflags = [ "-Wl,-no_deduplicate" ] # ld64. + } else if (use_gold || use_lld) { + ldflags = [ "-Wl,--icf=none" ] + } + } } action("run_node_mksnapshot") {