From 137a98cba1f0c4382c0a314fe0123f152649890b Mon Sep 17 00:00:00 2001 From: gerioldman Date: Wed, 28 Aug 2024 02:57:56 +0200 Subject: [PATCH] First draft version of Tasking MIL linking with b_lto and prelinking --- docs/markdown/Builtin-options.md | 1 - docs/markdown/Reference-tables.md | 12 +---- mesonbuild/backend/backends.py | 21 ++++++-- mesonbuild/backend/ninjabackend.py | 71 ++++++++------------------ mesonbuild/backend/vs2010backend.py | 4 +- mesonbuild/build.py | 7 ++- mesonbuild/compilers/c.py | 19 ++----- mesonbuild/compilers/compilers.py | 16 +++--- mesonbuild/compilers/detect.py | 30 ++--------- mesonbuild/compilers/mixins/apple.py | 4 +- mesonbuild/compilers/mixins/elbrus.py | 4 +- mesonbuild/compilers/mixins/gnu.py | 4 +- mesonbuild/compilers/mixins/tasking.py | 20 ++++++-- mesonbuild/linkers/linkers.py | 35 ++----------- 14 files changed, 85 insertions(+), 163 deletions(-) diff --git a/docs/markdown/Builtin-options.md b/docs/markdown/Builtin-options.md index 8d1772a43d20..f16a46ffebea 100644 --- a/docs/markdown/Builtin-options.md +++ b/docs/markdown/Builtin-options.md @@ -223,7 +223,6 @@ available on all platforms or with all compilers: | b_staticpic | true | true, false | Build static libraries as position independent | | b_pie | false | true, false | Build position-independent executables (since 0.49.0) | | b_vscrt | from_buildtype | none, md, mdd, mt, mtd, from_buildtype, static_from_buildtype | VS runtime library to use (since 0.48.0) (static_from_buildtype since 0.56.0) | -| b_tasking_mil_link | false | true, false | Use MIL linking for the TASKING VX-tools compiler family (since 1.4.0) | The value of `b_sanitize` can be one of: `none`, `address`, `thread`, `undefined`, `memory`, `leak`, `address,undefined`, but note that some diff --git a/docs/markdown/Reference-tables.md b/docs/markdown/Reference-tables.md index 9db23a0c0311..5b27e3de52ac 100644 --- a/docs/markdown/Reference-tables.md +++ b/docs/markdown/Reference-tables.md @@ -49,11 +49,7 @@ These are return values of the `get_id` (Compiler family) and | armasm | Microsoft Macro Assembler for ARM and AARCH64 (Since 0.64.0) | | | mwasmarm | Metrowerks Assembler for Embedded ARM | | | mwasmeppc | Metrowerks Assembler for Embedded PowerPC | | -| cctc | TASKING VX-toolset for TriCore compiler | | -| ccarm | TASKING VX-toolset for ARM compiler | | -| cc51 | TASKING VX-toolset for 8051 compiler | | -| ccmcs | TASKING VX-toolset for MCS compiler | | -| ccpcp | TASKING VX-toolset for PCP compiler | | +| tasking | TASKING VX-toolset | | ## Linker ids @@ -85,11 +81,7 @@ These are return values of the `get_linker_id` method in a compiler object. | ccomp | CompCert used as the linker driver | | mwldarm | The Metrowerks Linker with the ARM interface, used with mwccarm only | | mwldeppc | The Metrowerks Linker with the PowerPC interface, used with mwcceppc only | -| ltc | TASKING VX-toolset for TriCore linker | -| lkarm | TASKING VX-toolset for ARM linker | -| lk51 | TASKING VX-toolset for 8051 linker | -| lmsc | TASKING VX-toolset for MCS linker | -| lpcp | TASKING VX-toolset for PCP linker | +| tasking | TASKING VX-toolset | For languages that don't have separate dynamic linkers such as C# and Java, the `get_linker_id` will return the compiler name. diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index fb912b1d83d0..18caf7bbe8a7 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -24,10 +24,11 @@ from .. import programs from .. import mesonlib from .. import mlog -from ..compilers import LANGUAGES_USING_LDFLAGS, detect +from ..compilers import LANGUAGES_USING_LDFLAGS, detect, lang_suffixes from ..mesonlib import ( File, MachineChoice, MesonException, OrderedSet, - ExecutableSerialisation, classify_unity_sources, + ExecutableSerialisation, EnvironmentException, + classify_unity_sources, get_compiler_for_source ) from ..options import OptionKey @@ -837,7 +838,7 @@ def canonicalize_filename(fname: str) -> str: fname = fname.replace(ch, '_') return hashed + fname - def object_filename_from_source(self, target: build.BuildTarget, source: 'FileOrString', targetdir: T.Optional[str] = None) -> str: + def object_filename_from_source(self, target: build.BuildTarget, compiler: Compiler, source: 'FileOrString', targetdir: T.Optional[str] = None) -> str: assert isinstance(source, mesonlib.File) if isinstance(target, build.CompileTarget): return target.sources_map[source] @@ -868,7 +869,16 @@ def object_filename_from_source(self, target: build.BuildTarget, source: 'FileOr gen_source = os.path.relpath(os.path.join(build_dir, rel_src), os.path.join(self.environment.get_source_dir(), target.get_subdir())) machine = self.environment.machines[target.for_machine] - ret = self.canonicalize_filename(gen_source) + '.' + machine.get_object_suffix() + object_suffix = machine.get_object_suffix() + # For the TASKING compiler, in case of LTO or prelinking the object suffix has to be .mil + if compiler.get_id() == 'tasking': + if target.get_option(OptionKey('b_lto')) or (isinstance(target, build.StaticLibrary) and target.prelink): + if not source.rsplit('.', 1)[1] in lang_suffixes['c']: + if isinstance(target, build.StaticLibrary) and not target.prelink: + raise EnvironmentException('Tried using MIL linking for a static library with a assembly file. This can only be done if the static library is prelinked or disable \'b_lto\'.') + else: + object_suffix = 'mil' + ret = self.canonicalize_filename(gen_source) + '.' + object_suffix if targetdir is not None: return os.path.join(targetdir, ret) return ret @@ -924,7 +934,8 @@ def _determine_ext_objs(self, extobj: 'build.ExtractedObjects', proj_dir_to_buil sources.append(_src) for osrc in sources: - objname = self.object_filename_from_source(extobj.target, osrc, targetdir) + compiler = get_compiler_for_source(extobj.target.compilers.values(), osrc) + objname = self.object_filename_from_source(extobj.target, compiler, osrc, targetdir) objpath = os.path.join(proj_dir_to_build_root, objname) result.append(objpath) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 991f96edc81f..7125bbdf4e74 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -734,8 +734,7 @@ def generate_compdb(self) -> None: rules += [f"{rule}{ext}" for rule in [self.compiler_to_pch_rule_name(compiler)] for ext in ['', '_RSP']] # Add custom MIL link rules to get the files compiled by the TASKING compiler family to MIL files included in the database - key = OptionKey('b_tasking_mil_link') - if key in compiler.base_options: + if compiler.get_id() == 'tasking': rule = self.get_compiler_rule_name('tasking_mil_compile', compiler.for_machine) rules.append(rule) rules.append(f'{rule}_RSP') @@ -1085,19 +1084,11 @@ def generate_target(self, target) -> None: # Skip the link stage for this special type of target return linker, stdlib_args = self.determine_linker_and_stdlib_args(target) - # For prelinking and TASKING mil linking there needs to be an additional link target and the object list is modified + if not isinstance(target, build.StaticLibrary): final_obj_list = obj_list elif target.prelink: final_obj_list = self.generate_prelink(target, obj_list) - elif 'c' in target.compilers: - key = OptionKey('b_tasking_mil_link') - if key not in target.get_options() or key not in target.compilers['c'].base_options: - final_obj_list = obj_list - elif target.get_option(key): - final_obj_list = self.generate_mil_link(target, obj_list) - else: - final_obj_list = obj_list else: final_obj_list = obj_list elem = self.generate_link(target, outname, final_obj_list, linker, pch_objects, stdlib_args=stdlib_args) @@ -2621,9 +2612,8 @@ def generate_compile_rules(self) -> None: for langname, compiler in clist.items(): if compiler.get_id() == 'clang': self.generate_llvm_ir_compile_rule(compiler) - if OptionKey('b_tasking_mil_link') in compiler.base_options: + if compiler.get_id() == 'tasking': self.generate_tasking_mil_compile_rules(compiler) - self.generate_tasking_mil_link_rules(compiler) self.generate_compile_rule_for(langname, compiler) self.generate_pch_rule_for(langname, compiler) for mode in compiler.get_modes(): @@ -3063,12 +3053,7 @@ def generate_single_compile(self, target: build.BuildTarget, src, raise AssertionError(f'BUG: broken generated source file handling for {src!r}') else: raise InvalidArguments(f'Invalid source type: {src!r}') - obj_basename = self.object_filename_from_source(target, src) - # If mil linking is enabled for the target, then compilation output has to be MIL files instead of object files - if compiler.get_language() == 'c': - key = OptionKey('b_tasking_mil_link') - if key in compiler.base_options and target.get_option(key) and src.rsplit('.', 1)[1] in compilers.lang_suffixes['c']: - obj_basename = f'{os.path.splitext(obj_basename)[0]}.mil' + obj_basename = self.object_filename_from_source(target, compiler, src) rel_obj = os.path.join(self.get_target_private_dir(target), obj_basename) dep_file = compiler.depfile_for_object(rel_obj) @@ -3092,9 +3077,12 @@ def generate_single_compile(self, target: build.BuildTarget, src, # If TASKING compiler family is used and MIL linking is enabled for the target, # then compilation rule name is a special one to output MIL files # instead of object files for .c files - key = OptionKey('b_tasking_mil_link') - if key in compiler.base_options and target.get_option(key) and src.rsplit('.', 1)[1] in compilers.lang_suffixes['c']: - compiler_name = self.get_compiler_rule_name('tasking_mil_compile', compiler.for_machine) + key = OptionKey('b_lto') + if compiler.get_id() == 'tasking': + if ((isinstance(target, build.StaticLibrary) and target.prelink) or target.get_option(key)) and src.rsplit('.', 1)[1] in compilers.lang_suffixes['c']: + compiler_name = self.get_compiler_rule_name('tasking_mil_compile', compiler.for_machine) + else: + compiler_name = self.compiler_to_rule_name(compiler) else: compiler_name = self.compiler_to_rule_name(compiler) extra_deps = [] @@ -3473,36 +3461,19 @@ def generate_prelink(self, target, obj_list): prelinker = target.get_prelinker() cmd = prelinker.exelist[:] - cmd += prelinker.get_prelink_args(prelink_name, obj_list) + obj_list, args = prelinker.get_prelink_args(prelink_name, obj_list) + cmd += args + if prelinker.get_prelink_append_compile_args(): + compile_args = self._generate_single_compile_base_args(target, prelinker) + compile_args += self._generate_single_compile_target_args(target, prelinker) + compile_args = compile_args.compiler.compiler_args(compile_args) + cmd += compile_args.to_native() cmd = self.replace_paths(target, cmd) elem.add_item('COMMAND', cmd) elem.add_item('description', f'Prelinking {prelink_name}') self.add_build(elem) - return [prelink_name] - - def generate_mil_link(self, target: build.StaticLibrary, obj_list: T.List[str]) -> T.List[str]: - assert isinstance(target, build.StaticLibrary) - - mil_linked_name = os.path.join(self.get_target_private_dir(target), target.name + '-mil_link.o') - mil_link_list = [] - obj_file_list = [] - for obj in obj_list: - if obj.endswith('.mil'): - mil_link_list.append(obj) - else: - obj_file_list.append(obj) - obj_file_list.append(mil_linked_name) - compiler = get_compiler_for_source(target.compilers.values(), mil_link_list[0][:-3] + '.c') - commands = self._generate_single_compile_base_args(target, compiler) - commands += self._generate_single_compile_target_args(target, compiler) - commands = commands.compiler.compiler_args(commands) - - elem = NinjaBuildElement(self.all_outputs, [mil_linked_name], self.get_compiler_rule_name('tasking_mil_link', compiler.for_machine), mil_link_list) - elem.add_item('ARGS', commands) - self.add_build(elem) - - return obj_file_list + return obj_list def generate_link(self, target: build.BuildTarget, outname, obj_list, linker: T.Union['Compiler', 'StaticLinker'], extra_args=None, stdlib_args=None): extra_args = extra_args if extra_args is not None else [] @@ -3535,9 +3506,6 @@ def generate_link(self, target: build.BuildTarget, outname, obj_list, linker: T. linker, isinstance(target, build.SharedModule), self.environment.get_build_dir()) - # Add --mil-link if the option is enabled - if isinstance(target, build.Executable) and 'c' in target.compilers and OptionKey('b_tasking_mil_link') in target.get_options(): - commands += target.compilers['c'].get_tasking_mil_link_args(target.get_option(OptionKey('b_tasking_mil_link'))) # Add -nostdlib if needed; can't be overridden commands += self.get_no_stdlib_link_args(target, linker) # Add things like /NOLOGO; usually can't be overridden @@ -3647,6 +3615,9 @@ def generate_link(self, target: build.BuildTarget, outname, obj_list, linker: T. for t in target.link_depends]) elem = NinjaBuildElement(self.all_outputs, outname, linker_rule, obj_list, implicit_outs=implicit_outs) elem.add_dep(dep_targets + custom_target_libraries) + if linker.get_id() == 'tasking': + if len([x for x in dep_targets + custom_target_libraries if x.endswith('.ma')]) > 0 and not target.get_option(OptionKey('b_lto')): + raise MesonException(f'Tried to link the target named \'{target.name}\' with a MIL archive without LTO enabled! This causes the compiler to ignore the archive.') # Compiler args must be included in TI C28x linker commands. if linker.get_id() in {'c2000', 'c6000', 'ti'}: diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py index 08a19c659e44..0fb30a7b91b9 100644 --- a/mesonbuild/backend/vs2010backend.py +++ b/mesonbuild/backend/vs2010backend.py @@ -1725,7 +1725,7 @@ def path_normalize_add(path, lis): self.add_preprocessor_defines(lang, inc_cl, file_defines) self.add_include_dirs(lang, inc_cl, file_inc_dirs) ET.SubElement(inc_cl, 'ObjectFileName').text = "$(IntDir)" + \ - self.object_filename_from_source(target, s) + self.object_filename_from_source(target, compiler, s) for s in gen_src: if path_normalize_add(s, previous_sources): inc_cl = ET.SubElement(inc_src, 'CLCompile', Include=s) @@ -1739,7 +1739,7 @@ def path_normalize_add(path, lis): self.add_include_dirs(lang, inc_cl, file_inc_dirs) s = File.from_built_file(target.get_subdir(), s) ET.SubElement(inc_cl, 'ObjectFileName').text = "$(IntDir)" + \ - self.object_filename_from_source(target, s) + self.object_filename_from_source(target, compiler, s) for lang, headers in pch_sources.items(): impl = headers[1] if impl and path_normalize_add(impl, previous_sources): diff --git a/mesonbuild/build.py b/mesonbuild/build.py index cf92fc48faa2..ee857a4cfcbd 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -2018,7 +2018,7 @@ def post_init(self) -> None: elif ('c' in self.compilers and self.compilers['c'].get_id() in {'mwccarm', 'mwcceppc'} or 'cpp' in self.compilers and self.compilers['cpp'].get_id() in {'mwccarm', 'mwcceppc'}): self.suffix = 'nef' - elif ('c' in self.compilers and self.compilers['c'].get_id() in {'cctc', 'ccarm', 'cc51', 'ccmcs', 'ccpcp'}): + elif ('c' in self.compilers and self.compilers['c'].get_id() == 'tasking'): self.suffix = 'elf' else: self.suffix = machine.get_exe_suffix() @@ -2175,7 +2175,10 @@ def post_init(self) -> None: elif self.rust_crate_type == 'staticlib': self.suffix = 'a' else: - self.suffix = 'a' + if 'c' in self.compilers and self.compilers['c'].get_id() == 'tasking': + self.suffix = 'ma' if self.options.get_value('b_lto') and not self.prelink else 'a' + else: + self.suffix = 'a' self.filename = self.prefix + self.name + '.' + self.suffix self.outputs[0] = self.filename diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py index b72c5b5d2eb5..c75120fee4d0 100644 --- a/mesonbuild/compilers/c.py +++ b/mesonbuild/compilers/c.py @@ -832,7 +832,9 @@ def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str] args.append('-lang ' + std) return args -class _TaskingCCompiler(TaskingCompiler, CCompiler): +class TaskingCCompiler(TaskingCompiler, CCompiler): + id = 'tasking' + def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, info: 'MachineInfo', linker: T.Optional['DynamicLinker'] = None, @@ -840,18 +842,3 @@ def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_ CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, info, linker=linker, full_version=full_version) TaskingCompiler.__init__(self) - -class TaskingTricoreCCompiler(_TaskingCCompiler): - id = 'cctc' - -class TaskingArmCCompiler(_TaskingCCompiler): - id = 'ccarm' - -class Tasking8051CCompiler(_TaskingCCompiler): - id = 'cc51' - -class TaskingMCSCCompiler(_TaskingCCompiler): - id = 'ccmcs' - -class TaskingPCPCCompiler(_TaskingCCompiler): - id = 'ccpcp' diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index f8d4ac439b55..3dfa0ff2770f 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -251,7 +251,6 @@ def init_option(self, name: OptionKey) -> options._U: OptionKey('b_bitcode'): BaseOption(options.UserBooleanOption, 'Generate and embed bitcode (only macOS/iOS/tvOS)', False), OptionKey('b_vscrt'): BaseOption(options.UserComboOption, 'VS run-time library type to use.', 'from_buildtype', choices=MSCRT_VALS + ['from_buildtype', 'static_from_buildtype']), - OptionKey('b_tasking_mil_link'): BaseOption(options.UserBooleanOption, 'Use TASKING compiler families MIL linking feature', False), } base_options = {key: base_opt.init_option(key) for key, base_opt in BASE_OPTIONS.items()} @@ -433,8 +432,8 @@ class CompileResult(HoldableObject): output_name: T.Optional[str] = field(default=None, init=False) cached: bool = field(default=False, init=False) - class Compiler(HoldableObject, metaclass=abc.ABCMeta): + # Libraries to ignore in find_library() since they are provided by the # compiler or the C library. Currently only used for MSVC. ignore_libs: T.List[str] = [] @@ -1328,9 +1327,13 @@ def get_feature_args(self, kwargs: DFeatures, build_to_src: str) -> T.List[str]: # TODO: using a TypeDict here would improve this raise EnvironmentException(f'{self.id} does not implement get_feature_args') - def get_prelink_args(self, prelink_name: str, obj_list: T.List[str]) -> T.List[str]: + def get_prelink_args(self, prelink_name: str, obj_list: T.List[str]) -> T.Tuple[T.List[str], T.List[str]]: raise EnvironmentException(f'{self.id} does not know how to do prelinking.') + def get_prelink_append_compile_args(self) -> bool: + """Controls whether compile args have to be used for prelinking or not""" + return False + def rsp_file_syntax(self) -> 'RSPFileSyntax': """The format of the RSP file that this compiler supports. @@ -1354,13 +1357,6 @@ def get_preprocessor(self) -> Compiler: def form_compileropt_key(self, basename: str) -> OptionKey: return OptionKey(f'{self.language}_{basename}', machine=self.for_machine) - def get_tasking_mil_link_args(self, option_enabled: bool) -> T.List[str]: - """ - Argument for enabling TASKING's MIL link feature, - for most compilers, this will return nothing. - """ - return [] - def get_global_options(lang: str, comp: T.Type[Compiler], for_machine: MachineChoice, diff --git a/mesonbuild/compilers/detect.py b/mesonbuild/compilers/detect.py index a528acbf3fbb..5bc14350e4ee 100644 --- a/mesonbuild/compilers/detect.py +++ b/mesonbuild/compilers/detect.py @@ -241,16 +241,7 @@ def detect_static_linker(env: 'Environment', compiler: Compiler) -> StaticLinker else: return linkers.MetrowerksStaticLinkerEmbeddedPowerPC(linker) if 'TASKING VX-toolset' in err: - if 'TriCore' in err: - return linkers.TaskingTricoreStaticLinker(linker) - if 'ARM' in err: - return linkers.TaskingARMStaticLinker(linker) - if '8051' in err: - return linkers.Tasking8051StaticLinker(linker) - if 'PCP' in err: - return linkers.TaskingPCPStaticLinker(linker) - else: - return linkers.TaskingMCSStaticLinker(linker) + return linkers.TaskingStaticLinker(linker) if p.returncode == 0: return linkers.ArLinker(compiler.for_machine, linker) if p.returncode == 1 and err.startswith('usage'): # OSX @@ -617,23 +608,8 @@ def sanitize(p: T.Optional[str]) -> T.Optional[str]: ccache, compiler, compiler_version, for_machine, is_cross, info, full_version=full_version, linker=linker) if 'TASKING VX-toolset' in err: - if 'TriCore' in err or 'AURIX Development Studio' in err: - cls = c.TaskingTricoreCCompiler - lnk = linkers.TaskingTricoreLinker - elif 'ARM' in err: - cls = c.TaskingArmCCompiler - lnk = linkers.TaskingARMLinker - elif '8051' in err: - cls = c.Tasking8051CCompiler - lnk = linkers.Tasking8051Linker - elif 'PCP' in err: - cls = c.TaskingPCPCCompiler - lnk = linkers.TaskingPCPLinker - elif 'MCS' in err: - cls = c.TaskingMCSCCompiler - lnk = linkers.TaskingMCSLinker - else: - raise EnvironmentException('Failed to detect linker for TASKING VX-toolset compiler. Please update your cross file(s).') + cls = c.TaskingCCompiler + lnk = linkers.TaskingLinker tasking_ver_match = re.search(r'v([0-9]+)\.([0-9]+)r([0-9]+) Build ([0-9]+)', err) assert tasking_ver_match is not None, 'for mypy' diff --git a/mesonbuild/compilers/mixins/apple.py b/mesonbuild/compilers/mixins/apple.py index fc93d38a5673..6ec9239522fe 100644 --- a/mesonbuild/compilers/mixins/apple.py +++ b/mesonbuild/compilers/mixins/apple.py @@ -56,6 +56,6 @@ def openmp_link_flags(self, env: Environment) -> T.List[str]: raise MesonException("Couldn't find libomp") return self.__BASE_OMP_FLAGS + link - def get_prelink_args(self, prelink_name: str, obj_list: T.List[str]) -> T.List[str]: + def get_prelink_args(self, prelink_name: str, obj_list: T.List[str]) -> T.Tuple[T.List[str], T.List[str]]: # The objects are prelinked through the compiler, which injects -lSystem - return ['-nostdlib', '-r', '-o', prelink_name] + obj_list + return [prelink_name], ['-nostdlib', '-r', '-o', prelink_name] + obj_list diff --git a/mesonbuild/compilers/mixins/elbrus.py b/mesonbuild/compilers/mixins/elbrus.py index 66f419cf02d8..5818d8dee0b5 100644 --- a/mesonbuild/compilers/mixins/elbrus.py +++ b/mesonbuild/compilers/mixins/elbrus.py @@ -76,8 +76,8 @@ def get_default_include_dirs(self) -> T.List[str]: def get_optimization_args(self, optimization_level: str) -> T.List[str]: return gnu_optimization_args[optimization_level] - def get_prelink_args(self, prelink_name: str, obj_list: T.List[str]) -> T.List[str]: - return ['-r', '-nodefaultlibs', '-nostartfiles', '-o', prelink_name] + obj_list + def get_prelink_args(self, prelink_name: str, obj_list: T.List[str]) -> T.Tuple[T.List[str], T.List[str]]: + return [prelink_name], ['-r', '-nodefaultlibs', '-nostartfiles', '-o', prelink_name] + obj_list def get_pch_suffix(self) -> str: # Actually it's not supported for now, but probably will be supported in future diff --git a/mesonbuild/compilers/mixins/gnu.py b/mesonbuild/compilers/mixins/gnu.py index 976fa78714c6..66b01ef512e1 100644 --- a/mesonbuild/compilers/mixins/gnu.py +++ b/mesonbuild/compilers/mixins/gnu.py @@ -609,8 +609,8 @@ def get_has_func_attribute_extra_args(self, name: str) -> T.List[str]: # error. return ['-Werror=attributes'] - def get_prelink_args(self, prelink_name: str, obj_list: T.List[str]) -> T.List[str]: - return ['-r', '-o', prelink_name] + obj_list + def get_prelink_args(self, prelink_name: str, obj_list: T.List[str]) -> T.Tuple[T.List[str], T.List[str]]: + return [prelink_name], ['-r', '-o', prelink_name] + obj_list def get_lto_compile_args(self, *, threads: int = 0, mode: str = 'default') -> T.List[str]: if threads == 0: diff --git a/mesonbuild/compilers/mixins/tasking.py b/mesonbuild/compilers/mixins/tasking.py index 7675dbc75329..082cff073908 100644 --- a/mesonbuild/compilers/mixins/tasking.py +++ b/mesonbuild/compilers/mixins/tasking.py @@ -56,7 +56,7 @@ def __init__(self) -> None: self.base_options = { OptionKey(o) for o in [ - 'b_tasking_mil_link', + 'b_lto', 'b_staticpic', 'b_ndebug' ] @@ -112,6 +112,21 @@ def get_optimization_args(self, optimization_level: str) -> T.List[str]: def get_no_optimization_args(self) -> T.List[str]: return ['-O0'] + def get_prelink_args(self, prelink_name: str, obj_list: T.List[str]) -> T.Tuple[T.List[str], T.List[str]]: + mil_link_list = [] + obj_file_list = [] + for obj in obj_list: + if obj.endswith('.mil'): + mil_link_list.append(obj) + else: + obj_file_list.append(obj) + obj_file_list.append(prelink_name) + + return obj_file_list, ['--mil-link', '-o', prelink_name, '-c'] + mil_link_list + + def get_prelink_append_compile_args(self) -> bool: + return True + def compute_parameters_with_absolute_paths(self, parameter_list: T.List[str], build_dir: str) -> T.List[str]: for idx, i in enumerate(parameter_list): if i[:2] == '-I' or i[:2] == '-L': @@ -119,8 +134,5 @@ def compute_parameters_with_absolute_paths(self, parameter_list: T.List[str], bu return parameter_list - def get_tasking_mil_link_args(self, option_enabled: bool) -> T.List[str]: - return ['--mil-link'] if option_enabled else [] - def get_preprocess_only_args(self) -> T.List[str]: return ['-E'] diff --git a/mesonbuild/linkers/linkers.py b/mesonbuild/linkers/linkers.py index ba7b9228d718..705e4282138b 100644 --- a/mesonbuild/linkers/linkers.py +++ b/mesonbuild/linkers/linkers.py @@ -527,6 +527,7 @@ class MetrowerksStaticLinkerEmbeddedPowerPC(MetrowerksStaticLinker): id = 'mwldeppc' class TaskingStaticLinker(StaticLinker): + id = 'tasking' def __init__(self, exelist: T.List[str]): super().__init__(exelist) @@ -543,21 +544,6 @@ def get_output_args(self, target: str) -> T.List[str]: def get_linker_always_args(self) -> T.List[str]: return ['-r'] -class TaskingTricoreStaticLinker(TaskingStaticLinker): - id = 'artc' - -class TaskingARMStaticLinker(TaskingStaticLinker): - id = 'ararm' - -class Tasking8051StaticLinker(TaskingStaticLinker): - id = 'ar51' - -class TaskingMCSStaticLinker(TaskingStaticLinker): - id = 'armcs' - -class TaskingPCPStaticLinker(TaskingStaticLinker): - id = 'arpcp' - def prepare_rpaths(raw_rpaths: T.Tuple[str, ...], build_dir: str, from_dir: str) -> T.List[str]: # The rpaths we write must be relative if they point to the build dir, # because otherwise they have different length depending on the build @@ -1697,6 +1683,7 @@ class MetrowerksLinkerEmbeddedPowerPC(MetrowerksLinker): id = 'mwldeppc' class TaskingLinker(DynamicLinker): + id = 'tasking' _OPTIMIZATION_ARGS: T.Dict[str, T.List[str]] = { 'plain': [], @@ -1731,6 +1718,9 @@ def get_search_args(self, dirname: str) -> T.List[str]: def get_output_args(self, outputname: str) -> T.List[str]: return ['-o', outputname] + def get_lto_args(self) -> T.List[str]: + return ['--mil-link'] + def rsp_file_syntax(self) -> RSPFileSyntax: return RSPFileSyntax.TASKING @@ -1744,18 +1734,3 @@ def get_link_whole_for(self, args: T.List[str]) -> T.List[str]: for a in args: l.extend(self._apply_prefix('-Wl--whole-archive=' + a)) return l - -class TaskingTricoreLinker(TaskingLinker): - id = 'ltc' - -class TaskingARMLinker(TaskingLinker): - id = 'lkarm' - -class Tasking8051Linker(TaskingLinker): - id = 'lk51' - -class TaskingMCSLinker(TaskingLinker): - id = 'lmsc' - -class TaskingPCPLinker(TaskingLinker): - id = 'lpcp'