Debian Codegraph @

mesonbuild/linkers/linkers.py

raw
1 # SPDX-License-Identifier: Apache-2.0
2 # Copyright 2012-2022 The Meson development team
3 # Copyright © 2023-2025 Intel Corporation
4
5 from __future__ import annotations
6
7 import abc
8 import os
9 import typing as T
10 import re
11
12 from .base import ArLikeLinker, RSPFileSyntax
13 from .. import mesonlib
14 from ..mesonlib import EnvironmentException, MesonException, path_has_root
15 from ..arglist import CompilerArgs
16
17 if T.TYPE_CHECKING:
18 from ..environment import Environment
19 from ..mesonlib import MachineChoice
20 from ..build import BuildTarget
21 from ..compilers.compilers import LinkerOptionStyle
22
23
24 class StaticLinker:
25
26 id: str
27
28 def __init__(self, exelist: T.List[str], env: Environment):
29 self.exelist = exelist
30 self.environment = env
31
32 def get_id(self) -> str:
33 return self.id
34
35 def get_exe(self) -> str:
36 return self.exelist[0]
37
38 def compiler_args(self, args: T.Optional[T.Iterable[str]] = None) -> CompilerArgs:
39 return CompilerArgs(self, args)
40
41 def can_linker_accept_rsp(self) -> bool:
42 """
43 Determines whether the linker can accept arguments using the @rsp syntax.
44 """
45 return mesonlib.is_windows()
46
47 def get_base_link_args(self,
48 target: 'BuildTarget',
49 linker: StaticLinker,
50 env: 'Environment') -> T.List[str]:
51 """Like compilers.get_base_link_args, but for the static linker."""
52 return []
53
54 def get_exelist(self) -> T.List[str]:
55 return self.exelist.copy()
56
57 def get_archive_name(self, filename: str) -> str:
58 # Only used for shared libraries on AIX, so return empty.
59 return str()
60
61 def get_std_link_args(self, env: 'Environment', is_thin: bool) -> T.List[str]:
62 return []
63
64 def get_optimization_link_args(self, optimization_level: str) -> T.List[str]:
65 return []
66
67 def get_output_args(self, target: str) -> T.List[str]:
68 return []
69
70 def get_no_stdlib_link_args(self) -> T.List[str]:
71 """Arguments to turn off default linking to standard libraries."""
72 return []
73
74 def get_coverage_link_args(self) -> T.List[str]:
75 return []
76
77 def gen_vs_module_defs_args(self) -> T.List[str]:
78 return []
79
80 def build_rpath_args(self, build_dir: str, from_dir: str, target: BuildTarget,
81 extra_paths: T.Optional[T.List[str]] = None
82 ) -> T.Tuple[T.List[str], T.Set[bytes]]:
83 return ([], set())
84
85 def thread_flags(self) -> T.List[str]:
86 return []
87
88 def openmp_flags(self) -> T.List[str]:
89 return []
90
91 def get_option_link_args(self, target: 'BuildTarget', subproject: T.Optional[str] = None) -> T.List[str]:
92 return []
93
94 @classmethod
95 def unix_args_to_native(cls, args: T.List[str]) -> T.List[str]:
96 return args[:]
97
98 @classmethod
99 def native_args_to_unix(cls, args: T.List[str]) -> T.List[str]:
100 return args[:]
101
102 def get_link_debugfile_name(self, targetfile: str) -> T.Optional[str]:
103 return None
104
105 def get_link_debugfile_args(self, targetfile: str) -> T.List[str]:
106 # Static libraries do not have PDB files
107 return []
108
109 def get_always_args(self) -> T.List[str]:
110 return []
111
112 def get_linker_always_args(self) -> T.List[str]:
113 return []
114
115 def rsp_file_syntax(self) -> RSPFileSyntax:
116 """The format of the RSP file that this compiler supports.
117
118 If `self.can_linker_accept_rsp()` returns True, then this needs to
119 be implemented
120 """
121 assert not self.can_linker_accept_rsp(), f'{self.id} linker accepts RSP, but doesn\' provide a supported format, this is a bug'
122 raise EnvironmentException(f'{self.id} does not implement rsp format, this shouldn\'t be called')
123
124
125 class DynamicLinker(metaclass=mesonlib.SimpleABC):
126
127 """Base class for dynamic linkers."""
128
129 _OPTIMIZATION_ARGS: T.Dict[str, T.List[str]] = {
130 'plain': [],
131 '0': [],
132 'g': [],
133 '1': [],
134 '2': [],
135 '3': [],
136 's': [],
137 }
138
139 @abc.abstractproperty
140 def id(self) -> str:
141 pass
142
143 def _apply_prefix(self, *args: T.Union[str, T.List[str]]) -> T.List[str]:
144 if self.prefix_arg is None:
145 return mesonlib.listify(list(args))
146
147 return [arg
148 for group in args
149 for arg in self.prefix_arg.wrap(mesonlib.stringlistify(group))]
150
151 def __init__(self, exelist: T.List[str], env: Environment,
152 for_machine: mesonlib.MachineChoice, prefix_arg: T.Optional[LinkerOptionStyle],
153 always_args: T.List[str], *, system: str = 'unknown system',
154 version: str = 'unknown version'):
155 self.exelist = exelist
156 self.environment = env
157 self.for_machine = for_machine
158 self.system = system
159 self.version = version
160 self.prefix_arg = prefix_arg
161 self.always_args = always_args
162 self.machine: T.Optional[str] = None
163
164 def __repr__(self) -> str:
165 return '<{}: v{} `{}`>'.format(type(self).__name__, self.version, ' '.join(self.exelist))
166
167 def get_id(self) -> str:
168 return self.id
169
170 def get_exe(self) -> str:
171 return self.exelist[0]
172
173 def get_version_string(self) -> str:
174 return f'({self.id} {self.version})'
175
176 def get_exelist(self) -> T.List[str]:
177 return self.exelist.copy()
178
179 def get_accepts_rsp(self) -> bool:
180 # rsp files are only used when building on Windows because we want to
181 # avoid issues with quoting and max argument length
182 return mesonlib.is_windows()
183
184 def rsp_file_syntax(self) -> RSPFileSyntax:
185 """The format of the RSP file that this compiler supports.
186
187 If `self.can_linker_accept_rsp()` returns True, then this needs to
188 be implemented
189 """
190 return RSPFileSyntax.GCC
191
192 def get_always_args(self) -> T.List[str]:
193 return self.always_args.copy()
194
195 def get_lib_prefix(self) -> str:
196 return ''
197
198 # XXX: is use_ldflags a compiler or a linker attribute?
199
200 def get_option_args(self, target: 'BuildTarget', env: 'Environment', subproject: T.Optional[str] = None) -> T.List[str]:
201 return []
202
203 def get_option_link_args(self, target: 'BuildTarget', subproject: T.Optional[str] = None) -> T.List[str]:
204 return []
205
206 def has_multi_arguments(self, args: T.List[str]) -> T.Tuple[bool, bool]:
207 raise EnvironmentException(f'Language {self.id} does not support has_multi_link_arguments.')
208
209 def get_debugfile_name(self, targetfile: str) -> T.Optional[str]:
210 '''Name of debug file written out (see below)'''
211 return None
212
213 def get_debugfile_args(self, targetfile: str) -> T.List[str]:
214 """Some compilers (MSVC) write debug into a separate file.
215
216 This method takes the target object path and returns a list of
217 commands to append to the linker invocation to control where that
218 file is written.
219 """
220 return []
221
222 def get_optimization_link_args(self, optimization_level: str) -> T.List[str]:
223 # We can override these in children by just overriding the
224 # _OPTIMIZATION_ARGS value.
225 return mesonlib.listify([self._apply_prefix(a) for a in self._OPTIMIZATION_ARGS[optimization_level]])
226
227 def get_std_shared_lib_args(self) -> T.List[str]:
228 return []
229
230 def get_std_shared_module_args(self, Target: 'BuildTarget') -> T.List[str]:
231 return self.get_std_shared_lib_args()
232
233 def get_pie_args(self) -> T.List[str]:
234 # TODO: this really needs to take a boolean and return the args to
235 # disable pie, otherwise it only acts to enable pie if pie *isn't* the
236 # default.
237 raise EnvironmentException(f'Linker {self.id} does not support position-independent executable')
238
239 def get_lto_args(self) -> T.List[str]:
240 return []
241
242 def get_thinlto_cache_args(self, path: str) -> T.List[str]:
243 return []
244
245 def get_lto_obj_cache_path(self, path: str) -> T.List[str]:
246 return []
247
248 def sanitizer_args(self, value: T.List[str]) -> T.List[str]:
249 return []
250
251 def get_asneeded_args(self) -> T.List[str]:
252 return []
253
254 def get_link_whole_for(self, args: T.List[str]) -> T.List[str]:
255 raise EnvironmentException(
256 f'Linker {self.id} does not support link_whole')
257
258 def get_allow_undefined_args(self) -> T.List[str]:
259 raise EnvironmentException(
260 f'Linker {self.id} does not support allow undefined')
261
262 @abc.abstractmethod
263 def get_output_args(self, outputname: str) -> T.List[str]:
264 pass
265
266 def get_coverage_args(self) -> T.List[str]:
267 raise EnvironmentException(f"Linker {self.id} doesn't implement coverage data generation.")
268
269 def gen_vs_module_defs_args(self, defsfile: str) -> T.List[str]:
270 return []
271
272 @abc.abstractmethod
273 def get_search_args(self, dirname: str) -> T.List[str]:
274 pass
275
276 def export_dynamic_args(self) -> T.List[str]:
277 return []
278
279 def import_library_args(self, implibname: str) -> T.List[str]:
280 """The name of the outputted import library.
281
282 This implementation is used only on Windows by compilers that use GNU ld
283 """
284 return []
285
286 def thread_flags(self) -> T.List[str]:
287 return []
288
289 def no_undefined_args(self) -> T.List[str]:
290 """Arguments to error if there are any undefined symbols at link time.
291
292 This is the inverse of get_allow_undefined_args().
293
294 TODO: A future cleanup might merge this and
295 get_allow_undefined_args() into a single method taking a
296 boolean
297 """
298 return []
299
300 def fatal_warnings(self) -> T.List[str]:
301 """Arguments to make all warnings errors."""
302 return []
303
304 def headerpad_args(self) -> T.List[str]:
305 # Only used by the Apple linker
306 return []
307
308 def get_win_subsystem_args(self, value: str) -> T.List[str]:
309 # Only used if supported by the dynamic linker and
310 # only when targeting Windows
311 return []
312
313 def bitcode_args(self) -> T.List[str]:
314 raise MesonException('This linker does not support bitcode bundles')
315
316 def build_rpath_args(self, build_dir: str, from_dir: str, target: BuildTarget,
317 extra_paths: T.Optional[T.List[str]] = None
318 ) -> T.Tuple[T.List[str], T.Set[bytes]]:
319 return ([], set())
320
321 def get_soname_args(self, prefix: str, shlib_name: str,
322 suffix: str, soversion: str, darwin_versions: T.Tuple[str, str]) -> T.List[str]:
323 return []
324
325 def get_archive_name(self, filename: str) -> str:
326 #Only used by AIX.
327 return str()
328
329 def get_command_to_archive_shlib(self) -> T.List[str]:
330 #Only used by AIX.
331 return []
332
333
334 if T.TYPE_CHECKING:
335 StaticLinkerBase = StaticLinker
336 DynamicLinkerBase = DynamicLinker
337 else:
338 StaticLinkerBase = DynamicLinkerBase = object
339
340
341 class VisualStudioLikeLinker(StaticLinkerBase):
342 always_args = ['/NOLOGO']
343
344 def __init__(self, machine: str):
345 self.machine = machine
346
347 def get_always_args(self) -> T.List[str]:
348 return self.always_args.copy()
349
350 def get_linker_always_args(self) -> T.List[str]:
351 return self.always_args.copy()
352
353 def get_output_args(self, target: str) -> T.List[str]:
354 args: T.List[str] = []
355 if self.machine:
356 args += ['/MACHINE:' + self.machine]
357 args += ['/OUT:' + target]
358 return args
359
360 @classmethod
361 def unix_args_to_native(cls, args: T.List[str]) -> T.List[str]:
362 from ..compilers.c import VisualStudioCCompiler
363 return VisualStudioCCompiler.unix_args_to_native(args)
364
365 @classmethod
366 def native_args_to_unix(cls, args: T.List[str]) -> T.List[str]:
367 from ..compilers.c import VisualStudioCCompiler
368 return VisualStudioCCompiler.native_args_to_unix(args)
369
370 def rsp_file_syntax(self) -> RSPFileSyntax:
371 return RSPFileSyntax.MSVC
372
373
374 class VisualStudioLinker(VisualStudioLikeLinker, StaticLinker):
375
376 """Microsoft's lib static linker."""
377
378 id = 'lib'
379
380 def __init__(self, exelist: T.List[str], env: Environment, machine: str):
381 StaticLinker.__init__(self, exelist, env)
382 VisualStudioLikeLinker.__init__(self, machine)
383
384
385 class IntelVisualStudioLinker(VisualStudioLikeLinker, StaticLinker):
386
387 """Intel's xilib static linker."""
388
389 id = 'xilib'
390
391 def __init__(self, exelist: T.List[str], env: Environment, machine: str):
392 StaticLinker.__init__(self, exelist, env)
393 VisualStudioLikeLinker.__init__(self, machine)
394
395
396 class ArLinker(ArLikeLinker, StaticLinker):
397 id = 'ar'
398
399 def __init__(self, for_machine: mesonlib.MachineChoice, exelist: T.List[str], env: Environment):
400 super().__init__(exelist, env)
401 stdo = mesonlib.Popen_safe(self.exelist + ['-h'])[1]
402 # Enable deterministic builds if they are available.
403 stdargs = 'csr'
404 thinargs = ''
405 if '[D]' in stdo:
406 stdargs += 'D'
407 if '[T]' in stdo:
408 thinargs = 'T'
409 self.std_args = [stdargs]
410 self.std_thin_args = [stdargs + thinargs]
411 self.can_rsp = '@<' in stdo
412 self.for_machine = for_machine
413
414 def can_linker_accept_rsp(self) -> bool:
415 return self.can_rsp
416
417 def get_std_link_args(self, env: 'Environment', is_thin: bool) -> T.List[str]:
418 # Thin archives are a GNU extension not supported by the system linkers
419 # on Mac OS X, Solaris, or illumos, so don't build them on those OSes.
420 # OS X ld rejects with: "file built for unknown-unsupported file format"
421 # illumos/Solaris ld rejects with: "unknown file type"
422 # OS/2 ld rejects with: "malformed input file (not rel or archive)"
423 if is_thin and not env.machines[self.for_machine].is_darwin() \
424 and not env.machines[self.for_machine].is_sunos() \
425 and not env.machines[self.for_machine].is_os2():
426 return self.std_thin_args
427 else:
428 return self.std_args
429
430
431 class AppleArLinker(ArLinker):
432
433 # mostly this is used to determine that we need to call ranlib
434
435 id = 'applear'
436
437
438 class ArmarLinker(ArLikeLinker, StaticLinker):
439 id = 'armar'
440
441
442 class DLinker(StaticLinker):
443 def __init__(self, exelist: T.List[str], env: Environment, arch: str, *, rsp_syntax: RSPFileSyntax = RSPFileSyntax.GCC):
444 super().__init__(exelist, env)
445 self.id = exelist[0]
446 self.arch = arch
447 self.__rsp_syntax = rsp_syntax
448
449 def get_std_link_args(self, env: 'Environment', is_thin: bool) -> T.List[str]:
450 return ['-lib']
451
452 def get_output_args(self, target: str) -> T.List[str]:
453 return ['-of=' + target]
454
455 def get_linker_always_args(self) -> T.List[str]:
456 if mesonlib.is_windows():
457 if self.arch == 'x86_64':
458 return ['-m64']
459 elif self.arch == 'x86_mscoff' and self.id == 'dmd':
460 return ['-m32mscoff']
461 return ['-m32']
462 return []
463
464 def rsp_file_syntax(self) -> RSPFileSyntax:
465 return self.__rsp_syntax
466
467
468 class CcrxLinker(StaticLinker):
469
470 def __init__(self, exelist: T.List[str], env: Environment):
471 super().__init__(exelist, env)
472 self.id = 'rlink'
473
474 def can_linker_accept_rsp(self) -> bool:
475 return False
476
477 def get_output_args(self, target: str) -> T.List[str]:
478 return [f'-output={target}']
479
480 def get_linker_always_args(self) -> T.List[str]:
481 return ['-nologo', '-form=library']
482
483
484 class Xc16Linker(StaticLinker):
485
486 def __init__(self, exelist: T.List[str], env: Environment):
487 super().__init__(exelist, env)
488 self.id = 'xc16-ar'
489
490 def can_linker_accept_rsp(self) -> bool:
491 return False
492
493 def get_output_args(self, target: str) -> T.List[str]:
494 return [f'{target}']
495
496 def get_linker_always_args(self) -> T.List[str]:
497 return ['rcs']
498
499
500 class Xc32ArLinker(ArLinker):
501
502 """Static linker for Microchip XC32 compiler."""
503
504 id = 'xc32-ar'
505
506
507 class CompCertLinker(StaticLinker):
508
509 def __init__(self, exelist: T.List[str], env: Environment):
510 super().__init__(exelist, env)
511 self.id = 'ccomp'
512
513 def can_linker_accept_rsp(self) -> bool:
514 return False
515
516 def get_output_args(self, target: str) -> T.List[str]:
517 return [f'-o{target}']
518
519
520 class TILinker(StaticLinker):
521
522 def __init__(self, exelist: T.List[str], env: Environment):
523 super().__init__(exelist, env)
524 self.id = 'ti-ar'
525
526 def can_linker_accept_rsp(self) -> bool:
527 return False
528
529 def get_output_args(self, target: str) -> T.List[str]:
530 return [f'{target}']
531
532 def get_linker_always_args(self) -> T.List[str]:
533 return ['-r']
534
535
536 class C2000Linker(TILinker):
537 # Required for backwards compat with projects created before ti-cgt support existed
538 id = 'ar2000'
539
540 class C6000Linker(TILinker):
541 id = 'ar6000'
542
543
544 class AIXArLinker(ArLikeLinker, StaticLinker):
545 id = 'aixar'
546 std_args = ['-csr', '-Xany']
547
548
549 class MetrowerksStaticLinker(StaticLinker):
550
551 def can_linker_accept_rsp(self) -> bool:
552 return True
553
554 def get_linker_always_args(self) -> T.List[str]:
555 return ['-library']
556
557 def get_output_args(self, target: str) -> T.List[str]:
558 return ['-o', target]
559
560 def rsp_file_syntax(self) -> RSPFileSyntax:
561 return RSPFileSyntax.GCC
562
563
564 class MetrowerksStaticLinkerARM(MetrowerksStaticLinker):
565 id = 'mwldarm'
566
567
568 class MetrowerksStaticLinkerEmbeddedPowerPC(MetrowerksStaticLinker):
569 id = 'mwldeppc'
570
571 class TaskingStaticLinker(StaticLinker):
572 id = 'tasking'
573
574 def __init__(self, exelist: T.List[str], env: Environment):
575 super().__init__(exelist, env)
576
577 def can_linker_accept_rsp(self) -> bool:
578 return True
579
580 def rsp_file_syntax(self) -> RSPFileSyntax:
581 return RSPFileSyntax.TASKING
582
583 def get_output_args(self, target: str) -> T.List[str]:
584 return ['-n', target]
585
586 def get_linker_always_args(self) -> T.List[str]:
587 return ['-r']
588
589
590 class EmxomfArLinker(ArLinker):
591 id = 'emxomfar'
592
593 def get_std_link_args(self, env: 'Environment', is_thin: bool) -> T.List[str]:
594 return ['cr']
595
596 def prepare_rpaths(raw_rpaths: T.Tuple[str, ...], build_dir: str, from_dir: str) -> T.List[str]:
597 # The rpaths we write must be relative if they point to the build dir,
598 # because otherwise they have different length depending on the build
599 # directory. This breaks reproducible builds.
600 internal_format_rpaths = [evaluate_rpath(p, build_dir, from_dir) for p in raw_rpaths]
601 ordered_rpaths = order_rpaths(internal_format_rpaths)
602 return ordered_rpaths
603
604
605 def order_rpaths(rpath_list: T.List[str]) -> T.List[str]:
606 # We want rpaths that point inside our build dir to always override
607 # those pointing to other places in the file system. This is so built
608 # binaries prefer our libraries to the ones that may lie somewhere
609 # in the file system, such as /lib/x86_64-linux-gnu.
610 #
611 # The correct thing to do here would be C++'s std::stable_partition.
612 # Python standard library does not have it, so replicate it with
613 # sort, which is guaranteed to be stable.
614 return sorted(rpath_list, key=os.path.isabs)
615
616
617 def evaluate_rpath(p: str, build_dir: str, from_dir: str) -> str:
618 if p == from_dir:
619 return '' # relpath errors out in this case
620 elif path_has_root(p):
621 return p # These can be outside of build dir.
622 else:
623 return os.path.relpath(os.path.join(build_dir, p), os.path.join(build_dir, from_dir))
624
625
626 class PosixDynamicLinkerMixin(DynamicLinkerBase):
627
628 """Mixin class for POSIX-ish linkers.
629
630 This is obviously a pretty small subset of the linker interface, but
631 enough dynamic linkers that meson supports are POSIX-like but not
632 GNU-like that it makes sense to split this out.
633 """
634
635 def get_output_args(self, outputname: str) -> T.List[str]:
636 return ['-o', outputname]
637
638 def get_std_shared_lib_args(self) -> T.List[str]:
639 return ['-shared']
640
641 def get_search_args(self, dirname: str) -> T.List[str]:
642 return ['-L' + dirname]
643
644 def sanitizer_args(self, value: T.List[str]) -> T.List[str]:
645 return []
646
647
648 class GnuLikeDynamicLinkerMixin(DynamicLinkerBase):
649
650 """Mixin class for dynamic linkers that provides gnu-like interface.
651
652 This acts as a base for the GNU linkers (bfd and gold), LLVM's lld, and
653 other linkers like GNU-ld.
654 """
655
656 if T.TYPE_CHECKING:
657 for_machine = MachineChoice.HOST
658 def _apply_prefix(self, *args: T.Union[str, T.List[str]]) -> T.List[str]: ...
659
660 _OPTIMIZATION_ARGS: T.Dict[str, T.List[str]] = {
661 'plain': [],
662 '0': [],
663 'g': [],
664 '1': [],
665 '2': [],
666 '3': ['-O1'],
667 's': [],
668 }
669
670 _SUBSYSTEMS: T.Dict[str, str] = {
671 "native": "1",
672 "windows": "windows",
673 "console": "console",
674 "posix": "7",
675 "efi_application": "10",
676 "efi_boot_service_driver": "11",
677 "efi_runtime_driver": "12",
678 "efi_rom": "13",
679 "boot_application": "16",
680 }
681
682 def get_accepts_rsp(self) -> bool:
683 return True
684
685 def get_pie_args(self) -> T.List[str]:
686 return ['-pie']
687
688 def get_asneeded_args(self) -> T.List[str]:
689 return self._apply_prefix('--as-needed')
690
691 def get_link_whole_for(self, args: T.List[str]) -> T.List[str]:
692 if not args:
693 return args
694 return self._apply_prefix('--whole-archive') + args + self._apply_prefix('--no-whole-archive')
695
696 def get_allow_undefined_args(self) -> T.List[str]:
697 return self._apply_prefix('--allow-shlib-undefined')
698
699 def get_lto_args(self) -> T.List[str]:
700 return ['-flto']
701
702 def sanitizer_args(self, value: T.List[str]) -> T.List[str]:
703 if not value:
704 return value
705 return [f'-fsanitize={",".join(value)}']
706
707 def get_coverage_args(self) -> T.List[str]:
708 return ['--coverage']
709
710 def gen_vs_module_defs_args(self, defsfile: str) -> T.List[str]:
711 # On Windows targets, .def files may be specified on the linker command
712 # line like an object file.
713 m = self.environment.machines[self.for_machine]
714 if m.is_windows() or m.is_cygwin():
715 return [defsfile]
716 # For other targets, discard the .def file.
717 return []
718
719 def export_dynamic_args(self) -> T.List[str]:
720 m = self.environment.machines[self.for_machine]
721 if m.is_windows() or m.is_cygwin():
722 return self._apply_prefix('--export-all-symbols')
723 return self._apply_prefix('-export-dynamic')
724
725 def import_library_args(self, implibname: str) -> T.List[str]:
726 return self._apply_prefix('--out-implib=' + implibname)
727
728 def thread_flags(self) -> T.List[str]:
729 if self.environment.machines[self.for_machine].is_haiku():
730 return []
731 return ['-pthread']
732
733 def no_undefined_args(self) -> T.List[str]:
734 return self._apply_prefix('--no-undefined')
735
736 def fatal_warnings(self) -> T.List[str]:
737 return self._apply_prefix('--fatal-warnings')
738
739 def get_soname_args(self, prefix: str, shlib_name: str, suffix: str,
740 soversion: str, darwin_versions: T.Tuple[str, str]
741 ) -> T.List[str]:
742 m = self.environment.machines[self.for_machine]
743 if m.is_windows() or m.is_cygwin():
744 # For PE/COFF the soname argument has no effect
745 return []
746 sostr = '' if soversion is None else '.' + soversion
747 return self._apply_prefix(['-soname', f'{prefix}{shlib_name}.{suffix}{sostr}'])
748
749 def build_rpath_args(self, build_dir: str, from_dir: str, target: BuildTarget,
750 extra_paths: T.Optional[T.List[str]] = None
751 ) -> T.Tuple[T.List[str], T.Set[bytes]]:
752 m = self.environment.machines[self.for_machine]
753 if m.is_windows() or m.is_cygwin():
754 return ([], set())
755 rpath_paths = target.determine_rpath_dirs()
756 if not rpath_paths and not target.install_rpath and not target.build_rpath and not extra_paths:
757 return ([], set())
758 args: T.List[str] = []
759 origin_placeholder = '$ORIGIN'
760 processed_rpaths = prepare_rpaths(rpath_paths, build_dir, from_dir)
761 # Need to deduplicate rpaths, as macOS's install_name_tool
762 # is *very* allergic to duplicate -delete_rpath arguments
763 # when calling depfixer on installation.
764 all_paths = mesonlib.OrderedSet([os.path.join(origin_placeholder, p) for p in processed_rpaths])
765 rpath_dirs_to_remove: T.Set[bytes] = set()
766 for p in all_paths:
767 rpath_dirs_to_remove.add(p.encode('utf8'))
768 # Build_rpath is used as-is (it is usually absolute).
769 if target.build_rpath != '':
770 all_paths.add(target.build_rpath)
771 for p in target.build_rpath.split(':'):
772 rpath_dirs_to_remove.add(p.encode('utf8'))
773 if extra_paths:
774 all_paths.update(extra_paths)
775
776 # TODO: should this actually be "for (dragonfly|open)bsd"?
777 if mesonlib.is_dragonflybsd() or mesonlib.is_openbsd():
778 # This argument instructs the compiler to record the value of
779 # ORIGIN in the .dynamic section of the elf. On Linux this is done
780 # by default, but is not on dragonfly/openbsd for some reason. Without this
781 # $ORIGIN in the runtime path will be undefined and any binaries
782 # linked against local libraries will fail to resolve them.
783 args.extend(self._apply_prefix(['-z', 'origin']))
784
785 # In order to avoid relinking for RPATH removal, the binary needs to contain just
786 # enough space in the ELF header to hold the final installation RPATH.
787 paths = ':'.join(all_paths)
788 paths_length = len(paths.encode('utf-8'))
789 install_rpath_length = len(target.install_rpath.encode('utf-8'))
790 if paths_length < install_rpath_length:
791 padding = 'X' * (install_rpath_length - paths_length)
792 if not paths:
793 paths = padding
794 else:
795 paths = paths + ':' + padding
796 args.extend(self._apply_prefix(['-rpath', paths]))
797
798 # TODO: should this actually be "for solaris/sunos"?
799 # NOTE: Remove the zigcc check once zig support "-rpath-link"
800 # See https://github.com/ziglang/zig/issues/18713
801 if mesonlib.is_sunos() or self.id == 'ld.zigcc':
802 return (args, rpath_dirs_to_remove)
803
804 # Rpaths to use while linking must be absolute. These are not
805 # written to the binary. Needed only with GNU ld, and only for
806 # versions before 2.28:
807 # https://sourceware.org/bugzilla/show_bug.cgi?id=20535
808 # https://sourceware.org/bugzilla/show_bug.cgi?id=16936
809 # Not needed on Windows or other platforms that don't use RPATH
810 # https://github.com/mesonbuild/meson/issues/1897
811 #
812 # In 2.28 and on, $ORIGIN tokens inside of -rpath are respected,
813 # so we do not need to duplicate it in -rpath-link.
814 #
815 # In addition, this linker option tends to be quite long and some
816 # compilers have trouble dealing with it. That's why we will include
817 # one option per folder, like this:
818 #
819 # -Wl,-rpath-link,/path/to/folder1 -Wl,-rpath,/path/to/folder2 ...
820 #
821 # ...instead of just one single looooong option, like this:
822 #
823 # -Wl,-rpath-link,/path/to/folder1:/path/to/folder2:...
824 if self.id in {'ld.bfd', 'ld.gold'} and mesonlib.version_compare(self.version, '<2.28'):
825 for p in rpath_paths:
826 args.extend(self._apply_prefix(['-rpath-link', os.path.join(build_dir, p)]))
827
828 return (args, rpath_dirs_to_remove)
829
830 def get_win_subsystem_args(self, value: str) -> T.List[str]:
831 # MinGW only directly supports a couple of the possible
832 # PE application types. The raw integer works as an argument
833 # as well, and is always accepted, so we manually map the
834 # other types here. List of all types:
835 # https://github.com/wine-mirror/wine/blob/3ded60bd1654dc689d24a23305f4a93acce3a6f2/include/winnt.h#L2492-L2507
836 versionsuffix = None
837 if ',' in value:
838 value, versionsuffix = value.split(',', 1)
839 newvalue = self._SUBSYSTEMS.get(value)
840 if newvalue is not None:
841 if versionsuffix is not None:
842 newvalue += f':{versionsuffix}'
843 args = ['--subsystem', newvalue]
844 else:
845 raise mesonlib.MesonBugException(f'win_subsystem: {value!r} not handled in MinGW linker. This should not be possible.')
846
847 return self._apply_prefix(args)
848
849
850 class AppleDynamicLinker(PosixDynamicLinkerMixin, DynamicLinker):
851
852 """Apple's ld implementation."""
853
854 id = 'ld64'
855
856 def get_asneeded_args(self) -> T.List[str]:
857 return self._apply_prefix('-dead_strip_dylibs')
858
859 def get_allow_undefined_args(self) -> T.List[str]:
860 # iOS doesn't allow undefined symbols when linking
861 if self.system == 'ios':
862 return []
863 else:
864 return self._apply_prefix(['-undefined', 'dynamic_lookup'])
865
866 def get_std_shared_module_args(self, target: 'BuildTarget') -> T.List[str]:
867 if self.system == 'ios':
868 return ['-dynamiclib']
869 else:
870 return ['-bundle'] + self.get_allow_undefined_args()
871
872 def get_pie_args(self) -> T.List[str]:
873 return []
874
875 def get_link_whole_for(self, args: T.List[str]) -> T.List[str]:
876 result: T.List[str] = []
877 for a in args:
878 result.extend(self._apply_prefix('-force_load'))
879 result.append(a)
880 return result
881
882 def get_coverage_args(self) -> T.List[str]:
883 return ['--coverage']
884
885 def sanitizer_args(self, value: T.List[str]) -> T.List[str]:
886 if not value:
887 return value
888 return [f'-fsanitize={",".join(value)}']
889
890 def no_undefined_args(self) -> T.List[str]:
891 # We used to emit -undefined,error, but starting with Xcode 15 /
892 # Sonoma, doing so triggers "ld: warning: -undefined error is
893 # deprecated". Given that "-undefined error" is documented to be the
894 # linker's default behaviour, this warning seems ill advised. However,
895 # it does create a lot of noise. As "-undefined error" is the default
896 # behaviour, the least bad way to deal with this seems to be to just
897 # not emit anything here. Of course that only works as long as nothing
898 # else injects -undefined dynamic_lookup, or such. Complain to Apple.
899 return []
900
901 def headerpad_args(self) -> T.List[str]:
902 return self._apply_prefix('-headerpad_max_install_names')
903
904 def bitcode_args(self) -> T.List[str]:
905 return self._apply_prefix('-bitcode_bundle')
906
907 def no_warn_duplicate_libraries(self) -> T.List[str]:
908 # -no_warn_duplicate_libraries was added in Xcode 15, which has two
909 # linkers: classic ld64 (PROJECT:ld64-907) and the new one
910 # (PROJECT:dyld-1009.5). Both version numbers are >= 907, so a
911 # single comparison works for both.
912 if mesonlib.version_compare(self.version, '>=907'):
913 return self._apply_prefix('-no_warn_duplicate_libraries')
914 return []
915
916 def fatal_warnings(self) -> T.List[str]:
917 # no one else warns for duplicate libraries, and they're harmless;
918 # just make ld shup up when testing for supported flags
919 return self._apply_prefix('-fatal_warnings') + self.no_warn_duplicate_libraries()
920
921 def get_soname_args(self, prefix: str, shlib_name: str, suffix: str,
922 soversion: str, darwin_versions: T.Tuple[str, str]
923 ) -> T.List[str]:
924 install_name = ['@rpath/', prefix, shlib_name]
925 if soversion is not None:
926 install_name.append('.' + soversion)
927 install_name.append('.' + suffix)
928 args = ['-install_name', ''.join(install_name)]
929 if darwin_versions:
930 args.extend(['-compatibility_version', darwin_versions[0],
931 '-current_version', darwin_versions[1]])
932 return self._apply_prefix(args)
933
934 def build_rpath_args(self, build_dir: str, from_dir: str, target: BuildTarget,
935 extra_paths: T.Optional[T.List[str]] = None
936 ) -> T.Tuple[T.List[str], T.Set[bytes]]:
937 rpath_paths = target.determine_rpath_dirs()
938 if not rpath_paths and not target.install_rpath and not target.build_rpath and not extra_paths:
939 return ([], set())
940 args: T.List[str] = []
941 rpath_dirs_to_remove: T.Set[bytes] = set()
942 # @loader_path is the equivalent of $ORIGIN on macOS
943 # https://stackoverflow.com/q/26280738
944 origin_placeholder = '@loader_path'
945 processed_rpaths = prepare_rpaths(rpath_paths, build_dir, from_dir)
946 all_paths = mesonlib.OrderedSet([os.path.join(origin_placeholder, p) for p in processed_rpaths])
947 if target.build_rpath != '':
948 all_paths.update(target.build_rpath.split(':'))
949 if extra_paths:
950 all_paths.update(extra_paths)
951 for rp in all_paths:
952 rpath_dirs_to_remove.add(rp.encode('utf8'))
953 args.extend(self._apply_prefix(['-rpath', rp]))
954
955 return (args, rpath_dirs_to_remove)
956
957 def get_thinlto_cache_args(self, path: str) -> T.List[str]:
958 return self._apply_prefix(['-cache_path_lto', path])
959
960 def get_lto_obj_cache_path(self, path: str) -> T.List[str]:
961 # https://clang.llvm.org/docs/CommandGuide/clang.html#cmdoption-flto
962 if mesonlib.version_compare(self.version, '>=123.2'):
963 return self._apply_prefix(['-object_path_lto', path])
964 return []
965
966 def export_dynamic_args(self) -> T.List[str]:
967 if mesonlib.version_compare(self.version, '>=224.1'):
968 return self._apply_prefix('-export_dynamic')
969 return []
970
971
972 class LLVMLD64DynamicLinker(AppleDynamicLinker):
973
974 id = 'ld64.lld'
975
976 def no_warn_duplicate_libraries(self) -> T.List[str]:
977 # The flag currently has no effect on ld64.lld, but it is accepted
978 # since LLVM 19 and may do something in the future.
979 if mesonlib.version_compare(self.version, '>=19'):
980 return self._apply_prefix('-no_warn_duplicate_libraries')
981 return []
982
983 def export_dynamic_args(self) -> T.List[str]:
984 # -export_dynamic existed before LLVM 13 but did not work properly
985 # on macOS until https://github.com/llvm/llvm-project/commit/3eb2fc4b
986 if mesonlib.version_compare(self.version, '>=13'):
987 return self._apply_prefix('-export_dynamic')
988 return []
989
990
991 class GnuDynamicLinker(GnuLikeDynamicLinkerMixin, PosixDynamicLinkerMixin, DynamicLinker):
992
993 """Representation of GNU ld.bfd and ld.gold."""
994
995
996 class GnuGoldDynamicLinker(GnuDynamicLinker):
997
998 id = 'ld.gold'
999
1000 def get_thinlto_cache_args(self, path: str) -> T.List[str]:
1001 return self._apply_prefix(['-plugin-opt', 'cache-dir=' + path])
1002
1003
1004 class GnuBFDDynamicLinker(GnuDynamicLinker):
1005
1006 id = 'ld.bfd'
1007
1008
1009 class MoldDynamicLinker(GnuDynamicLinker):
1010
1011 id = 'ld.mold'
1012
1013 def get_thinlto_cache_args(self, path: str) -> T.List[str]:
1014 return self._apply_prefix(['--thinlto-cache-dir=' + path])
1015
1016
1017 class LLVMDynamicLinker(GnuLikeDynamicLinkerMixin, PosixDynamicLinkerMixin, DynamicLinker):
1018
1019 """Representation of LLVM's ld.lld linker.
1020
1021 This is only the gnu-like linker, not the apple like or link.exe like
1022 linkers.
1023 """
1024
1025 id = 'ld.lld'
1026
1027 def __init__(self, exelist: T.List[str], env: Environment,
1028 for_machine: mesonlib.MachineChoice, prefix_arg: T.Optional[LinkerOptionStyle],
1029 always_args: T.List[str], *, system: str = 'unknown system',
1030 version: str = 'unknown version'):
1031 super().__init__(exelist, env, for_machine, prefix_arg, always_args, system=system, version=version)
1032
1033 # Some targets don't seem to support this argument (windows, wasm, ...)
1034 self.has_allow_shlib_undefined = self._supports_flag('--allow-shlib-undefined', always_args)
1035 # These aren't supported by TI Arm Clang
1036 self.has_as_needed = self._supports_flag('--as-needed', always_args)
1037 self.has_no_undefined = self._supports_flag('--no-undefined', always_args)
1038
1039 def _supports_flag(self, flag: str, always_args: T.List[str]) -> bool:
1040 _, _, e = mesonlib.Popen_safe(self.exelist + always_args + self._apply_prefix(flag))
1041 return (
1042 # Versions < 9 do not have a quoted argument
1043 (f'unknown argument: {flag}' not in e) and
1044 (f"unknown argument: '{flag}'" not in e) and
1045 # TI Arm Clang uses a different message
1046 (f'invalid option: {flag}' not in e)
1047 )
1048
1049 def get_allow_undefined_args(self) -> T.List[str]:
1050 if self.has_allow_shlib_undefined:
1051 return self._apply_prefix('--allow-shlib-undefined')
1052 return []
1053
1054 def get_asneeded_args(self) -> T.List[str]:
1055 if self.has_as_needed:
1056 return self._apply_prefix('--as-needed')
1057 return []
1058
1059 def no_undefined_args(self) -> T.List[str]:
1060 if self.has_no_undefined:
1061 return self._apply_prefix('--no-undefined')
1062 return []
1063
1064 def get_thinlto_cache_args(self, path: str) -> T.List[str]:
1065 return self._apply_prefix(['--thinlto-cache-dir=' + path])
1066
1067 def get_win_subsystem_args(self, value: str) -> T.List[str]:
1068 # lld does not support a numeric subsystem value
1069 version = None
1070 if ',' in value:
1071 value, version = value.split(',', 1)
1072 if value in self._SUBSYSTEMS:
1073 if version is not None:
1074 value += f':{version}'
1075 return self._apply_prefix(['--subsystem', value])
1076 else:
1077 raise mesonlib.MesonBugException(f'win_subsystem: {value} not handled in lld linker. This should not be possible.')
1078
1079
1080 class ZigCCDynamicLinker(LLVMDynamicLinker):
1081 id = 'ld.zigcc'
1082
1083 def get_thinlto_cache_args(self, path: str) -> T.List[str]:
1084 return []
1085
1086
1087 class WASMDynamicLinker(GnuLikeDynamicLinkerMixin, PosixDynamicLinkerMixin, DynamicLinker):
1088
1089 """Emscripten's wasm-ld."""
1090
1091 id = 'ld.wasm'
1092
1093 def get_allow_undefined_args(self) -> T.List[str]:
1094 return ['-sERROR_ON_UNDEFINED_SYMBOLS=0']
1095
1096 def no_undefined_args(self) -> T.List[str]:
1097 return ['-sERROR_ON_UNDEFINED_SYMBOLS=1']
1098
1099 def get_soname_args(self, prefix: str, shlib_name: str, suffix: str,
1100 soversion: str, darwin_versions: T.Tuple[str, str]
1101 ) -> T.List[str]:
1102 raise MesonException(f'{self.id} does not support shared libraries.')
1103
1104 def get_asneeded_args(self) -> T.List[str]:
1105 return []
1106
1107 def build_rpath_args(self, build_dir: str, from_dir: str, target: BuildTarget,
1108 extra_paths: T.Optional[T.List[str]] = None
1109 ) -> T.Tuple[T.List[str], T.Set[bytes]]:
1110 return ([], set())
1111
1112
1113 class CcrxDynamicLinker(DynamicLinker):
1114
1115 """Linker for Renesas CCrx compiler."""
1116
1117 id = 'rlink'
1118
1119 def __init__(self, env: Environment, for_machine: mesonlib.MachineChoice,
1120 *, version: str = 'unknown version'):
1121 super().__init__(['rlink.exe'], env, for_machine, None, [],
1122 version=version)
1123
1124 def get_accepts_rsp(self) -> bool:
1125 return False
1126
1127 def get_lib_prefix(self) -> str:
1128 return '-lib='
1129
1130 def get_std_shared_lib_args(self) -> T.List[str]:
1131 return []
1132
1133 def get_output_args(self, outputname: str) -> T.List[str]:
1134 return [f'-output={outputname}']
1135
1136 def get_search_args(self, dirname: str) -> 'T.NoReturn':
1137 raise OSError('rlink.exe does not have a search dir argument')
1138
1139 def get_allow_undefined_args(self) -> T.List[str]:
1140 return []
1141
1142 def get_soname_args(self, prefix: str, shlib_name: str, suffix: str,
1143 soversion: str, darwin_versions: T.Tuple[str, str]
1144 ) -> T.List[str]:
1145 return []
1146
1147
1148 class Xc16DynamicLinker(DynamicLinker):
1149
1150 """Linker for Microchip XC16 compiler."""
1151
1152 id = 'xc16-gcc'
1153
1154 def __init__(self, env: Environment, for_machine: mesonlib.MachineChoice,
1155 *, version: str = 'unknown version'):
1156 super().__init__(['xc16-gcc'], env, for_machine, None, [],
1157 version=version)
1158
1159 def get_link_whole_for(self, args: T.List[str]) -> T.List[str]:
1160 if len(args) < 2:
1161 return args
1162 return self._apply_prefix('--start-group') + args + self._apply_prefix('--end-group')
1163
1164 def get_accepts_rsp(self) -> bool:
1165 return False
1166
1167 def get_lib_prefix(self) -> str:
1168 return ''
1169
1170 def get_std_shared_lib_args(self) -> T.List[str]:
1171 return []
1172
1173 def get_output_args(self, outputname: str) -> T.List[str]:
1174 return [f'-o{outputname}']
1175
1176 def get_search_args(self, dirname: str) -> 'T.NoReturn':
1177 raise OSError('xc16-gcc does not have a search dir argument')
1178
1179 def get_allow_undefined_args(self) -> T.List[str]:
1180 return []
1181
1182 def get_soname_args(self, prefix: str, shlib_name: str, suffix: str,
1183 soversion: str, darwin_versions: T.Tuple[str, str]
1184 ) -> T.List[str]:
1185 return []
1186
1187 def build_rpath_args(self, build_dir: str, from_dir: str, target: BuildTarget,
1188 extra_paths: T.Optional[T.List[str]] = None
1189 ) -> T.Tuple[T.List[str], T.Set[bytes]]:
1190 return ([], set())
1191
1192
1193 class Xc32DynamicLinker(GnuDynamicLinker):
1194
1195 """Linker for Microchip XC32 compiler."""
1196
1197 id = 'ld.xc32'
1198
1199 def sanitizer_args(self, value: T.List[str]) -> T.List[str]:
1200 return []
1201
1202 def get_coverage_args(self) -> T.List[str]:
1203 return DynamicLinker.get_coverage_args(self)
1204
1205 def get_pie_args(self) -> T.List[str]:
1206 return DynamicLinker.get_pie_args(self)
1207
1208 def thread_flags(self) -> T.List[str]:
1209 return []
1210
1211
1212 class CompCertDynamicLinker(DynamicLinker):
1213
1214 """Linker for CompCert C compiler."""
1215
1216 id = 'ccomp'
1217
1218 def __init__(self, env: Environment, for_machine: mesonlib.MachineChoice,
1219 *, version: str = 'unknown version'):
1220 super().__init__(['ccomp'], env, for_machine, None, [],
1221 version=version)
1222
1223 def get_link_whole_for(self, args: T.List[str]) -> T.List[str]:
1224 if not args:
1225 return args
1226 return self._apply_prefix('-Wl,--whole-archive') + args + self._apply_prefix('-Wl,--no-whole-archive')
1227
1228 def get_accepts_rsp(self) -> bool:
1229 return False
1230
1231 def get_lib_prefix(self) -> str:
1232 return ''
1233
1234 def get_std_shared_lib_args(self) -> T.List[str]:
1235 return []
1236
1237 def get_output_args(self, outputname: str) -> T.List[str]:
1238 return [f'-o{outputname}']
1239
1240 def get_search_args(self, dirname: str) -> T.List[str]:
1241 return [f'-L{dirname}']
1242
1243 def get_allow_undefined_args(self) -> T.List[str]:
1244 return []
1245
1246 def build_rpath_args(self, build_dir: str, from_dir: str, target: BuildTarget,
1247 extra_paths: T.Optional[T.List[str]] = None
1248 ) -> T.Tuple[T.List[str], T.Set[bytes]]:
1249 return ([], set())
1250
1251 class TIDynamicLinker(DynamicLinker):
1252
1253 """Linker for Texas Instruments compiler family."""
1254
1255 id = 'ti'
1256
1257 def __init__(self, exelist: T.List[str], env: Environment, for_machine: mesonlib.MachineChoice,
1258 *, version: str = 'unknown version'):
1259 super().__init__(exelist, env, for_machine, None, [],
1260 version=version)
1261
1262 def get_link_whole_for(self, args: T.List[str]) -> T.List[str]:
1263 if len(args) < 2:
1264 return args
1265 return self._apply_prefix('--start-group') + args + self._apply_prefix('--end-group')
1266
1267 def get_accepts_rsp(self) -> bool:
1268 return False
1269
1270 def get_lib_prefix(self) -> str:
1271 return '-l='
1272
1273 def get_std_shared_lib_args(self) -> T.List[str]:
1274 return []
1275
1276 def get_output_args(self, outputname: str) -> T.List[str]:
1277 return ['-z', f'--output_file={outputname}']
1278
1279 def get_search_args(self, dirname: str) -> 'T.NoReturn':
1280 raise OSError('TI compilers do not have a search dir argument')
1281
1282 def get_allow_undefined_args(self) -> T.List[str]:
1283 return []
1284
1285 def get_always_args(self) -> T.List[str]:
1286 return []
1287
1288
1289 class C2000DynamicLinker(TIDynamicLinker):
1290 # Required for backwards compat with projects created before ti-cgt support existed
1291 id = 'cl2000'
1292
1293 class C6000DynamicLinker(TIDynamicLinker):
1294 id = 'cl6000'
1295
1296
1297 class ArmDynamicLinker(PosixDynamicLinkerMixin, DynamicLinker):
1298
1299 """Linker for the ARM compiler."""
1300
1301 id = 'armlink'
1302
1303 def __init__(self, env: Environment, for_machine: mesonlib.MachineChoice,
1304 *, version: str = 'unknown version'):
1305 super().__init__(['armlink'], env, for_machine, None, [],
1306 version=version)
1307
1308 def get_accepts_rsp(self) -> bool:
1309 return False
1310
1311 def get_std_shared_lib_args(self) -> 'T.NoReturn':
1312 raise MesonException('The Arm Linkers do not support shared libraries')
1313
1314 def get_allow_undefined_args(self) -> T.List[str]:
1315 return []
1316
1317
1318 class ArmClangDynamicLinker(ArmDynamicLinker):
1319
1320 """Linker used with ARM's clang fork.
1321
1322 The interface is similar enough to the old ARM ld that it inherits and
1323 extends a few things as needed.
1324 """
1325
1326 def export_dynamic_args(self) -> T.List[str]:
1327 return ['--export_dynamic']
1328
1329 def import_library_args(self, implibname: str) -> T.List[str]:
1330 return ['--symdefs=' + implibname]
1331
1332 class QualcommLLVMDynamicLinker(LLVMDynamicLinker):
1333
1334 """ARM Linker from Snapdragon LLVM ARM Compiler."""
1335
1336 id = 'ld.qcld'
1337
1338 class ELDDynamicLinker(GnuLikeDynamicLinkerMixin, PosixDynamicLinkerMixin, DynamicLinker):
1339
1340 """Qualcomm's opensource embedded linker"""
1341
1342 id = 'ld.eld'
1343
1344
1345 class NAGDynamicLinker(PosixDynamicLinkerMixin, DynamicLinker):
1346
1347 """NAG Fortran linker, ld via gcc indirection.
1348
1349 Using nagfor -Wl,foo passes option foo to a backend gcc invocation.
1350 (This linking gathers the correct objects needed from the nagfor runtime
1351 system.)
1352 To pass gcc -Wl,foo options (i.e., to ld) one must apply indirection
1353 again: nagfor -Wl,-Wl,,foo
1354 """
1355
1356 id = 'nag'
1357
1358 def build_rpath_args(self, build_dir: str, from_dir: str, target: BuildTarget,
1359 extra_paths: T.Optional[T.List[str]] = None
1360 ) -> T.Tuple[T.List[str], T.Set[bytes]]:
1361 rpath_paths = target.determine_rpath_dirs()
1362 if not rpath_paths and not target.install_rpath and not target.build_rpath and not extra_paths:
1363 return ([], set())
1364 args: T.List[str] = []
1365 origin_placeholder = '$ORIGIN'
1366 processed_rpaths = prepare_rpaths(rpath_paths, build_dir, from_dir)
1367 all_paths = mesonlib.OrderedSet([os.path.join(origin_placeholder, p) for p in processed_rpaths])
1368 if target.build_rpath != '':
1369 all_paths.add(target.build_rpath)
1370 if extra_paths:
1371 all_paths.update(extra_paths)
1372 for rp in all_paths:
1373 args.extend(self._apply_prefix('-Wl,-Wl,,-rpath,,' + rp))
1374
1375 return (args, set())
1376
1377 def get_allow_undefined_args(self) -> T.List[str]:
1378 return []
1379
1380 def get_std_shared_lib_args(self) -> T.List[str]:
1381 from ..compilers.fortran import NAGFortranCompiler
1382 return NAGFortranCompiler.get_nagfor_quiet(self.version) + ['-Wl,-shared']
1383
1384
1385 class PGIDynamicLinker(PosixDynamicLinkerMixin, DynamicLinker):
1386
1387 """PGI linker."""
1388
1389 id = 'pgi'
1390
1391 def get_allow_undefined_args(self) -> T.List[str]:
1392 return []
1393
1394 def get_soname_args(self, prefix: str, shlib_name: str, suffix: str,
1395 soversion: str, darwin_versions: T.Tuple[str, str]
1396 ) -> T.List[str]:
1397 return []
1398
1399 def get_std_shared_lib_args(self) -> T.List[str]:
1400 # PGI -shared is Linux only.
1401 if mesonlib.is_windows():
1402 return ['-Bdynamic', '-Mmakedll']
1403 elif mesonlib.is_linux():
1404 return ['-shared']
1405 return []
1406
1407 def build_rpath_args(self, build_dir: str, from_dir: str, target: BuildTarget,
1408 extra_paths: T.Optional[T.List[str]] = None
1409 ) -> T.Tuple[T.List[str], T.Set[bytes]]:
1410 if not self.environment.machines[self.for_machine].is_windows():
1411 rpath_paths = target.determine_rpath_dirs()
1412 return (['-R' + os.path.join(build_dir, p) for p in rpath_paths], set())
1413 return ([], set())
1414
1415 NvidiaHPC_DynamicLinker = PGIDynamicLinker
1416
1417
1418 class PGIStaticLinker(StaticLinker):
1419 def __init__(self, exelist: T.List[str], env: Environment):
1420 super().__init__(exelist, env)
1421 self.id = 'ar'
1422 self.std_args = ['-r']
1423
1424 def get_std_link_args(self, env: 'Environment', is_thin: bool) -> T.List[str]:
1425 return self.std_args
1426
1427 def get_output_args(self, target: str) -> T.List[str]:
1428 return [target]
1429
1430 NvidiaHPC_StaticLinker = PGIStaticLinker
1431
1432
1433 class VisualStudioLikeLinkerMixin(DynamicLinkerBase):
1434
1435 """Mixin class for dynamic linkers that act like Microsoft's link.exe."""
1436
1437 if T.TYPE_CHECKING:
1438 for_machine = MachineChoice.HOST
1439 def _apply_prefix(self, *args: T.Union[str, T.List[str]]) -> T.List[str]: ...
1440
1441 _OPTIMIZATION_ARGS: T.Dict[str, T.List[str]] = {
1442 'plain': [],
1443 '0': [],
1444 'g': [],
1445 '1': [],
1446 '2': [],
1447 # The otherwise implicit REF and ICF linker optimisations are disabled by
1448 # /DEBUG. REF implies ICF.
1449 '3': ['/OPT:REF'],
1450 's': ['/INCREMENTAL:NO', '/OPT:REF'],
1451 }
1452
1453 def __init__(self, exelist: T.List[str], env: Environment,
1454 for_machine: mesonlib.MachineChoice, prefix_arg: T.Optional[LinkerOptionStyle],
1455 always_args: T.List[str], *, version: str = 'unknown version',
1456 direct: bool = True, machine: str = 'x86', rsp_syntax:
1457 RSPFileSyntax = RSPFileSyntax.MSVC):
1458 super().__init__(exelist, env, for_machine, prefix_arg, always_args, version=version)
1459 self.machine = machine
1460 self.direct = direct
1461 self.rsp_syntax = rsp_syntax
1462
1463 def invoked_by_compiler(self) -> bool:
1464 return not self.direct
1465
1466 def get_output_args(self, outputname: str) -> T.List[str]:
1467 return self._apply_prefix(['/MACHINE:' + self.machine, '/OUT:' + outputname])
1468
1469 def get_always_args(self) -> T.List[str]:
1470 parent = super().get_always_args()
1471 return self._apply_prefix('/nologo') + parent
1472
1473 def get_search_args(self, dirname: str) -> T.List[str]:
1474 return self._apply_prefix('/LIBPATH:' + dirname)
1475
1476 def get_std_shared_lib_args(self) -> T.List[str]:
1477 return self._apply_prefix('/DLL')
1478
1479 def get_debugfile_name(self, targetfile: str) -> str:
1480 return targetfile
1481
1482 def get_debugfile_args(self, targetfile: str) -> T.List[str]:
1483 return self._apply_prefix(['/DEBUG', '/PDB:' + self.get_debugfile_name(targetfile)])
1484
1485 def get_link_whole_for(self, args: T.List[str]) -> T.List[str]:
1486 # Only since VS2015
1487 args = mesonlib.listify(args)
1488 l: T.List[str] = []
1489 for a in args:
1490 l.extend(self._apply_prefix('/WHOLEARCHIVE:' + a))
1491 return l
1492
1493 def get_allow_undefined_args(self) -> T.List[str]:
1494 return []
1495
1496 def gen_vs_module_defs_args(self, defsfile: str) -> T.List[str]:
1497 # With MSVC, DLLs only export symbols that are explicitly exported,
1498 # so if a module defs file is specified, we use that to export symbols
1499 return self._apply_prefix(['/DEF:' + defsfile])
1500
1501 def get_soname_args(self, prefix: str, shlib_name: str, suffix: str,
1502 soversion: str, darwin_versions: T.Tuple[str, str]
1503 ) -> T.List[str]:
1504 return []
1505
1506 def import_library_args(self, implibname: str) -> T.List[str]:
1507 """The command to generate the import library."""
1508 return self._apply_prefix(['/IMPLIB:' + implibname])
1509
1510 def rsp_file_syntax(self) -> RSPFileSyntax:
1511 return self.rsp_syntax
1512
1513 def get_pie_args(self) -> T.List[str]:
1514 return []
1515
1516
1517 class MSVCDynamicLinker(VisualStudioLikeLinkerMixin, DynamicLinker):
1518
1519 """Microsoft's Link.exe."""
1520
1521 id = 'link'
1522
1523 def __init__(self, env: Environment, for_machine: mesonlib.MachineChoice,
1524 always_args: T.List[str], *,
1525 exelist: T.Optional[T.List[str]] = None,
1526 prefix: T.Optional[LinkerOptionStyle] = None,
1527 machine: str = 'x86', version: str = 'unknown version',
1528 direct: bool = True, rsp_syntax: RSPFileSyntax = RSPFileSyntax.MSVC):
1529 super().__init__(exelist or ['link.exe'], env, for_machine,
1530 prefix, always_args, machine=machine, version=version, direct=direct,
1531 rsp_syntax=rsp_syntax)
1532
1533 def get_always_args(self) -> T.List[str]:
1534 return self._apply_prefix(['/release']) + super().get_always_args()
1535
1536 def get_win_subsystem_args(self, value: str) -> T.List[str]:
1537 return self._apply_prefix([f'/SUBSYSTEM:{value.upper()}'])
1538
1539 def fatal_warnings(self) -> T.List[str]:
1540 return ['-WX']
1541
1542 def get_lto_args(self) -> T.List[str]:
1543 return ['/LTCG']
1544
1545
1546 class ClangClDynamicLinker(VisualStudioLikeLinkerMixin, DynamicLinker):
1547
1548 """Clang's lld-link.exe."""
1549
1550 id = 'lld-link'
1551
1552 def __init__(self, env: Environment, for_machine: mesonlib.MachineChoice,
1553 always_args: T.List[str], *,
1554 exelist: T.Optional[T.List[str]] = None,
1555 prefix: T.Optional[LinkerOptionStyle] = None,
1556 machine: str = 'x86', version: str = 'unknown version',
1557 direct: bool = True, rsp_syntax: RSPFileSyntax = RSPFileSyntax.MSVC):
1558 super().__init__(exelist or ['lld-link.exe'], env, for_machine,
1559 prefix, always_args, machine=machine, version=version, direct=direct,
1560 rsp_syntax=rsp_syntax)
1561
1562 def get_output_args(self, outputname: str) -> T.List[str]:
1563 # If we're being driven indirectly by clang just skip /MACHINE
1564 # as clang's target triple will handle the machine selection
1565 if self.machine is None:
1566 return self._apply_prefix([f"/OUT:{outputname}"])
1567
1568 return super().get_output_args(outputname)
1569
1570 def get_win_subsystem_args(self, value: str) -> T.List[str]:
1571 return self._apply_prefix([f'/SUBSYSTEM:{value.upper()}'])
1572
1573 def get_thinlto_cache_args(self, path: str) -> T.List[str]:
1574 return ["/lldltocache:" + path]
1575
1576 def fatal_warnings(self) -> T.List[str]:
1577 return ['-WX']
1578
1579
1580 class XilinkDynamicLinker(VisualStudioLikeLinkerMixin, DynamicLinker):
1581
1582 """Intel's Xilink.exe."""
1583
1584 id = 'xilink'
1585
1586 def __init__(self, env: Environment, for_machine: mesonlib.MachineChoice,
1587 always_args: T.List[str], *,
1588 exelist: T.Optional[T.List[str]] = None,
1589 prefix: T.Optional[LinkerOptionStyle] = None,
1590 machine: str = 'x86', version: str = 'unknown version',
1591 direct: bool = True):
1592 super().__init__(['xilink.exe'], env, for_machine, None, always_args, version=version)
1593
1594 def get_win_subsystem_args(self, value: str) -> T.List[str]:
1595 return self._apply_prefix([f'/SUBSYSTEM:{value.upper()}'])
1596
1597
1598 class SolarisDynamicLinker(PosixDynamicLinkerMixin, DynamicLinker):
1599
1600 """Sys-V derived linker used on Solaris and OpenSolaris."""
1601
1602 id = 'ld.solaris'
1603
1604 def get_link_whole_for(self, args: T.List[str]) -> T.List[str]:
1605 if not args:
1606 return args
1607 return self._apply_prefix('--whole-archive') + args + self._apply_prefix('--no-whole-archive')
1608
1609 def get_pie_args(self) -> T.List[str]:
1610 # Available in Solaris 11.2 and later
1611 pc, stdo, stde = mesonlib.Popen_safe(self.exelist + self._apply_prefix('-zhelp'))
1612 for line in (stdo + stde).split('\n'):
1613 if '-z type' in line:
1614 if 'pie' in line:
1615 return ['-z', 'type=pie']
1616 break
1617 return []
1618
1619 def get_asneeded_args(self) -> T.List[str]:
1620 return self._apply_prefix(['-z', 'ignore'])
1621
1622 def no_undefined_args(self) -> T.List[str]:
1623 return ['-z', 'defs']
1624
1625 def get_allow_undefined_args(self) -> T.List[str]:
1626 return ['-z', 'nodefs']
1627
1628 def fatal_warnings(self) -> T.List[str]:
1629 return ['-z', 'fatal-warnings']
1630
1631 def build_rpath_args(self, build_dir: str, from_dir: str, target: BuildTarget,
1632 extra_paths: T.Optional[T.List[str]] = None
1633 ) -> T.Tuple[T.List[str], T.Set[bytes]]:
1634 rpath_paths = target.determine_rpath_dirs()
1635 if not rpath_paths and not target.install_rpath and not target.build_rpath and not extra_paths:
1636 return ([], set())
1637 processed_rpaths = prepare_rpaths(rpath_paths, build_dir, from_dir)
1638 all_paths = mesonlib.OrderedSet([os.path.join('$ORIGIN', p) for p in processed_rpaths])
1639 rpath_dirs_to_remove: T.Set[bytes] = set()
1640 for p in all_paths:
1641 rpath_dirs_to_remove.add(p.encode('utf8'))
1642 if target.build_rpath != '':
1643 all_paths.add(target.build_rpath)
1644 for p in target.build_rpath.split(':'):
1645 rpath_dirs_to_remove.add(p.encode('utf8'))
1646 if extra_paths:
1647 all_paths.update(extra_paths)
1648
1649 # In order to avoid relinking for RPATH removal, the binary needs to contain just
1650 # enough space in the ELF header to hold the final installation RPATH.
1651 paths = ':'.join(all_paths)
1652 paths_length = len(paths.encode('utf-8'))
1653 install_rpath_length = len(target.install_rpath.encode('utf-8'))
1654 if paths_length < install_rpath_length:
1655 padding = 'X' * (install_rpath_length - paths_length)
1656 if not paths:
1657 paths = padding
1658 else:
1659 paths = paths + ':' + padding
1660 return (self._apply_prefix(['-rpath', paths]), rpath_dirs_to_remove)
1661
1662 def get_soname_args(self, prefix: str, shlib_name: str, suffix: str,
1663 soversion: str, darwin_versions: T.Tuple[str, str]
1664 ) -> T.List[str]:
1665 sostr = '' if soversion is None else '.' + soversion
1666 return self._apply_prefix(['-soname', f'{prefix}{shlib_name}.{suffix}{sostr}'])
1667
1668
1669 class AIXDynamicLinker(PosixDynamicLinkerMixin, DynamicLinker):
1670
1671 """Sys-V derived linker used on AIX"""
1672
1673 id = 'ld.aix'
1674
1675 def get_always_args(self) -> T.List[str]:
1676 return self._apply_prefix(['-bnoipath', '-bbigtoc']) + super().get_always_args()
1677
1678 def no_undefined_args(self) -> T.List[str]:
1679 return self._apply_prefix(['-bernotok'])
1680
1681 def get_allow_undefined_args(self) -> T.List[str]:
1682 return self._apply_prefix(['-berok'])
1683
1684 def get_archive_name(self, filename: str) -> str:
1685 # In AIX we allow the shared library name to have the lt_version and so_version.
1686 # But the archive name must just be .a .
1687 # For Example shared object can have the name libgio.so.0.7200.1 but the archive
1688 # must have the name libgio.a having libgio.a (libgio.so.0.7200.1) in the
1689 # archive. This regular expression is to do the same.
1690 filename = re.sub('[.][a]([.]?([0-9]+))*([.]?([a-z]+))*', '.a', filename.replace('.so', '.a'))
1691 return filename
1692
1693 def get_command_to_archive_shlib(self) -> T.List[str]:
1694 # Archive shared library object and remove the shared library object,
1695 # since it already exists in the archive.
1696 command = ['ar', '-X32_64', '-r', '-s', '-v', '$out', '$in', '&&', 'rm', '-f', '$in']
1697 return command
1698
1699 def get_link_whole_for(self, args: T.List[str]) -> T.List[str]:
1700 # AIX's linker always links the whole archive: "The ld command
1701 # processes all input files in the same manner, whether they are
1702 # archives or not."
1703 return args
1704
1705 def build_rpath_args(self, build_dir: str, from_dir: str, target: BuildTarget,
1706 extra_paths: T.Optional[T.List[str]] = None
1707 ) -> T.Tuple[T.List[str], T.Set[bytes]]:
1708 # Extract rpath information from target
1709 rpath_paths = target.determine_rpath_dirs()
1710 install_rpath = target.install_rpath
1711 build_rpath = target.build_rpath
1712
1713 all_paths: mesonlib.OrderedSet[str] = mesonlib.OrderedSet()
1714 rpath_dirs_to_remove: T.Set[bytes] = set()
1715 # install_rpath first, followed by other paths, and the system path last
1716 if install_rpath != '':
1717 all_paths.add(install_rpath)
1718 if build_rpath != '':
1719 all_paths.add(build_rpath)
1720 for p in build_rpath.split(':'):
1721 rpath_dirs_to_remove.add(p.encode('utf8'))
1722 for p in rpath_paths:
1723 path = os.path.join(build_dir, p)
1724 all_paths.add(path)
1725 rpath_dirs_to_remove.add(path.encode('utf8'))
1726 # We should consider allowing the $LIBPATH environment variable
1727 # to override sys_path.
1728 sys_path = self.environment.get_compiler_system_lib_dirs(self.for_machine)
1729 if len(sys_path) == 0:
1730 # get_compiler_system_lib_dirs doesn't support our compiler.
1731 # Use the default system library path
1732 all_paths.update(['/usr/lib', '/lib'])
1733 else:
1734 # Include the compiler's default library paths, but filter out paths that don't exist
1735 for p in sys_path:
1736 if os.path.isdir(p):
1737 all_paths.add(p)
1738 if extra_paths:
1739 all_paths.update(extra_paths)
1740 return (self._apply_prefix('-blibpath:' + ':'.join(all_paths)), rpath_dirs_to_remove)
1741
1742 def thread_flags(self) -> T.List[str]:
1743 return ['-pthread']
1744
1745
1746 class OptlinkDynamicLinker(VisualStudioLikeLinkerMixin, DynamicLinker):
1747
1748 """Digital Mars dynamic linker for windows."""
1749
1750 id = 'optlink'
1751
1752 def __init__(self, exelist: T.List[str], env: Environment, for_machine: mesonlib.MachineChoice,
1753 *, version: str = 'unknown version'):
1754 # Use optlink instead of link so we don't interfere with other link.exe
1755 # implementations.
1756 super().__init__(exelist, env, for_machine, None, [], version=version)
1757
1758 def get_allow_undefined_args(self) -> T.List[str]:
1759 return []
1760
1761 def get_debugfile_args(self, targetfile: str) -> T.List[str]:
1762 # Optlink does not generate pdb files.
1763 return []
1764
1765 def get_always_args(self) -> T.List[str]:
1766 return []
1767
1768
1769 class CudaLinker(PosixDynamicLinkerMixin, DynamicLinker):
1770 """Cuda linker (nvlink)"""
1771
1772 id = 'nvlink'
1773
1774 @staticmethod
1775 def parse_version() -> str:
1776 version_cmd = ['nvlink', '--version']
1777 try:
1778 _, out, _ = mesonlib.Popen_safe(version_cmd)
1779 except OSError:
1780 return 'unknown version'
1781 # Output example:
1782 # nvlink: NVIDIA (R) Cuda linker
1783 # Copyright (c) 2005-2018 NVIDIA Corporation
1784 # Built on Sun_Sep_30_21:09:22_CDT_2018
1785 # Cuda compilation tools, release 10.0, V10.0.166
1786 # we need the most verbose version output. Luckily starting with V
1787 return out.strip().rsplit('V', maxsplit=1)[-1].split(maxsplit=1)[0]
1788
1789 def get_accepts_rsp(self) -> bool:
1790 # nvcc does not support response files
1791 return False
1792
1793 def get_lib_prefix(self) -> str:
1794 # nvcc doesn't recognize Meson's default .a extension for static libraries on
1795 # Windows and passes it to cl as an object file, resulting in 'warning D9024 :
1796 # unrecognized source file type 'xxx.a', object file assumed'.
1797 #
1798 # nvcc's --library= option doesn't help: it takes the library name without the
1799 # extension and assumes that the extension on Windows is .lib; prefixing the
1800 # library with -Xlinker= seems to work.
1801 #
1802 # On Linux, we have to use rely on -Xlinker= too, since nvcc/nvlink chokes on
1803 # versioned shared libraries:
1804 #
1805 # nvcc fatal : Don't know what to do with 'subprojects/foo/libbar.so.0.1.2'
1806 #
1807 from ..compilers.cuda import CudaCompiler
1808 return CudaCompiler.LINKER_OPTION_STYLE.prefix
1809
1810 def fatal_warnings(self) -> T.List[str]:
1811 return ['--warning-as-error']
1812
1813 def get_allow_undefined_args(self) -> T.List[str]:
1814 return []
1815
1816 def get_soname_args(self, prefix: str, shlib_name: str, suffix: str,
1817 soversion: str, darwin_versions: T.Tuple[str, str]
1818 ) -> T.List[str]:
1819 return []
1820
1821
1822 class MetrowerksLinker(DynamicLinker):
1823
1824 def __init__(self, exelist: T.List[str], env: Environment, for_machine: mesonlib.MachineChoice,
1825 *, version: str = 'unknown version'):
1826 super().__init__(exelist, env, for_machine, None, [],
1827 version=version)
1828
1829 def fatal_warnings(self) -> T.List[str]:
1830 return ['-w', 'error']
1831
1832 def get_allow_undefined_args(self) -> T.List[str]:
1833 return []
1834
1835 def get_accepts_rsp(self) -> bool:
1836 return True
1837
1838 def get_linker_always_args(self) -> T.List[str]:
1839 return []
1840
1841 def get_output_args(self, outputname: str) -> T.List[str]:
1842 return ['-o', outputname]
1843
1844 def get_search_args(self, dirname: str) -> T.List[str]:
1845 return self._apply_prefix('-L' + dirname)
1846
1847 def invoked_by_compiler(self) -> bool:
1848 return False
1849
1850 def get_soname_args(self, prefix: str, shlib_name: str, suffix: str,
1851 soversion: str, darwin_versions: T.Tuple[str, str]
1852 ) -> T.List[str]:
1853 raise MesonException(f'{self.id} does not support shared libraries.')
1854
1855
1856 class MetrowerksLinkerARM(MetrowerksLinker):
1857 id = 'mwldarm'
1858
1859
1860 class MetrowerksLinkerEmbeddedPowerPC(MetrowerksLinker):
1861 id = 'mwldeppc'
1862
1863 class TaskingLinker(DynamicLinker):
1864 id = 'tasking'
1865
1866 _OPTIMIZATION_ARGS: T.Dict[str, T.List[str]] = {
1867 'plain': [],
1868 '0': ['-O0'],
1869 'g': ['-O1'], # There is no debug specific level, O1 is recommended by the compiler
1870 '1': ['-O1'],
1871 '2': ['-O2'],
1872 '3': ['-O2'], # There is no 3rd level optimization for the linker
1873 's': ['-Os'],
1874 }
1875
1876 def __init__(self, exelist: T.List[str], env: Environment, for_machine: mesonlib.MachineChoice,
1877 *, version: str = 'unknown version'):
1878 super().__init__(exelist, env, for_machine, None, [],
1879 version=version)
1880
1881 def get_accepts_rsp(self) -> bool:
1882 return True
1883
1884 def get_lib_prefix(self) -> str:
1885 return ""
1886
1887 def get_allow_undefined_args(self) -> T.List[str]:
1888 return []
1889
1890 def invoked_by_compiler(self) -> bool:
1891 return True
1892
1893 def get_search_args(self, dirname: str) -> T.List[str]:
1894 return self._apply_prefix('-L' + dirname)
1895
1896 def get_output_args(self, outputname: str) -> T.List[str]:
1897 return ['-o', outputname]
1898
1899 def get_lto_args(self) -> T.List[str]:
1900 return ['--mil-link']
1901
1902 def rsp_file_syntax(self) -> RSPFileSyntax:
1903 return RSPFileSyntax.TASKING
1904
1905 def fatal_warnings(self) -> T.List[str]:
1906 """Arguments to make all warnings errors."""
1907 return self._apply_prefix('--warnings-as-errors')
1908
1909 def get_link_whole_for(self, args: T.List[str]) -> T.List[str]:
1910 args = mesonlib.listify(args)
1911 l: T.List[str] = []
1912 for a in args:
1913 l.extend(self._apply_prefix('-Wl--whole-archive=' + a))
1914 return l
1915
1916
1917 class OS2DynamicLinker(PosixDynamicLinkerMixin, DynamicLinker):
1918 """ld and emxomfld"""
1919
1920 def get_allow_undefined_args(self) -> T.List[str]:
1921 return []
1922
1923 def thread_flags(self) -> T.List[str]:
1924 return ['-lpthread']
1925
1926 def get_std_shared_lib_args(self) -> T.List[str]:
1927 return ['-Zdll']
1928
1929 def get_soname_args(self, prefix: str, shlib_name: str, suffix: str,
1930 soversion: str, darwin_versions: T.Tuple[str, str]
1931 ) -> T.List[str]:
1932 return []
1933
1934 def get_always_args(self) -> T.List[str]:
1935 return ['-Zomf']
1936
1937
1938 class OS2AoutDynamicLinker(OS2DynamicLinker):
1939 id = 'ld.os2'
1940
1941
1942 class OS2OmfDynamicLinker(OS2DynamicLinker):
1943 id = 'emxomfld'