diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index f42726260..c80ffb00b 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -377,9 +377,10 @@ def get_base_link_args(options, linker, is_shared_module): # -Wl,-dead_strip_dylibs is incompatible with bitcode args.extend(linker.get_asneeded_args()) - # Apple's ld (the only one that supports bitcode) does not like any - # -undefined arguments at all, so don't pass these when using bitcode + # Apple's ld (the only one that supports bitcode) does not like -undefined + # arguments or -headerpad_max_install_names when bitcode is enabled if not bitcode: + args.extend(linker.headerpad_args()) if (not is_shared_module and option_enabled(linker.base_options, options, 'b_lundef')): args.extend(linker.no_undefined_link_args()) @@ -1203,6 +1204,9 @@ class Compiler: def get_asneeded_args(self) -> T.List[str]: return self.linker.get_asneeded_args() + def headerpad_args(self) -> T.List[str]: + return self.linker.headerpad_args() + def bitcode_args(self) -> T.List[str]: return self.linker.bitcode_args() diff --git a/mesonbuild/linkers.py b/mesonbuild/linkers.py index 25a8c9c11..bb3229db5 100644 --- a/mesonbuild/linkers.py +++ b/mesonbuild/linkers.py @@ -440,6 +440,10 @@ class DynamicLinker(LinkerEnvVarsMixin, metaclass=abc.ABCMeta): """Arguments to make all warnings errors.""" return [] + def headerpad_args(self) -> T.List[str]: + # Only used by the Apple linker + return [] + def bitcode_args(self) -> T.List[str]: raise mesonlib.MesonException('This linker does not support bitcode bundles') @@ -659,8 +663,8 @@ class AppleDynamicLinker(PosixDynamicLinkerMixin, DynamicLinker): def no_undefined_args(self) -> T.List[str]: return self._apply_prefix('-undefined,error') - def get_always_args(self) -> T.List[str]: - return self._apply_prefix('-headerpad_max_install_names') + super().get_always_args() + def headerpad_args(self) -> T.List[str]: + return self._apply_prefix('-headerpad_max_install_names') def bitcode_args(self) -> T.List[str]: return self._apply_prefix('-bitcode_bundle') @@ -688,9 +692,7 @@ class AppleDynamicLinker(PosixDynamicLinkerMixin, DynamicLinker): install_rpath: str) -> T.Tuple[T.List[str], T.Set[bytes]]: if not rpath_paths and not install_rpath and not build_rpath: return ([], set()) - # Ensure that there is enough space for install_name_tool in-place - # editing of large RPATHs - args = self._apply_prefix('-headerpad_max_install_names') + args = [] # @loader_path is the equivalent of $ORIGIN on macOS # https://stackoverflow.com/q/26280738 origin_placeholder = '@loader_path'