Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 80c32b7

Browse filesBrowse files
jesecdanielleadams
authored andcommitted
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: #38751 Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 30c0020 commit 80c32b7
Copy full SHA for 80c32b7

File tree

Expand file treeCollapse file tree

2 files changed

+35
-19
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+35
-19
lines changed
Open diff view settings
Collapse file

‎common.gypi‎

Copy file name to clipboardExpand all lines: common.gypi
+12-5Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,28 @@
164164
'v8_enable_handle_zapping': 0,
165165
'pgo_generate': ' -fprofile-generate ',
166166
'pgo_use': ' -fprofile-use -fprofile-correction ',
167-
'lto': ' -flto=4 -fuse-linker-plugin -ffat-lto-objects ',
168167
'conditions': [
169168
['node_shared != "true"', {
170169
'MSVC_runtimeType': 0 # MultiThreaded (/MT)
171170
}, {
172171
'MSVC_runtimeType': 2 # MultiThreadedDLL (/MD)
173172
}],
173+
['llvm_version=="0.0"', {
174+
'lto': ' -flto=4 -fuse-linker-plugin -ffat-lto-objects ', # GCC
175+
}, {
176+
'lto': ' -flto ', # Clang
177+
}],
174178
],
175179
},
176180
'cflags': [ '-O3' ],
177181
'conditions': [
182+
['enable_lto=="true"', {
183+
'cflags': ['<(lto)'],
184+
'ldflags': ['<(lto)'],
185+
'xcode_settings': {
186+
'LLVM_LTO': 'YES',
187+
},
188+
}],
178189
['OS=="linux"', {
179190
'conditions': [
180191
['node_section_ordering_info!=""', {
@@ -206,10 +217,6 @@
206217
'cflags': ['<(pgo_use)'],
207218
'ldflags': ['<(pgo_use)'],
208219
},],
209-
['enable_lto=="true"', {
210-
'cflags': ['<(lto)'],
211-
'ldflags': ['<(lto)'],
212-
},],
213220
],
214221
},],
215222
['OS == "android"', {
Collapse file

‎configure.py‎

Copy file name to clipboardExpand all lines: configure.py
+23-14Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@
173173
dest="enable_lto",
174174
default=None,
175175
help="Enable compiling with lto of a binary. This feature is only available "
176-
"on linux with gcc and g++ 5.4.1 or newer.")
176+
"with gcc 5.4.1+ or clang 3.9.1+.")
177177

178178
parser.add_argument("--link-module",
179179
action="append",
@@ -952,6 +952,7 @@ def get_gas_version(cc):
952952
# quite prepared to go that far yet.
953953
def check_compiler(o):
954954
if sys.platform == 'win32':
955+
o['variables']['llvm_version'] = '0.0'
955956
if not options.openssl_no_asm and options.dest_cpu in ('x86', 'x64'):
956957
nasm_version = get_nasm_version('nasm')
957958
o['variables']['nasm_version'] = nasm_version
@@ -1131,12 +1132,19 @@ def configure_mips(o, target_arch):
11311132
host_byteorder = 'little' if target_arch in ('mipsel', 'mips64el') else 'big'
11321133
o['variables']['v8_host_byteorder'] = host_byteorder
11331134

1135+
def clang_version_ge(version_checked):
1136+
for compiler in [(CC, 'c'), (CXX, 'c++')]:
1137+
ok, is_clang, clang_version, gcc_version = \
1138+
try_check_compiler(compiler[0], compiler[1])
1139+
if is_clang and clang_version >= version_checked:
1140+
return True
1141+
return False
11341142

11351143
def gcc_version_ge(version_checked):
11361144
for compiler in [(CC, 'c'), (CXX, 'c++')]:
1137-
ok, is_clang, clang_version, compiler_version = \
1145+
ok, is_clang, clang_version, gcc_version = \
11381146
try_check_compiler(compiler[0], compiler[1])
1139-
if is_clang or compiler_version < version_checked:
1147+
if is_clang or gcc_version < version_checked:
11401148
return False
11411149
return True
11421150

@@ -1217,18 +1225,19 @@ def configure_node(o):
12171225
o['variables']['enable_pgo_generate'] = b(options.enable_pgo_generate)
12181226
o['variables']['enable_pgo_use'] = b(options.enable_pgo_use)
12191227

1220-
if flavor != 'linux' and (options.enable_lto):
1228+
if flavor == 'win' and (options.enable_lto):
12211229
raise Exception(
1222-
'The lto option is supported only on linux.')
1223-
1224-
if flavor == 'linux':
1225-
if options.enable_lto:
1226-
version_checked = (5, 4, 1)
1227-
if not gcc_version_ge(version_checked):
1228-
version_checked_str = ".".join(map(str, version_checked))
1229-
raise Exception(
1230-
'The option --enable-lto is supported for gcc and gxx %s'
1231-
' or newer only.' % (version_checked_str))
1230+
'Use Link Time Code Generation instead.')
1231+
1232+
if options.enable_lto:
1233+
gcc_version_checked = (5, 4, 1)
1234+
clang_version_checked = (3, 9, 1)
1235+
if not gcc_version_ge(gcc_version_checked) and not clang_version_ge(clang_version_checked):
1236+
gcc_version_checked_str = ".".join(map(str, gcc_version_checked))
1237+
clang_version_checked_str = ".".join(map(str, clang_version_checked))
1238+
raise Exception(
1239+
'The option --enable-lto is supported for gcc %s+'
1240+
'or clang %s+ only.' % (gcc_version_checked_str, clang_version_checked_str))
12321241

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.