From 68cd9c089d995e5db507a458822b2745d8c12805 Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Mon, 3 Jun 2024 18:08:58 +0200 Subject: [PATCH] Add -export_dynamic flag for AppleDynamicLinker The apple linker uses -export_dynamic instead of --export-dynamic [1]. This should be set when setting export_dynamic: true. Resolves #13290 [1]: https://opensource.apple.com/source/ld64/ld64-609/doc/man/man1/ld.1.auto.html --- mesonbuild/linkers/linkers.py | 3 +++ unittests/darwintests.py | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/mesonbuild/linkers/linkers.py b/mesonbuild/linkers/linkers.py index de08e0f443e9..7507f5ab7b6c 100644 --- a/mesonbuild/linkers/linkers.py +++ b/mesonbuild/linkers/linkers.py @@ -834,6 +834,9 @@ def build_rpath_args(self, env: 'Environment', build_dir: str, from_dir: str, def get_thinlto_cache_args(self, path: str) -> T.List[str]: return ["-Wl,-cache_path_lto," + path] + def export_dynamic_args(self, env: 'Environment') -> T.List[str]: + return self._apply_prefix('-export_dynamic') + class LLVMLD64DynamicLinker(AppleDynamicLinker): diff --git a/unittests/darwintests.py b/unittests/darwintests.py index 5528bbc9fdc7..7403104771b7 100644 --- a/unittests/darwintests.py +++ b/unittests/darwintests.py @@ -81,6 +81,18 @@ def test_apple_bitcode_modules(self): self.build() self.run_tests() + def test_apple_lto_export_dynamic(self): + ''' + Tests that -Wl,-export_dynamic is correctly added, when export_dynamic: true is set. + On macOS, this is relevant for LTO builds only. + ''' + testdir = os.path.join(self.common_test_dir, '148 shared module resolving symbol in executable') + # Ensure that it builds even with LTO enabled + env = {'CFLAGS': '-flto'} + self.init(testdir, override_envvars=env) + self.build() + self.run_tests() + def _get_darwin_versions(self, fname): fname = os.path.join(self.builddir, fname) out = subprocess.check_output(['otool', '-L', fname], universal_newlines=True)