Skip to content

Commit

Permalink
Add link_syms parameter to build targets
Browse files Browse the repository at this point in the history
This parameter provides a place to add -Wl,--defsym=a=b and
-Wl,--undefined=c parameters during linking. These should occur before
any object files and must occur before any libraries so that the
results will affect the link correctly.

In the ninjabackend, this is done by adding these to the ARGS
parameter during linking as that is placed in the command line before
any input files or libraries.

Signed-off-by: Keith Packard <[email protected]>
  • Loading branch information
keith-packard committed Dec 14, 2024
1 parent 54cab09 commit f480f2b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/yaml/functions/_build_target_base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
8 changes: 6 additions & 2 deletions mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions mesonbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class DFeatures(TypedDict):
'link_with',
'link_whole',
'link_args',
'link_syms',
'link_depends',
'implicit_include_directories',
'include_directories',
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions mesonbuild/compilers/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
7 changes: 7 additions & 0 deletions mesonbuild/interpreter/type_checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down

0 comments on commit f480f2b

Please sign in to comment.