diff --git a/docs/yaml/functions/_build_target_base.yaml b/docs/yaml/functions/_build_target_base.yaml index 1721b29cfe5a..d73bdf35ff16 100644 --- a/docs/yaml/functions/_build_target_base.yaml +++ b/docs/yaml/functions/_build_target_base.yaml @@ -103,6 +103,12 @@ kwargs: Flags to use during linking. You can use UNIX-style flags here for all platforms. + link_syms: + type: list[str] + description: | + Flags to define and undefine symbols during linking. You must use + build-system-appropriate flags here. + link_depends: type: str | file | custom_tgt | custom_idx description: | diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 5716ea29e351..311e80761066 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -3558,15 +3558,19 @@ def generate_link(self, target: build.BuildTarget, outname, obj_list, linker: T. elem.add_dep(dep_targets + custom_target_libraries) # Compiler args must be included in TI C28x linker commands. + compile_args = [] if linker.get_id() in {'c2000', 'c6000', 'ti'}: - compile_args = [] for for_machine in MachineChoice: clist = self.environment.coredata.compilers[for_machine] for langname, compiler in clist.items(): if langname in {'c', 'cpp'} and compiler.get_id() in {'c2000', 'c6000', 'ti'}: compile_args += self.generate_basic_compiler_args(target, compiler) - elem.add_item('ARGS', compile_args) + # Add -Wl,--defsym and -Wl,--undefined args + if not isinstance(target, build.StaticLibrary): + compile_args += linker.get_target_link_syms(target) + if compile_args: + elem.add_item('ARGS', compile_args) elem.add_item('LINK_ARGS', commands) self.create_target_linker_introspection(target, linker, commands) return elem diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 35f1f24a42f8..e1be289212a8 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -84,6 +84,7 @@ class DFeatures(TypedDict): 'link_with', 'link_whole', 'link_args', + 'link_syms', 'link_depends', 'implicit_include_directories', 'include_directories', @@ -1151,6 +1152,10 @@ def process_kwargs(self, kwargs): or build_rpath properties instead. This will become a hard error in a future Meson release. ''')) + self.link_syms = extract_as_list(kwargs, 'link_syms') + for i in self.link_syms: + if not isinstance(i, str): + raise InvalidArguments('Link_syms arguments must be strings.') self.process_link_depends(kwargs.get('link_depends', [])) # Target-specific include dirs must be added BEFORE include dirs from # internal deps (added inside self.add_deps()) to override them. diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index 603a3eb484de..7a34f42b1afc 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -1038,6 +1038,9 @@ def get_soname_args(self, env: 'Environment', prefix: str, shlib_name: str, def get_target_link_args(self, target: 'BuildTarget') -> T.List[str]: return target.link_args + def get_target_link_syms(self, target: 'BuildTarget') -> T.List[str]: + return target.link_syms + def get_dependency_compile_args(self, dep: 'Dependency') -> T.List[str]: return dep.get_compile_args() diff --git a/mesonbuild/interpreter/type_checking.py b/mesonbuild/interpreter/type_checking.py index ed34be950065..de9f601b6e0c 100644 --- a/mesonbuild/interpreter/type_checking.py +++ b/mesonbuild/interpreter/type_checking.py @@ -646,6 +646,13 @@ def _name_suffix_validator(arg: T.Optional[T.Union[str, T.List]]) -> T.Optional[ validator=in_set_validator(set(compilers.all_languages)), since='0.51.0', ), + KwargInfo( + 'link_syms', + (ContainerTypeInfo(list, str), NoneType), + listify=True, + default=None, + since='1.7.0', + ), ] def _validate_win_subsystem(value: T.Optional[str]) -> T.Optional[str]: