list-header-symbols.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/python
  2. # Print a list of symbols exported by some headers that would
  3. # otherwise be in the user's namespace.
  4. # Copyright (C) 2018-2019 Free Software Foundation, Inc.
  5. # This file is part of the GNU C Library.
  6. #
  7. # The GNU C Library is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU Lesser General Public
  9. # License as published by the Free Software Foundation; either
  10. # version 2.1 of the License, or (at your option) any later version.
  11. #
  12. # The GNU C Library is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. # Lesser General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Lesser General Public
  18. # License along with the GNU C Library; if not, see
  19. # <http://www.gnu.org/licenses/>.
  20. import argparse
  21. import glibcconform
  22. # Extra symbols possibly not found through -aux-info but still
  23. # reserved by the standard: either data symbols, or symbols where the
  24. # standard leaves unspecified whether the identifier is a macro or
  25. # defined with external linkage.
  26. EXTRA_SYMS = {}
  27. EXTRA_SYMS['ISO'] = {'errno', 'setjmp', 'va_end'}
  28. EXTRA_SYMS['ISO99'] = EXTRA_SYMS['ISO'] | {'math_errhandling'}
  29. # stdatomic.h not yet covered by conformance tests; as per DR#419, all
  30. # the generic functions there or may not be defined with external
  31. # linkage (but are reserved in any case).
  32. EXTRA_SYMS['ISO11'] = EXTRA_SYMS['ISO99']
  33. # The following lists may not be exhaustive.
  34. EXTRA_SYMS['POSIX'] = (EXTRA_SYMS['ISO']
  35. | {'environ', 'sigsetjmp', 'optarg', 'optind', 'opterr',
  36. 'optopt', 'tzname'})
  37. EXTRA_SYMS['XPG4'] = (EXTRA_SYMS['POSIX']
  38. | {'signgam', 'loc1', 'loc2', 'locs', 'daylight',
  39. 'timezone'})
  40. EXTRA_SYMS['XPG42'] = EXTRA_SYMS['XPG4'] | {'getdate_err', 'h_errno'}
  41. EXTRA_SYMS['UNIX98'] = EXTRA_SYMS['XPG42']
  42. EXTRA_SYMS['XOPEN2K'] = (EXTRA_SYMS['POSIX']
  43. | {'signgam', 'daylight', 'timezone', 'getdate_err',
  44. 'h_errno', 'in6addr_any', 'in6addr_loopback'})
  45. EXTRA_SYMS['POSIX2008'] = (EXTRA_SYMS['POSIX']
  46. | {'in6addr_any', 'in6addr_loopback'})
  47. EXTRA_SYMS['XOPEN2K8'] = (EXTRA_SYMS['POSIX2008']
  48. | {'signgam', 'daylight', 'timezone', 'getdate_err'})
  49. def main():
  50. """The main entry point."""
  51. parser = argparse.ArgumentParser(description='List exported symbols.')
  52. parser.add_argument('--headers', metavar='HEADERS',
  53. help='list of headers')
  54. parser.add_argument('--standard', metavar='STD',
  55. help='standard to use when processing headers')
  56. parser.add_argument('--cc', metavar='CC',
  57. help='C compiler to use')
  58. parser.add_argument('--flags', metavar='CFLAGS',
  59. help='Compiler flags to use with CC')
  60. args = parser.parse_args()
  61. fns = set()
  62. compiler = '%s %s' % (args.cc, args.flags)
  63. for header in args.headers.split():
  64. fns |= glibcconform.list_exported_functions(compiler, args.standard,
  65. header)
  66. fns |= EXTRA_SYMS[args.standard]
  67. print('\n'.join(sorted(fn for fn in fns if not fn.startswith('_'))))
  68. if __name__ == '__main__':
  69. main()