vcstocl_quirks.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # VCSToChangeLog Quirks for the GNU C Library.
  2. # Copyright (C) 2019-2026 Free Software Foundation, Inc.
  3. #
  4. # The GNU C Library is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU Lesser General Public
  6. # License as published by the Free Software Foundation; either
  7. # version 2.1 of the License, or (at your option) any later version.
  8. #
  9. # The GNU C Library is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # Lesser General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Lesser General Public
  15. # License along with the GNU C Library; if not, see
  16. # <http://www.gnu.org/licenses/>.
  17. from frontend_c import Frontend
  18. from projectquirks import ProjectQuirks
  19. import re
  20. class GlibcProjectQuirks(ProjectQuirks):
  21. repo = 'git'
  22. IGNORE_LIST = [
  23. 'ChangeLog',
  24. 'sysdeps/x86_64/dl-trampoline.h'
  25. ]
  26. MACRO_QUIRKS = \
  27. [{'orig': r'ElfW\((\w+)\)', 'sub': r'\1__ELF_NATIVE_CLASS_t'},
  28. {'orig': r'(libc_freeres_fn)\s*\((\w+)\)', 'sub': r'static void \1__\2 (void)'},
  29. {'orig': r'(IMPL)\s*\((\w+), .*\)$', 'sub': r'static void \1__\2 (void) {}'},
  30. {'orig': r'__(BEGIN|END)_DECLS', 'sub': r''},
  31. {'orig': 'weak_function', 'sub': '__attribute__ ((weak))'},
  32. {'orig': r'ATTRIBUTE_(CONST|MALLOC|PURE|FORMAT)',
  33. 'sub': r'__attribute__ ((\1))'},
  34. {'orig': r'__THROW', 'sub': r'__attribute__ ((__nothrow__ __LEAF))'},
  35. {'orig': r'__THROWNL', 'sub': r'__attribute__ ((__nothrow__))'},
  36. {'orig': r'__nonnull \(\(([^)]+)\)\)',
  37. 'sub': r'__attribute__ ((__nonnull__ \1))'},
  38. {'orig': r'([^_])attribute_(\w+)', 'sub': r'\1__attribute__ ((\2))'},
  39. {'orig': r'^attribute_(\w+)', 'sub': r'__attribute__ ((\1))'}]
  40. def __init__(self, debug):
  41. self.debug = debug
  42. ''' Build a list of macro calls used for symbol versioning and attributes.
  43. glibc uses a set of macro calls that do not end with a semi-colon and hence
  44. breaks our parser. Identify those calls from include/libc-symbols.h and
  45. filter them out.
  46. '''
  47. with open('include/libc-symbols.h') as macrofile:
  48. op = macrofile.readlines()
  49. op = Frontend.remove_comments(self, op)
  50. self.C_MACROS = [re.sub(r'.*define (\w+).*', r'\1', x[:-1]) for x in op \
  51. if 'define ' in x]
  52. super().__init__()
  53. def get_project_quirks(debug):
  54. ''' Accessor function.
  55. '''
  56. return GlibcProjectQuirks(debug)