Skip to content

Commit c094151

Browse files
committed
compilers: pass target to get_lto_*_args
Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 054fd1e commit c094151

File tree

6 files changed

+32
-24
lines changed

6 files changed

+32
-24
lines changed

mesonbuild/compilers/compilers.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ def get_base_compile_args(target: 'BuildTarget', compiler: 'Compiler', env: 'Env
279279
num_threads = get_option_value_for_target(env, target, OptionKey('b_lto_threads'), 0)
280280
ltomode = get_option_value_for_target(env, target, OptionKey('b_lto_mode'), 'default')
281281
args.extend(compiler.get_lto_compile_args(
282+
target=target,
282283
threads=num_threads,
283284
mode=ltomode))
284285
lto = True
@@ -357,6 +358,7 @@ def get_base_link_args(target: 'BuildTarget',
357358
num_threads = get_option_value_for_target(env, target, OptionKey('b_lto_threads'), 0)
358359
lto_mode = get_option_value_for_target(env, target, OptionKey('b_lto_mode'), 'default')
359360
args.extend(linker.get_lto_link_args(
361+
target=target,
360362
threads=num_threads,
361363
mode=lto_mode,
362364
thinlto_cache_dir=thinlto_cache_dir))
@@ -1043,11 +1045,12 @@ def remove_linkerlike_args(self, args: T.List[str]) -> T.List[str]:
10431045
def get_embed_bitcode_args(self, bitcode: bool, lto: bool) -> T.List[str]:
10441046
return []
10451047

1046-
def get_lto_compile_args(self, *, threads: int = 0, mode: str = 'default') -> T.List[str]:
1048+
def get_lto_compile_args(self, *, target: T.Optional[BuildTarget] = None, threads: int = 0,
1049+
mode: str = 'default') -> T.List[str]:
10471050
return []
10481051

1049-
def get_lto_link_args(self, *, threads: int = 0, mode: str = 'default',
1050-
thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
1052+
def get_lto_link_args(self, *, target: T.Optional[BuildTarget] = None, threads: int = 0,
1053+
mode: str = 'default', thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
10511054
return self.linker.get_lto_args()
10521055

10531056
def get_lto_obj_cache_path(self, path: str) -> T.List[str]:

mesonbuild/compilers/mixins/clang.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
if T.TYPE_CHECKING:
2121
from ...options import MutableKeyedOptionDictType
2222
from ...dependencies import Dependency # noqa: F401
23+
from ...build import BuildTarget
2324
from ..compilers import Compiler
2425

2526
CompilerMixinBase = Compiler
@@ -211,7 +212,8 @@ def get_coverage_link_args(self) -> T.List[str]:
211212
def get_embed_bitcode_args(self, bitcode: bool, lto: bool) -> T.List[str]:
212213
return ['-fembed-bitcode'] if bitcode else []
213214

214-
def get_lto_compile_args(self, *, threads: int = 0, mode: str = 'default') -> T.List[str]:
215+
def get_lto_compile_args(self, *, target: T.Optional[BuildTarget] = None, threads: int = 0,
216+
mode: str = 'default') -> T.List[str]:
215217
args: T.List[str] = []
216218
if mode == 'thin':
217219
# ThinLTO requires the use of gold, lld, ld64, lld-link or mold 1.1+
@@ -224,7 +226,7 @@ def get_lto_compile_args(self, *, threads: int = 0, mode: str = 'default') -> T.
224226
args.append(f'-flto={mode}')
225227
else:
226228
assert mode == 'default', 'someone forgot to wire something up'
227-
args.extend(super().get_lto_compile_args(threads=threads))
229+
args.extend(super().get_lto_compile_args(target=target, threads=threads))
228230
return args
229231

230232
def linker_to_compiler_args(self, args: T.List[str]) -> T.List[str]:
@@ -233,9 +235,9 @@ def linker_to_compiler_args(self, args: T.List[str]) -> T.List[str]:
233235
else:
234236
return args
235237

236-
def get_lto_link_args(self, *, threads: int = 0, mode: str = 'default',
237-
thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
238-
args = self.get_lto_compile_args(threads=threads, mode=mode)
238+
def get_lto_link_args(self, *, target: T.Optional[BuildTarget] = None, threads: int = 0,
239+
mode: str = 'default', thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
240+
args = self.get_lto_compile_args(target=target, threads=threads, mode=mode)
239241
if mode == 'thin' and thinlto_cache_dir is not None:
240242
# We check for ThinLTO linker support above in get_lto_compile_args, and all of them support
241243
# get_thinlto_cache_args as well

mesonbuild/compilers/mixins/gnu.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,8 @@ def get_compiler_dirs(self, name: str) -> T.List[str]:
481481
return self._split_fetch_real_dirs(line.split('=', 1)[1])
482482
return []
483483

484-
def get_lto_compile_args(self, *, threads: int = 0, mode: str = 'default') -> T.List[str]:
484+
def get_lto_compile_args(self, *, target: T.Optional[BuildTarget] = None, threads: int = 0,
485+
mode: str = 'default') -> T.List[str]:
485486
# This provides a base for many compilers, GCC and Clang override this
486487
# for their specific arguments
487488
return ['-flto']
@@ -612,8 +613,8 @@ def get_has_func_attribute_extra_args(self, name: str) -> T.List[str]:
612613
def get_prelink_args(self, prelink_name: str, obj_list: T.List[str]) -> T.Tuple[T.List[str], T.List[str]]:
613614
return [prelink_name], ['-r', '-o', prelink_name] + obj_list
614615

615-
def get_lto_compile_args(self, *, threads: int = 0, mode: str = 'default',
616-
thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
616+
def get_lto_compile_args(self, *, target: T.Optional[BuildTarget] = None, threads: int = 0,
617+
mode: str = 'default', thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
617618
args: T.List[str] = []
618619

619620
if threads == 0:
@@ -626,7 +627,7 @@ def get_lto_compile_args(self, *, threads: int = 0, mode: str = 'default',
626627
elif threads > 0:
627628
args.append(f'-flto={threads}')
628629
else:
629-
args.extend(super().get_lto_compile_args(threads=threads))
630+
args.extend(super().get_lto_compile_args(target=target, threads=threads))
630631

631632
if thinlto_cache_dir is not None:
632633
# We check for ThinLTO linker support above in get_lto_compile_args, and all of them support
@@ -646,10 +647,10 @@ def use_linker_args(cls, linker: str, version: str) -> T.List[str]:
646647
return ['-fuse-ld=mold']
647648
return super().use_linker_args(linker, version)
648649

649-
def get_lto_link_args(self, *, threads: int = 0, mode: str = 'default',
650-
thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
650+
def get_lto_link_args(self, *, target: T.Optional[BuildTarget] = None, threads: int = 0,
651+
mode: str = 'default', thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
651652
args: T.List[str] = []
652-
args.extend(self.get_lto_compile_args(threads=threads, thinlto_cache_dir=thinlto_cache_dir))
653+
args.extend(self.get_lto_compile_args(target=target, threads=threads, thinlto_cache_dir=thinlto_cache_dir))
653654
return args
654655

655656
def get_profile_use_args(self) -> T.List[str]:

mesonbuild/compilers/mixins/islinker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ class BasicLinkerIsCompilerMixin(Compiler):
4040
def sanitizer_link_args(self, target: BuildTarget, value: T.List[str]) -> T.List[str]:
4141
return []
4242

43-
def get_lto_link_args(self, *, threads: int = 0, mode: str = 'default',
44-
thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
43+
def get_lto_link_args(self, *, target: T.Optional[BuildTarget] = None, threads: int = 0,
44+
mode: str = 'default', thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
4545
return []
4646

4747
def can_linker_accept_rsp(self) -> bool:

mesonbuild/compilers/mixins/visualstudio.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,8 @@ def openmp_link_flags(self) -> T.List[str]:
492492
raise mesonlib.MesonBugException('Could not find libomp')
493493
return super().openmp_link_flags() + libs
494494

495-
def get_lto_compile_args(self, *, threads: int = 0, mode: str = 'default') -> T.List[str]:
495+
def get_lto_compile_args(self, *, target: T.Optional[BuildTarget] = None, threads: int = 0,
496+
mode: str = 'default') -> T.List[str]:
496497
args: T.List[str] = []
497498
if mode == 'thin':
498499
# LTO data generated by clang-cl is only usable by lld-link
@@ -501,11 +502,11 @@ def get_lto_compile_args(self, *, threads: int = 0, mode: str = 'default') -> T.
501502
args.append(f'-flto={mode}')
502503
else:
503504
assert mode == 'default', 'someone forgot to wire something up'
504-
args.extend(super().get_lto_compile_args(threads=threads))
505+
args.extend(super().get_lto_compile_args(target=target, threads=threads))
505506
return args
506507

507-
def get_lto_link_args(self, *, threads: int = 0, mode: str = 'default',
508-
thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
508+
def get_lto_link_args(self, *, target: T.Optional[BuildTarget] = None, threads: int = 0,
509+
mode: str = 'default', thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
509510
args = []
510511
if mode == 'thin' and thinlto_cache_dir is not None:
511512
args.extend(self.linker.get_thinlto_cache_args(thinlto_cache_dir))

mesonbuild/compilers/rust.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,13 +365,14 @@ def get_embed_bitcode_args(self, bitcode: bool, lto: bool) -> T.List[str]:
365365
else:
366366
return ['-C', 'embed-bitcode=no']
367367

368-
def get_lto_compile_args(self, *, threads: int = 0, mode: str = 'default') -> T.List[str]:
368+
def get_lto_compile_args(self, *, target: T.Optional[BuildTarget] = None, threads: int = 0,
369+
mode: str = 'default') -> T.List[str]:
369370
# TODO: what about -Clinker-plugin-lto?
370371
rustc_lto = 'lto=thin' if mode == 'thin' else 'lto'
371372
return ['-C', rustc_lto]
372373

373-
def get_lto_link_args(self, *, threads: int = 0, mode: str = 'default',
374-
thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
374+
def get_lto_link_args(self, *, target: T.Optional[BuildTarget] = None, threads: int = 0,
375+
mode: str = 'default', thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
375376
# no need to specify anything because the rustc command line
376377
# includes the result of get_lto_compile_args()
377378
return []

0 commit comments

Comments
 (0)