Skip to content

Commit

Permalink
Add -export_dynamic flag for AppleDynamicLinker
Browse files Browse the repository at this point in the history
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
  • Loading branch information
wolfgangwalther committed Jun 3, 2024
1 parent e5aed6a commit 68cd9c0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mesonbuild/linkers/linkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
12 changes: 12 additions & 0 deletions unittests/darwintests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 68cd9c0

Please sign in to comment.