Mesa (master): symbols-check: fix `nm` invocation on MacOS

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sun Aug 4 10:09:29 UTC 2019


Module: Mesa
Branch: master
Commit: 8f1cdac7937eeb1a7874e6741fb32a7d6154382b
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=8f1cdac7937eeb1a7874e6741fb32a7d6154382b

Author: Eric Engestrom <eric.engestrom at intel.com>
Date:   Sat Aug  3 18:08:38 2019 +0100

symbols-check: fix `nm` invocation on MacOS

According to Mac OSX's man page [1], this is how we should get the list
of exported symbols:
  nm -g -P foo.dylib

-g to only show the exported symbols
-P to show it in a "portable" format, ie. readable by a script

Since this is supported by GNU nm as well, let's use that everywhere,
although some care needs to be taken as there are some differences in
the output.

[1] https://www.unix.com/man-page/osx/1/nm/

Signed-off-by: Eric Engestrom <eric.engestrom at intel.com>
Tested-by: Vinson Lee <vlee at freedesktop.org>

---

 bin/symbols-check.py | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/bin/symbols-check.py b/bin/symbols-check.py
index 39ad1451852..329ca5f46a0 100644
--- a/bin/symbols-check.py
+++ b/bin/symbols-check.py
@@ -1,8 +1,9 @@
 #!/usr/bin/env python
 
 import argparse
-import subprocess
 import os
+import platform
+import subprocess
 
 # This list contains symbols that _might_ be exported for some platforms
 PLATFORM_SYMBOLS = [
@@ -23,13 +24,22 @@ def get_symbols(nm, lib):
     List all the (non platform-specific) symbols exported by the library
     '''
     symbols = []
-    output = subprocess.check_output([nm, '--format=bsd', '-D', '--defined-only', lib],
+    platform_name = platform.system()
+    output = subprocess.check_output([nm, '-gP', lib],
                                      stderr=open(os.devnull, 'w')).decode("ascii")
     for line in output.splitlines():
-        (_, _, symbol_name) = line.split()
-        if symbol_name in PLATFORM_SYMBOLS:
+        fields = line.split()
+        if len(fields) == 2 or fields[1] == 'U':
             continue
+        symbol_name = fields[0]
+        if platform_name == 'Linux':
+            if symbol_name in PLATFORM_SYMBOLS:
+                continue
+        elif platform_name == 'Darwin':
+            assert symbol_name[0] == '_'
+            symbol_name = symbol_name[1:]
         symbols.append(symbol_name)
+
     return symbols
 
 




More information about the mesa-commit mailing list