summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2016-11-18 01:40:20 +0000
committerEric Fiselier <eric@efcs.ca>2016-11-18 01:40:20 +0000
commit0d6941834cb62a02deed43af20d24cc2a10e8acb (patch)
tree478d9954b6979e91fae1fc2817dc6bd4f4040bcf /utils
parenta93ebeca94f812e18b4f465d98aad94f92220354 (diff)
Change sym_check to filter non-stdlib symbols.
Currently sym_check almost all names found in the binary, including those which are defined in other libraries. This makes our ABI lists harder to maintain. This patch adds a --only-stdlib-symbols option to sym_check which removes all symbols which aren't possibly provided by libc++. It also re-generates the linux ABI list after making this change. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@287294 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils')
-rw-r--r--utils/sym_check/sym_check/extract.py10
-rw-r--r--utils/sym_check/sym_check/util.py39
-rwxr-xr-xutils/sym_check/sym_diff.py7
-rwxr-xr-xutils/sym_check/sym_extract.py5
4 files changed, 59 insertions, 2 deletions
diff --git a/utils/sym_check/sym_check/extract.py b/utils/sym_check/sym_check/extract.py
index 7bafd8ec4..d132e2282 100644
--- a/utils/sym_check/sym_check/extract.py
+++ b/utils/sym_check/sym_check/extract.py
@@ -12,9 +12,11 @@ extract - A set of function that extract symbol lists from shared libraries.
"""
import distutils.spawn
import sys
+import re
from sym_check import util
+extract_ignore_names = ['_init', '_fini']
class NMExtractor(object):
"""
@@ -65,7 +67,8 @@ class NMExtractor(object):
return None
new_sym = {
'name': bits[0],
- 'type': bits[1]
+ 'type': bits[1],
+ 'is_defined': (bits[1].lower() != 'u')
}
new_sym['name'] = new_sym['name'].replace('@@', '@')
new_sym = self._transform_sym_type(new_sym)
@@ -81,6 +84,8 @@ class NMExtractor(object):
"""
if sym is None or len(sym) < 2:
return False
+ if sym['name'] in extract_ignore_names:
+ return False
bad_types = ['t', 'b', 'r', 'd', 'w']
return (sym['type'] not in bad_types
and sym['name'] not in ['__bss_start', '_end', '_edata'])
@@ -148,8 +153,11 @@ class ReadElfExtractor(object):
'name': parts[7],
'size': int(parts[2]),
'type': parts[3],
+ 'is_defined': (parts[6] != 'UND')
}
assert new_sym['type'] in ['OBJECT', 'FUNC', 'NOTYPE']
+ if new_sym['name'] in extract_ignore_names:
+ continue
if new_sym['type'] == 'NOTYPE':
continue
if new_sym['type'] == 'FUNC':
diff --git a/utils/sym_check/sym_check/util.py b/utils/sym_check/sym_check/util.py
index fd1b0b1e1..84f8d523c 100644
--- a/utils/sym_check/sym_check/util.py
+++ b/utils/sym_check/sym_check/util.py
@@ -12,7 +12,7 @@ import distutils.spawn
import signal
import subprocess
import sys
-
+import re
def execute_command(cmd, input_str=None):
"""
@@ -135,3 +135,40 @@ def extract_or_load(filename):
if is_library_file(filename):
return sym_check.extract.extract_symbols(filename)
return read_syms_from_file(filename)
+
+def adjust_mangled_name(name):
+ if not name.startswith('__Z'):
+ return name
+ return name[1:]
+
+new_delete_std_symbols = [
+ '_Znam',
+ '_Znwm',
+ '_ZdaPv',
+ '_ZdaPvm',
+ '_ZdlPv',
+ '_ZdlPvm'
+]
+
+def is_stdlib_symbol_name(name):
+ name = adjust_mangled_name(name)
+ if name in new_delete_std_symbols:
+ return True
+ if re.search("@GLIBC|@GCC", name):
+ return False
+ if re.search('(St[0-9])|(__cxa)|(__cxxabi)', name):
+ return True
+ return True
+
+def filter_stdlib_symbols(syms):
+ stdlib_symbols = []
+ other_symbols = []
+ for s in syms:
+ canon_name = adjust_mangled_name(s['name'])
+ if not is_stdlib_symbol_name(canon_name):
+ assert not s['is_defined'] and \
+ 'have non-stdlib symbol defined in stdlib'
+ other_symbols += [s]
+ else:
+ stdlib_symbols += [s]
+ return stdlib_symbols, other_symbols
diff --git a/utils/sym_check/sym_diff.py b/utils/sym_check/sym_diff.py
index 0d88a2b87..842e908dd 100755
--- a/utils/sym_check/sym_diff.py
+++ b/utils/sym_check/sym_diff.py
@@ -27,6 +27,9 @@ def main():
'--removed-only', dest='removed_only',
help='Only print removed symbols',
action='store_true', default=False)
+ parser.add_argument('--only-stdlib-symbols', dest='only_stdlib',
+ help="Filter all symbols not related to the stdlib",
+ action='store_true', default=False)
parser.add_argument(
'-o', '--output', dest='output',
help='The output file. stdout is used if not given',
@@ -44,6 +47,10 @@ def main():
old_syms_list = util.extract_or_load(args.old_syms)
new_syms_list = util.extract_or_load(args.new_syms)
+ if args.only_stdlib:
+ old_syms_list, _ = util.filter_stdlib_symbols(old_syms_list)
+ new_syms_list, _ = util.filter_stdlib_symbols(new_syms_list)
+
added, removed, changed = diff.diff(old_syms_list, new_syms_list)
if args.removed_only:
added = {}
diff --git a/utils/sym_check/sym_extract.py b/utils/sym_check/sym_extract.py
index a0fbb3e63..27765679e 100755
--- a/utils/sym_check/sym_extract.py
+++ b/utils/sym_check/sym_extract.py
@@ -25,11 +25,16 @@ def main():
parser.add_argument('--names-only', dest='names_only',
help='Output only the name of the symbol',
action='store_true', default=False)
+ parser.add_argument('--only-stdlib-symbols', dest='only_stdlib',
+ help="Filter all symbols not related to the stdlib",
+ action='store_true', default=False)
args = parser.parse_args()
if args.output is not None:
print('Extracting symbols from %s to %s.'
% (args.library, args.output))
syms = extract.extract_symbols(args.library)
+ if args.only_stdlib:
+ syms, other_syms = util.filter_stdlib_symbols(syms)
util.write_syms(syms, out=args.output, names_only=args.names_only)