[libcxx-commits] [libcxx] b128373 - [libc++] Make it easier to re-generate the ABI lists
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Nov 2 08:36:55 PST 2020
Author: Louis Dionne
Date: 2020-11-02T11:36:35-05:00
New Revision: b128373eb85e3f3813c2d71ece1999046d6aff54
URL: https://github.com/llvm/llvm-project/commit/b128373eb85e3f3813c2d71ece1999046d6aff54
DIFF: https://github.com/llvm/llvm-project/commit/b128373eb85e3f3813c2d71ece1999046d6aff54.diff
LOG: [libc++] Make it easier to re-generate the ABI lists
Instead of having to remember the command-line to use every time, this
commit adds a CMake target to generate the ABI list in the current
configuration, if it is supported.
As a fly-by change, remove scripts that are now unused (sym_match.py
and sym_extract.py).
Added:
libcxx/utils/generate_abi_list.py
Modified:
libcxx/lib/abi/CMakeLists.txt
libcxx/lib/abi/README.TXT
Removed:
libcxx/utils/sym_extract.py
libcxx/utils/sym_match.py
################################################################################
diff --git a/libcxx/lib/abi/CMakeLists.txt b/libcxx/lib/abi/CMakeLists.txt
index e39bad0c7ca4..98cfe8bf1e14 100644
--- a/libcxx/lib/abi/CMakeLists.txt
+++ b/libcxx/lib/abi/CMakeLists.txt
@@ -30,6 +30,13 @@ if (EXISTS "${ABILIST_FILE}"
$<TARGET_SONAME_FILE:cxx_shared>
DEPENDS cxx_shared
COMMENT "Testing ABI compatibility...")
+
+ add_custom_target(generate-cxx-abilist
+ COMMAND ${Python3_EXECUTABLE} "${LIBCXX_SOURCE_DIR}/utils/generate_abi_list.py"
+ --output "${ABILIST_FILE}"
+ "$<TARGET_SONAME_FILE:cxx_shared>"
+ DEPENDS cxx_shared
+ COMMENT "Generating the ABI list for the current configuration")
else()
message(STATUS "there is no pre-generated ABI list for the requested libc++ configuration. "
"check-cxx-abilist target is not supported")
diff --git a/libcxx/lib/abi/README.TXT b/libcxx/lib/abi/README.TXT
index f098b80403aa..32a2d337fcf5 100644
--- a/libcxx/lib/abi/README.TXT
+++ b/libcxx/lib/abi/README.TXT
@@ -1,8 +1,9 @@
This directory contains abi lists representing the symbols exported
-by the libc++ library. The lists are generated using sym_extract.py.
+by the libc++ library. The lists are generated using libcxx/utils/generate_abi_list.py.
-Every time a symbol is added or removed from the libc++ library each of the
-lists *MUST* be updated to reflect the changes.
+Every time a symbol is added or removed from the libc++ library, each of the
+lists *MUST* be updated to reflect the changes. This can be done by using the
+`generate-cxx-abilist` CMake target.
-TODO Add more documentation about generating and using the lists.
-TODO Add more documentation about the build configuration the lists are generated against.
+We do not keep an up-to-date ABI list for all the build configurations of libc++.
+Currently, only the default configuration on MacOS and Linux are supported.
diff --git a/libcxx/utils/generate_abi_list.py b/libcxx/utils/generate_abi_list.py
new file mode 100755
index 000000000000..018b436f4663
--- /dev/null
+++ b/libcxx/utils/generate_abi_list.py
@@ -0,0 +1,40 @@
+#!/usr/bin/env python
+#===----------------------------------------------------------------------===##
+#
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#
+#===----------------------------------------------------------------------===##
+
+import argparse
+import io
+import libcxx.sym_check.extract
+import libcxx.sym_check.util
+import pprint
+import sys
+
+def OutputFile(file):
+ if isinstance(file, io.IOBase):
+ return file
+ assert isinstance(file, str), "Got object {} which is not a str".format(file)
+ return open(file, 'w')
+
+def main(argv):
+ parser = argparse.ArgumentParser(
+ description='Extract a list of symbols from a shared library.')
+ parser.add_argument('library', metavar='LIB', type=str,
+ help='The library to extract symbols from.')
+ parser.add_argument('-o', '--output', dest='output', type=OutputFile, default=sys.stdout,
+ help='The output file to write the symbols to. It is overwritten if it already exists. '
+ 'If no file is specified, the results are written to standard output.')
+ args = parser.parse_args(argv)
+
+ symbols = libcxx.sym_check.extract.extract_symbols(args.library)
+ symbols, _ = libcxx.sym_check.util.filter_stdlib_symbols(symbols)
+
+ lines = [pprint.pformat(sym, width=99999) for sym in symbols]
+ args.output.writelines('\n'.join(sorted(lines)))
+
+if __name__ == '__main__':
+ main(sys.argv[1:])
diff --git a/libcxx/utils/sym_extract.py b/libcxx/utils/sym_extract.py
deleted file mode 100755
index 987c207c1e41..000000000000
--- a/libcxx/utils/sym_extract.py
+++ /dev/null
@@ -1,54 +0,0 @@
-#!/usr/bin/env python
-#===----------------------------------------------------------------------===##
-#
-# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-# See https://llvm.org/LICENSE.txt for license information.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-#
-#===----------------------------------------------------------------------===##
-"""
-sym_extract - Extract and output a list of symbols from a shared library.
-"""
-from argparse import ArgumentParser
-from libcxx.sym_check import extract, util
-
-
-def main():
- parser = ArgumentParser(
- description='Extract a list of symbols from a shared library.')
- parser.add_argument('library', metavar='shared-lib', type=str,
- help='The library to extract symbols from')
- parser.add_argument('-o', '--output', dest='output',
- help='The output file. stdout is used if not given',
- type=str, action='store', default=None)
- 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)
- parser.add_argument('--defined-only', dest='defined_only',
- help="Filter all symbols that are not defined",
- action='store_true', default=False)
- parser.add_argument('--undefined-only', dest='undefined_only',
- help="Filter all symbols that are defined",
- action='store_true', default=False)
-
- args = parser.parse_args()
- assert not (args.undefined_only and args.defined_only)
- 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)
- filter = lambda x: x
- if args.defined_only:
- filter = lambda l: list([x for x in l if x['is_defined']])
- if args.undefined_only:
- filter = lambda l: list([x for x in l if not x['is_defined']])
- util.write_syms(syms, out=args.output, names_only=args.names_only, filter=filter)
-
-
-if __name__ == '__main__':
- main()
diff --git a/libcxx/utils/sym_match.py b/libcxx/utils/sym_match.py
deleted file mode 100755
index e1fd28bd6a51..000000000000
--- a/libcxx/utils/sym_match.py
+++ /dev/null
@@ -1,50 +0,0 @@
-#!/usr/bin/env python
-#===----------------------------------------------------------------------===##
-#
-# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-# See https://llvm.org/LICENSE.txt for license information.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-#
-#===----------------------------------------------------------------------===##
-
-"""
-sym_match - Match all symbols in a list against a list of regexes.
-"""
-from argparse import ArgumentParser
-import sys
-from libcxx.sym_check import util, match, extract
-
-
-def main():
- parser = ArgumentParser(
- description='Extract a list of symbols from a shared library.')
- parser.add_argument(
- '--exclusions', dest='exclusions',
- type=str, action='store', default=None)
- parser.add_argument(
- 'symbol_list', metavar='symbol_list', type=str,
- help='The file containing the old symbol list')
- parser.add_argument(
- 'regexes', metavar='regexes', default=[], nargs='*',
- help='The file containing the new symbol list or a library')
- args = parser.parse_args()
-
- if not args.regexes and args.exclusions is None:
- sys.stderr.write('Either a regex or a exclusions must be specified.\n')
- sys.exit(1)
- if args.exclusions:
- search_list = util.read_exclusions(args.exclusions)
- else:
- search_list = args.regexes
-
- symbol_list = util.extract_or_load(args.symbol_list)
-
- matching_count, report = match.find_and_report_matching(
- symbol_list, search_list)
- sys.stdout.write(report)
- if matching_count != 0:
- print('%d matching symbols found...' % matching_count)
-
-
-if __name__ == '__main__':
- main()
More information about the libcxx-commits
mailing list