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@gentoo.org>
This commit is contained in:
Marek Szuba
2021-04-22 15:47:11 +02:00
parent 3e9b50beee
commit 5b43e0081f
3 changed files with 50 additions and 2 deletions

View File

@@ -0,0 +1,39 @@
From ea694e2b138d2f991989e09fc0e964fec3587b5f Mon Sep 17 00:00:00 2001
From: Jesse Chan <jc@linux.com>
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 <jc@linux.com>
---
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"', {

View File

@@ -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>

View File

@@ -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