build: allow LTO with Clang 3.9.1+
Bug: #38568 Test: manual, - arm64-apple-darwin20.5.0 / Apple clang version 12.0.5 (clang-1205.0.22.9) - x86_64-pc-linux-gnu / Ubuntu clang version 13.0.0-++20210520052624+48780527dd68-1~exp1~20210520153429.417 Signed-off-by: Jesse Chan <jc@linux.com> PR-URL: https://github.com/nodejs/node/pull/38751 Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
parent
9a7cbe25de
commit
ab71af3453
17
common.gypi
17
common.gypi
@ -164,17 +164,28 @@
|
|||||||
'v8_enable_handle_zapping': 0,
|
'v8_enable_handle_zapping': 0,
|
||||||
'pgo_generate': ' -fprofile-generate ',
|
'pgo_generate': ' -fprofile-generate ',
|
||||||
'pgo_use': ' -fprofile-use -fprofile-correction ',
|
'pgo_use': ' -fprofile-use -fprofile-correction ',
|
||||||
'lto': ' -flto=4 -fuse-linker-plugin -ffat-lto-objects ',
|
|
||||||
'conditions': [
|
'conditions': [
|
||||||
['node_shared != "true"', {
|
['node_shared != "true"', {
|
||||||
'MSVC_runtimeType': 0 # MultiThreaded (/MT)
|
'MSVC_runtimeType': 0 # MultiThreaded (/MT)
|
||||||
}, {
|
}, {
|
||||||
'MSVC_runtimeType': 2 # MultiThreadedDLL (/MD)
|
'MSVC_runtimeType': 2 # MultiThreadedDLL (/MD)
|
||||||
}],
|
}],
|
||||||
|
['llvm_version=="0.0"', {
|
||||||
|
'lto': ' -flto=4 -fuse-linker-plugin -ffat-lto-objects ', # GCC
|
||||||
|
}, {
|
||||||
|
'lto': ' -flto ', # Clang
|
||||||
|
}],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
'cflags': [ '-O3' ],
|
'cflags': [ '-O3' ],
|
||||||
'conditions': [
|
'conditions': [
|
||||||
|
['enable_lto=="true"', {
|
||||||
|
'cflags': ['<(lto)'],
|
||||||
|
'ldflags': ['<(lto)'],
|
||||||
|
'xcode_settings': {
|
||||||
|
'LLVM_LTO': 'YES',
|
||||||
|
},
|
||||||
|
}],
|
||||||
['OS=="linux"', {
|
['OS=="linux"', {
|
||||||
'conditions': [
|
'conditions': [
|
||||||
['node_section_ordering_info!=""', {
|
['node_section_ordering_info!=""', {
|
||||||
@ -206,10 +217,6 @@
|
|||||||
'cflags': ['<(pgo_use)'],
|
'cflags': ['<(pgo_use)'],
|
||||||
'ldflags': ['<(pgo_use)'],
|
'ldflags': ['<(pgo_use)'],
|
||||||
},],
|
},],
|
||||||
['enable_lto=="true"', {
|
|
||||||
'cflags': ['<(lto)'],
|
|
||||||
'ldflags': ['<(lto)'],
|
|
||||||
},],
|
|
||||||
],
|
],
|
||||||
},],
|
},],
|
||||||
['OS == "android"', {
|
['OS == "android"', {
|
||||||
|
35
configure.py
35
configure.py
@ -173,7 +173,7 @@ parser.add_argument("--enable-lto",
|
|||||||
dest="enable_lto",
|
dest="enable_lto",
|
||||||
default=None,
|
default=None,
|
||||||
help="Enable compiling with lto of a binary. This feature is only available "
|
help="Enable compiling with lto of a binary. This feature is only available "
|
||||||
"on linux with gcc and g++ 5.4.1 or newer.")
|
"with gcc 5.4.1+ or clang 3.9.1+.")
|
||||||
|
|
||||||
parser.add_argument("--link-module",
|
parser.add_argument("--link-module",
|
||||||
action="append",
|
action="append",
|
||||||
@ -952,6 +952,7 @@ def get_gas_version(cc):
|
|||||||
# quite prepared to go that far yet.
|
# quite prepared to go that far yet.
|
||||||
def check_compiler(o):
|
def check_compiler(o):
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
|
o['variables']['llvm_version'] = '0.0'
|
||||||
if not options.openssl_no_asm and options.dest_cpu in ('x86', 'x64'):
|
if not options.openssl_no_asm and options.dest_cpu in ('x86', 'x64'):
|
||||||
nasm_version = get_nasm_version('nasm')
|
nasm_version = get_nasm_version('nasm')
|
||||||
o['variables']['nasm_version'] = nasm_version
|
o['variables']['nasm_version'] = nasm_version
|
||||||
@ -1131,12 +1132,19 @@ def configure_mips(o, target_arch):
|
|||||||
host_byteorder = 'little' if target_arch in ('mipsel', 'mips64el') else 'big'
|
host_byteorder = 'little' if target_arch in ('mipsel', 'mips64el') else 'big'
|
||||||
o['variables']['v8_host_byteorder'] = host_byteorder
|
o['variables']['v8_host_byteorder'] = host_byteorder
|
||||||
|
|
||||||
|
def clang_version_ge(version_checked):
|
||||||
|
for compiler in [(CC, 'c'), (CXX, 'c++')]:
|
||||||
|
ok, is_clang, clang_version, gcc_version = \
|
||||||
|
try_check_compiler(compiler[0], compiler[1])
|
||||||
|
if is_clang and clang_version >= version_checked:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def gcc_version_ge(version_checked):
|
def gcc_version_ge(version_checked):
|
||||||
for compiler in [(CC, 'c'), (CXX, 'c++')]:
|
for compiler in [(CC, 'c'), (CXX, 'c++')]:
|
||||||
ok, is_clang, clang_version, compiler_version = \
|
ok, is_clang, clang_version, gcc_version = \
|
||||||
try_check_compiler(compiler[0], compiler[1])
|
try_check_compiler(compiler[0], compiler[1])
|
||||||
if is_clang or compiler_version < version_checked:
|
if is_clang or gcc_version < version_checked:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -1217,18 +1225,19 @@ def configure_node(o):
|
|||||||
o['variables']['enable_pgo_generate'] = b(options.enable_pgo_generate)
|
o['variables']['enable_pgo_generate'] = b(options.enable_pgo_generate)
|
||||||
o['variables']['enable_pgo_use'] = b(options.enable_pgo_use)
|
o['variables']['enable_pgo_use'] = b(options.enable_pgo_use)
|
||||||
|
|
||||||
if flavor != 'linux' and (options.enable_lto):
|
if flavor == 'win' and (options.enable_lto):
|
||||||
raise Exception(
|
raise Exception(
|
||||||
'The lto option is supported only on linux.')
|
'Use Link Time Code Generation instead.')
|
||||||
|
|
||||||
if flavor == 'linux':
|
if options.enable_lto:
|
||||||
if options.enable_lto:
|
gcc_version_checked = (5, 4, 1)
|
||||||
version_checked = (5, 4, 1)
|
clang_version_checked = (3, 9, 1)
|
||||||
if not gcc_version_ge(version_checked):
|
if not gcc_version_ge(gcc_version_checked) and not clang_version_ge(clang_version_checked):
|
||||||
version_checked_str = ".".join(map(str, version_checked))
|
gcc_version_checked_str = ".".join(map(str, gcc_version_checked))
|
||||||
raise Exception(
|
clang_version_checked_str = ".".join(map(str, clang_version_checked))
|
||||||
'The option --enable-lto is supported for gcc and gxx %s'
|
raise Exception(
|
||||||
' or newer only.' % (version_checked_str))
|
'The option --enable-lto is supported for gcc %s+'
|
||||||
|
'or clang %s+ only.' % (gcc_version_checked_str, clang_version_checked_str))
|
||||||
|
|
||||||
o['variables']['enable_lto'] = b(options.enable_lto)
|
o['variables']['enable_lto'] = b(options.enable_lto)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user