Skip to content

Commit

Permalink
linkers: add extra_paths to build_rpath_args
Browse files Browse the repository at this point in the history
Allow adding extra directories to the rpath.  Rust needs this when Rustup
is in use.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
bonzini committed Feb 5, 2025
1 parent 0e6e687 commit e30bc27
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions mesonbuild/linkers/linkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def get_coverage_link_args(self) -> T.List[str]:

def build_rpath_args(self, env: 'Environment', build_dir: str, from_dir: str,
rpath_paths: T.Tuple[str, ...], build_rpath: str,
install_rpath: str) -> T.Tuple[T.List[str], T.Set[bytes]]:
install_rpath: str, extra_paths: T.Optional[T.List[str]] = None) -> T.Tuple[T.List[str], T.Set[bytes]]:
return ([], set())

def thread_link_flags(self, env: 'Environment') -> T.List[str]:
Expand Down Expand Up @@ -283,7 +283,7 @@ def bitcode_args(self) -> T.List[str]:

def build_rpath_args(self, env: 'Environment', build_dir: str, from_dir: str,
rpath_paths: T.Tuple[str, ...], build_rpath: str,
install_rpath: str) -> T.Tuple[T.List[str], T.Set[bytes]]:
install_rpath: str, extra_paths: T.Optional[T.List[str]] = None) -> T.Tuple[T.List[str], T.Set[bytes]]:
return ([], set())

def get_soname_args(self, env: 'Environment', prefix: str, shlib_name: str,
Expand Down Expand Up @@ -686,11 +686,11 @@ def get_soname_args(self, env: 'Environment', prefix: str, shlib_name: str,

def build_rpath_args(self, env: 'Environment', build_dir: str, from_dir: str,
rpath_paths: T.Tuple[str, ...], build_rpath: str,
install_rpath: str) -> T.Tuple[T.List[str], T.Set[bytes]]:
install_rpath: str, extra_paths: T.Optional[T.List[str]] = None) -> T.Tuple[T.List[str], T.Set[bytes]]:
m = env.machines[self.for_machine]
if m.is_windows() or m.is_cygwin():
return ([], set())
if not rpath_paths and not install_rpath and not build_rpath:
if not rpath_paths and not install_rpath and not build_rpath and not extra_paths:
return ([], set())
args: T.List[str] = []
origin_placeholder = '$ORIGIN'
Expand All @@ -707,6 +707,8 @@ def build_rpath_args(self, env: 'Environment', build_dir: str, from_dir: str,
all_paths.add(build_rpath)
for p in build_rpath.split(':'):
rpath_dirs_to_remove.add(p.encode('utf8'))
if extra_paths:
all_paths.update(extra_paths)

# TODO: should this actually be "for (dragonfly|open)bsd"?
if mesonlib.is_dragonflybsd() or mesonlib.is_openbsd():
Expand Down Expand Up @@ -843,8 +845,8 @@ def get_soname_args(self, env: 'Environment', prefix: str, shlib_name: str,

def build_rpath_args(self, env: 'Environment', build_dir: str, from_dir: str,
rpath_paths: T.Tuple[str, ...], build_rpath: str,
install_rpath: str) -> T.Tuple[T.List[str], T.Set[bytes]]:
if not rpath_paths and not install_rpath and not build_rpath:
install_rpath: str, extra_paths: T.Optional[T.List[str]] = None) -> T.Tuple[T.List[str], T.Set[bytes]]:
if not rpath_paths and not install_rpath and not build_rpath and not extra_paths:
return ([], set())
args: T.List[str] = []
rpath_dirs_to_remove: T.Set[bytes] = set()
Expand All @@ -855,6 +857,8 @@ def build_rpath_args(self, env: 'Environment', build_dir: str, from_dir: str,
all_paths = mesonlib.OrderedSet([os.path.join(origin_placeholder, p) for p in processed_rpaths])
if build_rpath != '':
all_paths.update(build_rpath.split(':'))
if extra_paths:
all_paths.update(extra_paths)
for rp in all_paths:
rpath_dirs_to_remove.add(rp.encode('utf8'))
args.extend(self._apply_prefix('-rpath,' + rp))
Expand Down Expand Up @@ -991,7 +995,7 @@ def get_asneeded_args(self) -> T.List[str]:

def build_rpath_args(self, env: 'Environment', build_dir: str, from_dir: str,
rpath_paths: T.Tuple[str, ...], build_rpath: str,
install_rpath: str) -> T.Tuple[T.List[str], T.Set[bytes]]:
install_rpath: str, extra_paths: T.Optional[T.List[str]] = None) -> T.Tuple[T.List[str], T.Set[bytes]]:
return ([], set())


Expand Down Expand Up @@ -1069,7 +1073,7 @@ def get_soname_args(self, env: 'Environment', prefix: str, shlib_name: str,

def build_rpath_args(self, env: 'Environment', build_dir: str, from_dir: str,
rpath_paths: T.Tuple[str, ...], build_rpath: str,
install_rpath: str) -> T.Tuple[T.List[str], T.Set[bytes]]:
install_rpath: str, extra_paths: T.Optional[T.List[str]] = None) -> T.Tuple[T.List[str], T.Set[bytes]]:
return ([], set())

class CompCertDynamicLinker(DynamicLinker):
Expand Down Expand Up @@ -1112,7 +1116,7 @@ def get_soname_args(self, env: 'Environment', prefix: str, shlib_name: str,

def build_rpath_args(self, env: 'Environment', build_dir: str, from_dir: str,
rpath_paths: T.Tuple[str, ...], build_rpath: str,
install_rpath: str) -> T.Tuple[T.List[str], T.Set[bytes]]:
install_rpath: str, extra_paths: T.Optional[T.List[str]] = None) -> T.Tuple[T.List[str], T.Set[bytes]]:
return ([], set())

class TIDynamicLinker(DynamicLinker):
Expand Down Expand Up @@ -1218,15 +1222,17 @@ class NAGDynamicLinker(PosixDynamicLinkerMixin, DynamicLinker):

def build_rpath_args(self, env: 'Environment', build_dir: str, from_dir: str,
rpath_paths: T.Tuple[str, ...], build_rpath: str,
install_rpath: str) -> T.Tuple[T.List[str], T.Set[bytes]]:
if not rpath_paths and not install_rpath and not build_rpath:
install_rpath: str, extra_paths: T.Optional[T.List[str]] = None) -> T.Tuple[T.List[str], T.Set[bytes]]:
if not rpath_paths and not install_rpath and not build_rpath and not extra_paths:
return ([], set())
args: T.List[str] = []
origin_placeholder = '$ORIGIN'
processed_rpaths = prepare_rpaths(rpath_paths, build_dir, from_dir)
all_paths = mesonlib.OrderedSet([os.path.join(origin_placeholder, p) for p in processed_rpaths])
if build_rpath != '':
all_paths.add(build_rpath)
if extra_paths:
all_paths.update(extra_paths)
for rp in all_paths:
args.extend(self._apply_prefix('-Wl,-Wl,,-rpath,,' + rp))

Expand Down Expand Up @@ -1263,7 +1269,7 @@ def get_std_shared_lib_args(self) -> T.List[str]:

def build_rpath_args(self, env: 'Environment', build_dir: str, from_dir: str,
rpath_paths: T.Tuple[str, ...], build_rpath: str,
install_rpath: str) -> T.Tuple[T.List[str], T.Set[bytes]]:
install_rpath: str, extra_paths: T.Optional[T.List[str]] = None) -> T.Tuple[T.List[str], T.Set[bytes]]:
if not env.machines[self.for_machine].is_windows():
return (['-R' + os.path.join(build_dir, p) for p in rpath_paths], set())
return ([], set())
Expand Down Expand Up @@ -1474,8 +1480,8 @@ def fatal_warnings(self) -> T.List[str]:

def build_rpath_args(self, env: 'Environment', build_dir: str, from_dir: str,
rpath_paths: T.Tuple[str, ...], build_rpath: str,
install_rpath: str) -> T.Tuple[T.List[str], T.Set[bytes]]:
if not rpath_paths and not install_rpath and not build_rpath:
install_rpath: str, extra_paths: T.Optional[T.List[str]] = None) -> T.Tuple[T.List[str], T.Set[bytes]]:
if not rpath_paths and not install_rpath and not build_rpath and not extra_paths:
return ([], set())
processed_rpaths = prepare_rpaths(rpath_paths, build_dir, from_dir)
all_paths = mesonlib.OrderedSet([os.path.join('$ORIGIN', p) for p in processed_rpaths])
Expand All @@ -1486,6 +1492,8 @@ def build_rpath_args(self, env: 'Environment', build_dir: str, from_dir: str,
all_paths.add(build_rpath)
for p in build_rpath.split(':'):
rpath_dirs_to_remove.add(p.encode('utf8'))
if extra_paths:
all_paths.update(extra_paths)

# In order to avoid relinking for RPATH removal, the binary needs to contain just
# enough space in the ELF header to hold the final installation RPATH.
Expand Down Expand Up @@ -1544,7 +1552,7 @@ def get_link_whole_for(self, args: T.List[str]) -> T.List[str]:

def build_rpath_args(self, env: 'Environment', build_dir: str, from_dir: str,
rpath_paths: T.Tuple[str, ...], build_rpath: str,
install_rpath: str) -> T.Tuple[T.List[str], T.Set[bytes]]:
install_rpath: str, extra_paths: T.Optional[T.List[str]] = None) -> T.Tuple[T.List[str], T.Set[bytes]]:
all_paths: mesonlib.OrderedSet[str] = mesonlib.OrderedSet()
# install_rpath first, followed by other paths, and the system path last
if install_rpath != '':
Expand All @@ -1565,6 +1573,8 @@ def build_rpath_args(self, env: 'Environment', build_dir: str, from_dir: str,
for p in sys_path:
if os.path.isdir(p):
all_paths.add(p)
if extra_paths:
all_paths.update(extra_paths)
return (self._apply_prefix('-blibpath:' + ':'.join(all_paths)), set())

def thread_flags(self, env: 'Environment') -> T.List[str]:
Expand Down

0 comments on commit e30bc27

Please sign in to comment.