aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorL. E. Segovia <amy@amyspark.me>2022-10-30 13:05:40 +0000
committerJussi Pakkanen <jpakkane@gmail.com>2022-11-01 17:56:18 +0200
commit7e5b0760ce18666c7b1a42f97ca29ce03406e21b (patch)
tree1d38a4770efe0bd2be5da9bf67a712926d9f47a9
parent21f86fa90209538b1d9cc9aa3aaa1d8dc884137f (diff)
downloadmeson-7e5b0760ce18666c7b1a42f97ca29ce03406e21b.zip
meson-7e5b0760ce18666c7b1a42f97ca29ce03406e21b.tar.gz
meson-7e5b0760ce18666c7b1a42f97ca29ce03406e21b.tar.bz2
minstall: make do_strip run with -Sx for macOS targets
This commit also adds some extra symbol noise to lib.c, in order to aid detection of the debug information with nm. Fixes #10943
-rw-r--r--mesonbuild/minstall.py10
-rw-r--r--test cases/unit/103 strip/lib.c4
-rw-r--r--unittests/linuxliketests.py28
3 files changed, 33 insertions, 9 deletions
diff --git a/mesonbuild/minstall.py b/mesonbuild/minstall.py
index 69763fa..8c74990 100644
--- a/mesonbuild/minstall.py
+++ b/mesonbuild/minstall.py
@@ -27,7 +27,7 @@ import typing as T
from . import build
from . import environment
from .backend.backends import InstallData
-from .mesonlib import MesonException, Popen_safe, RealPathAction, is_windows, setup_vsenv, pickle_load
+from .mesonlib import MesonException, Popen_safe, RealPathAction, is_windows, setup_vsenv, pickle_load, is_osx
from .scripts import depfixer, destdir_join
from .scripts.meson_exe import run_exe
try:
@@ -566,7 +566,13 @@ class Installer:
def do_strip(self, strip_bin: T.List[str], fname: str, outname: str) -> None:
self.log(f'Stripping target {fname!r}.')
- returncode, stdo, stde = self.Popen_safe(strip_bin + [outname])
+ if is_osx():
+ # macOS expects dynamic objects to be stripped with -x maximum.
+ # To also strip the debug info, -S must be added.
+ # See: https://www.unix.com/man-page/osx/1/strip/
+ returncode, stdo, stde = self.Popen_safe(strip_bin + ['-S', '-x', outname])
+ else:
+ returncode, stdo, stde = self.Popen_safe(strip_bin + [outname])
if returncode != 0:
print('Could not strip file.\n')
print(f'Stdout:\n{stdo}\n')
diff --git a/test cases/unit/103 strip/lib.c b/test cases/unit/103 strip/lib.c
index 3940fde..7d8163c 100644
--- a/test cases/unit/103 strip/lib.c
+++ b/test cases/unit/103 strip/lib.c
@@ -1 +1,3 @@
-void func(void){}
+#include <stdio.h>
+
+void func(void){ fprintf(stderr, "Test 1 2 3\n"); }
diff --git a/unittests/linuxliketests.py b/unittests/linuxliketests.py
index 357e420..8dd9cfc 100644
--- a/unittests/linuxliketests.py
+++ b/unittests/linuxliketests.py
@@ -1773,25 +1773,41 @@ class LinuxlikeTests(BasePlatformTests):
# If so, we can test that cmake works with "gcc -m32"
self.do_one_test_with_nativefile('../cmake/1 basic', "['gcc', '-m32']")
- @skipUnless(is_linux(), 'Test only applicable to Linux')
+ @skipUnless(is_linux() or is_osx(), 'Test only applicable to Linux and macOS')
def test_install_strip(self):
testdir = os.path.join(self.unit_test_dir, '103 strip')
self.init(testdir)
self.build()
destdir = self.installdir + self.prefix
- lib = os.path.join(destdir, self.libdir, 'liba.so')
+ if is_linux():
+ lib = os.path.join(destdir, self.libdir, 'liba.so')
+ else:
+ lib = os.path.join(destdir, self.libdir, 'liba.dylib')
install_cmd = self.meson_command + ['install', '--destdir', self.installdir]
# Check we have debug symbols by default
self._run(install_cmd, workdir=self.builddir)
- stdout = self._run(['file', '-b', lib])
- self.assertIn('not stripped', stdout)
+ if is_linux():
+ # file can detect stripped libraries on linux
+ stdout = self._run(['file', '-b', lib])
+ self.assertIn('not stripped', stdout)
+ else:
+ # on macOS we need to query dsymutil instead.
+ # Alternatively, check if __dyld_private is defined
+ # in the output of nm liba.dylib, but that is not
+ # 100% reliable, it needs linking to an external library
+ stdout = self._run(['dsymutil', '--dump-debug-map', lib])
+ self.assertIn('symbols:', stdout)
# Check debug symbols got removed with --strip
self._run(install_cmd + ['--strip'], workdir=self.builddir)
- stdout = self._run(['file', '-b', lib])
- self.assertNotIn('not stripped', stdout)
+ if is_linux():
+ stdout = self._run(['file', '-b', lib])
+ self.assertNotIn('not stripped', stdout)
+ else:
+ stdout = self._run(['dsymutil', '--dump-debug-map', lib])
+ self.assertNotIn('symbols:', stdout)
def test_isystem_default_removal_with_symlink(self):
env = get_fake_env()