[extract_symbols.py] Adjust usage of nm again
authorJohn Brawn <john.brawn@arm.com>
Mon, 13 Feb 2023 15:59:20 +0000 (15:59 +0000)
committerJohn Brawn <john.brawn@arm.com>
Mon, 13 Feb 2023 16:29:08 +0000 (16:29 +0000)
The previous change to extract_symbols.py means that building on macOS
with LLVM_EXPORT_SYMBOLS_FOR_PLUGINS fails as we try to export some
local symbols, as the regex used to match external symbols wasn't good
enough. Solve this by using the -g option to nm, so we only get
external symbols and don't have to check for local symbols at all.

llvm/utils/extract_symbols.py

index 7270f59ec0d549cad0e9c261eb507e01c3c9a4b3..1d057cd3a51a5969027b5b0095d2d014f3659325 100755 (executable)
@@ -42,14 +42,14 @@ def dumpbin_get_symbols(lib):
     process.wait()
 
 def nm_get_symbols(lib):
+    # -P means the output is in portable format, and -g means we only get global
+    # symbols.
+    cmd = ['nm','-P','-g']
     if sys.platform.startswith('aix'):
-        process = subprocess.Popen(['nm','-P','-Xany','-C','-p',lib], bufsize=1,
-                                   stdout=subprocess.PIPE, stdin=subprocess.PIPE,
-                                   universal_newlines=True)
-    else:
-        process = subprocess.Popen(['nm','-P',lib], bufsize=1,
-                                   stdout=subprocess.PIPE, stdin=subprocess.PIPE,
-                                   universal_newlines=True)
+        cmd += ['-Xany','-C','-p']
+    process = subprocess.Popen(cmd+[lib], bufsize=1,
+                               stdout=subprocess.PIPE, stdin=subprocess.PIPE,
+                               universal_newlines=True)
     process.stdin.close()
     for line in process.stdout:
         # Look for external symbols that are defined in some section, i.e.
@@ -59,7 +59,7 @@ def nm_get_symbols(lib):
         # The -P flag displays the size field for symbols only when applicable,
         # so the last field is optional. There's no space after the value field,
         # but \s+ match newline also, so \s+\S* will match the optional size field.
-        match = re.match("^(\S+)\s+[^AabdtU]\s+\S+\s+\S*$", line)
+        match = re.match("^(\S+)\s+[^AU]\s+\S+\s+\S*$", line)
         if match:
             yield (match.group(1), True)
         # Look for undefined symbols, which have only name and type (which is U).