commit:     5b43e0081fcb5059fc9e68a0aa7d2993a8805643
Author:     Marek Szuba <marecki <AT> gentoo <DOT> org>
AuthorDate: Thu Apr 22 13:47:11 2021 +0000
Commit:     Marek Szuba <marecki <AT> gentoo <DOT> org>
CommitDate: Thu Apr 22 15:27:12 2021 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=5b43e008

net-libs/nodejs-16.0.0: implement IUSE=lto

Note that the upstream patch which for the time being is required to
make LTO work only has an effect if the aforementioned USE flag is set.

Closes: https://bugs.gentoo.org/784995
Signed-off-by: Marek Szuba <marecki <AT> gentoo.org>

 net-libs/nodejs/files/nodejs-16.0.0-v8_lto.patch   | 39 ++++++++++++++++++++++
 net-libs/nodejs/metadata.xml                       |  1 +
 ...odejs-16.0.0.ebuild => nodejs-16.0.0-r1.ebuild} | 12 +++++--
 3 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/net-libs/nodejs/files/nodejs-16.0.0-v8_lto.patch 
b/net-libs/nodejs/files/nodejs-16.0.0-v8_lto.patch
new file mode 100644
index 00000000000..a3e4acb02c3
--- /dev/null
+++ b/net-libs/nodejs/files/nodejs-16.0.0-v8_lto.patch
@@ -0,0 +1,39 @@
+From ea694e2b138d2f991989e09fc0e964fec3587b5f Mon Sep 17 00:00:00 2001
+From: Jesse Chan <[email protected]>
+Date: Thu, 22 Apr 2021 19:41:09 +0800
+Subject: [PATCH] tools: disable LTO for "v8_cppgc_shared" target
+
+"PushAllRegistersAndIterateStack" is implemented in assembly and
+called from "stack.cc" via 'extern "C"'. [1]
+
+However, LTO does not work well with symbol usage from assembly. [2]
+
+This change workarounds the issue by disabling LTO for the target.
+
+With GCC 10 and "./configure --enable-lto", compilation succeeds
+after this change.
+
+[1] v8/v8@c10863153
+[2] 
https://gcc.gnu.org/wiki/LinkTimeOptimizationFAQ#Symbol_usage_from_assembly_language
+
+Refs: #35957
+Refs: #38335
+Signed-off-by: Jesse Chan <[email protected]>
+---
+ tools/v8_gypfiles/v8.gyp | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/tools/v8_gypfiles/v8.gyp b/tools/v8_gypfiles/v8.gyp
+index ccb5984f47d..377e12d1fdc 100644
+--- a/tools/v8_gypfiles/v8.gyp
++++ b/tools/v8_gypfiles/v8.gyp
+@@ -1378,6 +1378,9 @@
+           '<(V8_ROOT)/src/heap/base/worklist.h',
+         ],
+         'conditions': [
++          ['enable_lto=="true"', {
++            'cflags_cc': [ '-fno-lto' ],
++          }],
+           ['clang or OS!="win"', {
+             'conditions': [
+               ['_toolset == "host" and host_arch == "x64" or _toolset == 
"target" and target_arch=="x64"', {

diff --git a/net-libs/nodejs/metadata.xml b/net-libs/nodejs/metadata.xml
index db1b9aefa8e..15befbfa251 100644
--- a/net-libs/nodejs/metadata.xml
+++ b/net-libs/nodejs/metadata.xml
@@ -12,6 +12,7 @@
        </maintainer>
        <use>
                <flag name="inspector">Enable V8 inspector</flag>
+               <flag name="lto">Build with link-time optimisation</flag>
                <flag name="npm">Enable NPM package manager</flag>
                <flag name="pax_kernel">Enable building under a PaX enabled 
kernel</flag>
                <flag name="snapshot">Enable snapshot creation for faster 
startup</flag>

diff --git a/net-libs/nodejs/nodejs-16.0.0.ebuild 
b/net-libs/nodejs/nodejs-16.0.0-r1.ebuild
similarity index 93%
rename from net-libs/nodejs/nodejs-16.0.0.ebuild
rename to net-libs/nodejs/nodejs-16.0.0-r1.ebuild
index 3b317ab08c9..612a576994a 100644
--- a/net-libs/nodejs/nodejs-16.0.0.ebuild
+++ b/net-libs/nodejs/nodejs-16.0.0-r1.ebuild
@@ -6,7 +6,7 @@ EAPI=7
 PYTHON_COMPAT=( python3_{7..9} )
 PYTHON_REQ_USE="threads(+)"
 
-inherit bash-completion-r1 flag-o-matic pax-utils python-any-r1 
toolchain-funcs xdg-utils
+inherit bash-completion-r1 pax-utils python-any-r1 toolchain-funcs xdg-utils
 
 DESCRIPTION="A JavaScript runtime built on Chrome's V8 JavaScript engine"
 HOMEPAGE="https://nodejs.org/";
@@ -16,7 +16,7 @@ LICENSE="Apache-1.1 Apache-2.0 BSD BSD-2 MIT"
 SLOT="0/$(ver_cut 1)"
 KEYWORDS="~amd64 ~arm ~arm64 ~ppc64 ~x86 ~amd64-linux ~x64-macos"
 
-IUSE="cpu_flags_x86_sse2 debug doc +icu inspector +npm pax_kernel +snapshot 
+ssl system-icu +system-ssl systemtap test"
+IUSE="cpu_flags_x86_sse2 debug doc +icu inspector lto +npm pax_kernel 
+snapshot +ssl system-icu +system-ssl systemtap test"
 REQUIRED_USE="inspector? ( icu ssl )
        npm? ( ssl )
        system-icu? ( icu )
@@ -42,6 +42,7 @@ DEPEND="${RDEPEND}"
 
 PATCHES=(
        "${FILESDIR}"/${PN}-15.2.0-global-npm-config.patch
+       "${FILESDIR}"/${PN}-16.0.0-v8_lto.patch
 )
 
 S="${WORKDIR}/node-v${PV}"
@@ -49,6 +50,12 @@ S="${WORKDIR}/node-v${PV}"
 pkg_pretend() {
        (use x86 && ! use cpu_flags_x86_sse2) && \
                die "Your CPU doesn't support the required SSE2 instruction."
+
+       if [[ ${MERGE_TYPE} != "binary" ]]; then
+               if use lto; then
+                       tc-is-gcc || die "${PN} only supports LTO for gcc"
+               fi
+       fi
 }
 
 src_prepare() {
@@ -103,6 +110,7 @@ src_configure() {
                --shared-zlib
        )
        use debug && myconf+=( --debug )
+       use lto && myconf+=( --enable-lto )
        if use system-icu; then
                myconf+=( --with-intl=system-icu )
        elif use icu; then

Reply via email to