Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lto: enabling lto at configure #21677

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,17 @@
['OS!="mac" and OS!="win"', {
'cflags': [ '-fno-omit-frame-pointer' ],
}],
['OS=="linux"', {
'variables': {
'lto': ' -flto=4 -fuse-linker-plugin -ffat-lto-objects ',
},
'conditions': [
['enable_lto=="true"', {
'cflags': ['<(lto)'],
'ldflags': ['<(lto)'],
},],
],
},],
['OS == "android"', {
'cflags': [ '-fPIE' ],
'ldflags': [ '-fPIE', '-pie' ]
Expand Down
22 changes: 22 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ parser.add_option("--enable-vtune-profiling",
"JavaScript code executed in nodejs. This feature is only available "
"for x32, x86, and x64 architectures.")

parser.add_option("--enable-lto",
action="store_true",
dest="enable_lto",
help="Enable compiling with lto of a binary. This feature is only available "
"on linux with gcc and g++.")

parser.add_option("--link-module",
action="append",
Expand Down Expand Up @@ -932,6 +937,23 @@ def configure_node(o):
else:
o['variables']['node_enable_v8_vtunejit'] = 'false'

if flavor != 'linux' and (options.enable_lto):
raise Exception(
'The lto option is supported only on linux.')

if flavor == 'linux':
if options.enable_lto:
version_checked = '5.4.1'
for compiler in [(CC, 'c'), (CXX, 'c++')]:
ok, is_clang, clang_version, compiler_version = \
try_check_compiler(compiler[0], compiler[1])
if is_clang or compiler_version < version_checked:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String-based version range checking like this is not foolproof, for example: '10.0.0' < '5.4.1' will evaluate to True. At the very least we would need a version comparison function that simply splits on '.' and compares each integer value between two version strings.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or do a tuple comparison, e.g.,

node/configure

Line 727 in 0a78f7d

elif clang_version < (3, 4, 2) if is_clang else gcc_version < (4, 9, 4):

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello

Thank you for the comment. I will implement this asap.

@octaviansoldea

raise Exception(
'The option --enable-lto is supported for '
'gcc and gxx 5.4.1 or newer only.')

o['variables']['enable_lto'] = b(options.enable_lto)

if flavor in ('solaris', 'mac', 'linux', 'freebsd'):
use_dtrace = not options.without_dtrace
# Don't enable by default on linux and freebsd
Expand Down