Skip to content

Commit 0336e66

Browse files
committed
depfixer: don't invoke install_name_tool on non-darwin targets
fix_rpath() fell through to the install_name_tool/otool path whenever a file wasn't valid ELF, regardless of target system. detect_elf_type() exits 0 for any non-ELF file, and that exit was caught and treated as "try darwin fixup" unconditionally. On a non-darwin system with install_name_tool on PATH (e.g. darwin cross-toolchain installed alongside), this ran otool/install_name_tool against native binaries. Gate the darwin-only path on system == 'darwin'. Fixes #8027
1 parent 16fe37e commit 0336e66

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

mesonbuild/scripts/depfixer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,9 @@ def fix_rpath(fname: str, rpath_dirs_to_remove: T.Set[bytes], new_rpath: T.Union
832832
pass
833833
else:
834834
raise
835+
# Non-ELF files fall through here on any system, not just darwin (#8027)
836+
if system != 'darwin':
837+
return
835838
# We don't look for this on import because it will do a useless PATH lookup
836839
# on non-mac platforms. That can be expensive on some Windows machines
837840
# (up to 30ms), which is significant with --only-changed. For details, see:

unittests/internaltests.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import mesonbuild.envconfig
2626
import mesonbuild.environment
2727
import mesonbuild.modules.gnome
28+
import mesonbuild.scripts.depfixer
2829
import mesonbuild.scripts.env2mfile
2930
from mesonbuild import coredata
3031
from mesonbuild.compilers.c import ClangCCompiler, GnuCCompiler
@@ -2233,3 +2234,13 @@ def expected_binaries(gnu_tuple: str) -> T.Dict[str, T.List[str]]:
22332234
self.assertEqual(actual.compile_args, expected.compile_args)
22342235
self.assertEqual(actual.link_args, expected.link_args)
22352236
self.assertEqual(actual.cmake, expected.cmake)
2237+
2238+
def test_depfixer_skips_install_name_tool_on_non_darwin(self) -> None:
2239+
# non-ELF file on non-darwin must not probe for install_name_tool (#8027)
2240+
with tempfile.NamedTemporaryFile(suffix='.so') as f:
2241+
f.write(b'not an elf file')
2242+
f.flush()
2243+
with mock.patch('mesonbuild.scripts.depfixer.shutil.which') as mock_which:
2244+
mesonbuild.scripts.depfixer.fix_rpath(
2245+
f.name, set(), '', '', {}, system='linux', verbose=False)
2246+
mock_which.assert_not_called()

0 commit comments

Comments
 (0)