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