xref: /aosp_15_r20/bionic/libc/kernel/tools/defaults.py (revision 8d67ca893c1523eb926b9080dbe4e2ffd2a27ba1)
1*8d67ca89SAndroid Build Coastguard Worker# All the defaults used to generate the cleaned-up uapi headers for bionic.
2*8d67ca89SAndroid Build Coastguard Worker
3*8d67ca89SAndroid Build Coastguard Worker# the list of include directories that belong to the kernel
4*8d67ca89SAndroid Build Coastguard Worker# tree. used when looking for sources...
5*8d67ca89SAndroid Build Coastguard Workerkernel_dirs = [ "linux", "asm", "asm-generic", "mtd" ]
6*8d67ca89SAndroid Build Coastguard Worker
7*8d67ca89SAndroid Build Coastguard Worker# a special value that is used to indicate that a given macro is known to be
8*8d67ca89SAndroid Build Coastguard Worker# undefined during optimization
9*8d67ca89SAndroid Build Coastguard WorkerkCppUndefinedMacro = "<<<undefined>>>"
10*8d67ca89SAndroid Build Coastguard Worker
11*8d67ca89SAndroid Build Coastguard Worker# this is the set of known macros we want to totally optimize out from the
12*8d67ca89SAndroid Build Coastguard Worker# final headers
13*8d67ca89SAndroid Build Coastguard Workerkernel_known_macros = {
14*8d67ca89SAndroid Build Coastguard Worker    "__KERNEL__": kCppUndefinedMacro,
15*8d67ca89SAndroid Build Coastguard Worker    "__KERNEL_STRICT_NAMES":"1",
16*8d67ca89SAndroid Build Coastguard Worker    "__CHECKER__": kCppUndefinedMacro,
17*8d67ca89SAndroid Build Coastguard Worker    "__CHECK_ENDIAN__": kCppUndefinedMacro,
18*8d67ca89SAndroid Build Coastguard Worker    "CONFIG_64BIT": "__LP64__",
19*8d67ca89SAndroid Build Coastguard Worker    "CONFIG_X86_32": "__i386__",
20*8d67ca89SAndroid Build Coastguard Worker    "__EXPORTED_HEADERS__": "1",
21*8d67ca89SAndroid Build Coastguard Worker    "__HAVE_BUILTIN_BSWAP16__": "1",
22*8d67ca89SAndroid Build Coastguard Worker    "__HAVE_BUILTIN_BSWAP32__": "1",
23*8d67ca89SAndroid Build Coastguard Worker    "__HAVE_BUILTIN_BSWAP64__": "1",
24*8d67ca89SAndroid Build Coastguard Worker    # Use this to remove the struct __kernel_old_timeval definition.
25*8d67ca89SAndroid Build Coastguard Worker    # Otherwise, there will be two struct timeval definitions when
26*8d67ca89SAndroid Build Coastguard Worker    # __kernel_old_timeval is renamed to timeval.
27*8d67ca89SAndroid Build Coastguard Worker    "__kernel_old_timeval": "1",
28*8d67ca89SAndroid Build Coastguard Worker    # Drop the custom byte swap functions and just use the clang builtins.
29*8d67ca89SAndroid Build Coastguard Worker    # https://github.com/android/ndk/issues/2107
30*8d67ca89SAndroid Build Coastguard Worker    "__arch_swab16": kCppUndefinedMacro,
31*8d67ca89SAndroid Build Coastguard Worker    "__arch_swab16p": kCppUndefinedMacro,
32*8d67ca89SAndroid Build Coastguard Worker    "__arch_swab16s": kCppUndefinedMacro,
33*8d67ca89SAndroid Build Coastguard Worker    "__arch_swab32": kCppUndefinedMacro,
34*8d67ca89SAndroid Build Coastguard Worker    "__arch_swab32p": kCppUndefinedMacro,
35*8d67ca89SAndroid Build Coastguard Worker    "__arch_swab32s": kCppUndefinedMacro,
36*8d67ca89SAndroid Build Coastguard Worker    "__arch_swab64": kCppUndefinedMacro,
37*8d67ca89SAndroid Build Coastguard Worker    "__arch_swab64p": kCppUndefinedMacro,
38*8d67ca89SAndroid Build Coastguard Worker    "__arch_swab64s": kCppUndefinedMacro,
39*8d67ca89SAndroid Build Coastguard Worker    "__arch_swahb32": kCppUndefinedMacro,
40*8d67ca89SAndroid Build Coastguard Worker    "__arch_swahb32p": kCppUndefinedMacro,
41*8d67ca89SAndroid Build Coastguard Worker    "__arch_swahb32s": kCppUndefinedMacro,
42*8d67ca89SAndroid Build Coastguard Worker    "__arch_swahw32": kCppUndefinedMacro,
43*8d67ca89SAndroid Build Coastguard Worker    "__arch_swahw32p": kCppUndefinedMacro,
44*8d67ca89SAndroid Build Coastguard Worker    "__arch_swahw32s": kCppUndefinedMacro,
45*8d67ca89SAndroid Build Coastguard Worker    }
46*8d67ca89SAndroid Build Coastguard Worker
47*8d67ca89SAndroid Build Coastguard Worker# This is the set of known kernel data structures we want to remove from
48*8d67ca89SAndroid Build Coastguard Worker# the final headers. If the map value is non-empty, that means that in
49*8d67ca89SAndroid Build Coastguard Worker# addition to removing the structure, add a #include to the file.
50*8d67ca89SAndroid Build Coastguard Workerkernel_structs_to_remove = {
51*8d67ca89SAndroid Build Coastguard Worker    # Remove these structures since they are still the same as
52*8d67ca89SAndroid Build Coastguard Worker    # timeval, itimerval. Also, add an include of linux/time.h
53*8d67ca89SAndroid Build Coastguard Worker    # since __kernel_old_timeval is being changed to timeval, and
54*8d67ca89SAndroid Build Coastguard Worker    # is only present in linux/time.h.
55*8d67ca89SAndroid Build Coastguard Worker    "__kernel_old_timeval": "linux/time.h",
56*8d67ca89SAndroid Build Coastguard Worker    "__kernel_old_itimerval": None,
57*8d67ca89SAndroid Build Coastguard Worker    # Replace all of the below structures with #include <bits/STRUCT.h>
58*8d67ca89SAndroid Build Coastguard Worker    "__kernel_sockaddr_storage": "bits/sockaddr_storage.h",
59*8d67ca89SAndroid Build Coastguard Worker    "epoll_event": "bits/epoll_event.h",
60*8d67ca89SAndroid Build Coastguard Worker    "flock": "bits/flock.h",
61*8d67ca89SAndroid Build Coastguard Worker    "flock64": "bits/flock64.h",
62*8d67ca89SAndroid Build Coastguard Worker    "in_addr": "bits/in_addr.h",
63*8d67ca89SAndroid Build Coastguard Worker    "ip_mreq_source": "bits/ip_mreq_source.h",
64*8d67ca89SAndroid Build Coastguard Worker    "ip_msfilter": "bits/ip_msfilter.h",
65*8d67ca89SAndroid Build Coastguard Worker    "tcphdr": "bits/tcphdr.h",
66*8d67ca89SAndroid Build Coastguard Worker    "timespec": "bits/timespec.h",
67*8d67ca89SAndroid Build Coastguard Worker    }
68*8d67ca89SAndroid Build Coastguard Worker
69*8d67ca89SAndroid Build Coastguard Worker# define to true if you want to remove all defined(CONFIG_FOO) tests
70*8d67ca89SAndroid Build Coastguard Worker# from the clean headers. testing shows that this is not strictly necessary
71*8d67ca89SAndroid Build Coastguard Worker# but just generates cleaner results
72*8d67ca89SAndroid Build Coastguard Workerkernel_remove_config_macros = True
73*8d67ca89SAndroid Build Coastguard Worker
74*8d67ca89SAndroid Build Coastguard Worker# Maps an architecture to a set of default macros that would be provided by
75*8d67ca89SAndroid Build Coastguard Worker# the toolchain's preprocessor. Currently only used to remove confusing
76*8d67ca89SAndroid Build Coastguard Worker# big-endian junk from the 32-bit arm headers.
77*8d67ca89SAndroid Build Coastguard Workerkernel_default_arch_macros = {
78*8d67ca89SAndroid Build Coastguard Worker    "arm": {"__ARMEB__": kCppUndefinedMacro, "__ARM_EABI__": "1"},
79*8d67ca89SAndroid Build Coastguard Worker    }
80*8d67ca89SAndroid Build Coastguard Worker
81*8d67ca89SAndroid Build Coastguard Worker# Replace tokens in the output according to this mapping.
82*8d67ca89SAndroid Build Coastguard Workerkernel_token_replacements = {
83*8d67ca89SAndroid Build Coastguard Worker    # The kernel usage of __unused for unused struct fields conflicts with the macro defined in <sys/cdefs.h>.
84*8d67ca89SAndroid Build Coastguard Worker    "__unused": "__linux_unused",
85*8d67ca89SAndroid Build Coastguard Worker    # The kernel usage of C++ keywords causes problems for C++ code so rename.
86*8d67ca89SAndroid Build Coastguard Worker    "class": "__linux_class",
87*8d67ca89SAndroid Build Coastguard Worker    "private": "__linux_private",
88*8d67ca89SAndroid Build Coastguard Worker    "virtual": "__linux_virtual",
89*8d67ca89SAndroid Build Coastguard Worker    # The non-64 stuff is legacy; msqid64_ds/ipc64_perm is what userspace wants.
90*8d67ca89SAndroid Build Coastguard Worker    "msqid_ds": "__kernel_legacy_msqid_ds",
91*8d67ca89SAndroid Build Coastguard Worker    "semid_ds": "__kernel_legacy_semid_ds",
92*8d67ca89SAndroid Build Coastguard Worker    "shmid_ds": "__kernel_legacy_shmid_ds",
93*8d67ca89SAndroid Build Coastguard Worker    "ipc_perm": "__kernel_legacy_ipc_perm",
94*8d67ca89SAndroid Build Coastguard Worker    # The kernel semun isn't usable (https://github.com/android-ndk/ndk/issues/400).
95*8d67ca89SAndroid Build Coastguard Worker    "semun": "__kernel_legacy_semun",
96*8d67ca89SAndroid Build Coastguard Worker    # The kernel's _NSIG/NSIG are one less than the userspace value, so we need to move them aside.
97*8d67ca89SAndroid Build Coastguard Worker    "_NSIG": "_KERNEL__NSIG",
98*8d67ca89SAndroid Build Coastguard Worker    "NSIG": "_KERNEL_NSIG",
99*8d67ca89SAndroid Build Coastguard Worker    # The kernel's SIGRTMIN/SIGRTMAX are absolute limits; userspace steals a few.
100*8d67ca89SAndroid Build Coastguard Worker    "SIGRTMIN": "__SIGRTMIN",
101*8d67ca89SAndroid Build Coastguard Worker    "SIGRTMAX": "__SIGRTMAX",
102*8d67ca89SAndroid Build Coastguard Worker    # We want to support both BSD and Linux member names in struct udphdr.
103*8d67ca89SAndroid Build Coastguard Worker    "udphdr": "__kernel_udphdr",
104*8d67ca89SAndroid Build Coastguard Worker    # This causes problems when trying to export the headers for the ndk.
105*8d67ca89SAndroid Build Coastguard Worker    "__attribute_const__": "__attribute__((__const__))",
106*8d67ca89SAndroid Build Coastguard Worker    # The kernel started using struct __kernel_old_timeval in some places,
107*8d67ca89SAndroid Build Coastguard Worker    # which is the exact same as struct timeval. Replace that name with
108*8d67ca89SAndroid Build Coastguard Worker    # timeval so that kernel structures all use the same named structure.
109*8d67ca89SAndroid Build Coastguard Worker    # If struct __kernel_old_timeval and struct timeval become different,
110*8d67ca89SAndroid Build Coastguard Worker    # then a different solution needs to be implemented.
111*8d67ca89SAndroid Build Coastguard Worker    "__kernel_old_timeval": "timeval",
112*8d67ca89SAndroid Build Coastguard Worker    # Do the same for __kernel_old_itimerval as for timeval.
113*8d67ca89SAndroid Build Coastguard Worker    "__kernel_old_itimerval": "itimerval",
114*8d67ca89SAndroid Build Coastguard Worker    # Do the same for __kernel_sockaddr_storage.
115*8d67ca89SAndroid Build Coastguard Worker    "__kernel_sockaddr_storage": "sockaddr_storage",
116*8d67ca89SAndroid Build Coastguard Worker    # Replace __packed with __attribute__((__packed__)) to avoid depending
117*8d67ca89SAndroid Build Coastguard Worker    # on sys/cdefs.h
118*8d67ca89SAndroid Build Coastguard Worker    "__packed": "__attribute__((__packed__))",
119*8d67ca89SAndroid Build Coastguard Worker    # Remove unused macros (http://b/262917450).
120*8d67ca89SAndroid Build Coastguard Worker    "__force": "",
121*8d67ca89SAndroid Build Coastguard Worker    "__user": "",
122*8d67ca89SAndroid Build Coastguard Worker    # Rename the kernel's sigaction so we can expose our POSIX one publicly,
123*8d67ca89SAndroid Build Coastguard Worker    # but translate to the kernel's one internally.
124*8d67ca89SAndroid Build Coastguard Worker    "sigaction": "__kernel_sigaction",
125*8d67ca89SAndroid Build Coastguard Worker    }
126*8d67ca89SAndroid Build Coastguard Worker
127*8d67ca89SAndroid Build Coastguard Worker
128*8d67ca89SAndroid Build Coastguard Worker# Static inline functions that we want to keep.
129*8d67ca89SAndroid Build Coastguard Workerkernel_known_generic_statics = set(
130*8d67ca89SAndroid Build Coastguard Worker        [
131*8d67ca89SAndroid Build Coastguard Worker          "ipt_get_target",  # uapi/linux/netfilter_ipv4/ip_tables.h
132*8d67ca89SAndroid Build Coastguard Worker          "ip6t_get_target", # uapi/linux/netfilter_ipv6/ip6_tables.h
133*8d67ca89SAndroid Build Coastguard Worker          # Byte swapping inlines from uapi/linux/swab.h
134*8d67ca89SAndroid Build Coastguard Worker          # The below functions are the ones we are guaranting we export.
135*8d67ca89SAndroid Build Coastguard Worker          "__swab16",
136*8d67ca89SAndroid Build Coastguard Worker          "__swab32",
137*8d67ca89SAndroid Build Coastguard Worker          "__swab64",
138*8d67ca89SAndroid Build Coastguard Worker          "__swab16p",
139*8d67ca89SAndroid Build Coastguard Worker          "__swab32p",
140*8d67ca89SAndroid Build Coastguard Worker          "__swab64p",
141*8d67ca89SAndroid Build Coastguard Worker          "__swab16s",
142*8d67ca89SAndroid Build Coastguard Worker          "__swab32s",
143*8d67ca89SAndroid Build Coastguard Worker          "__swab64s",
144*8d67ca89SAndroid Build Coastguard Worker          "__swahw32",
145*8d67ca89SAndroid Build Coastguard Worker          "__swahb32",
146*8d67ca89SAndroid Build Coastguard Worker          "__swahw32p",
147*8d67ca89SAndroid Build Coastguard Worker          "__swahb32p",
148*8d67ca89SAndroid Build Coastguard Worker          "__swahw32s",
149*8d67ca89SAndroid Build Coastguard Worker          "__swahb32s",
150*8d67ca89SAndroid Build Coastguard Worker          # These are required to support the above functions.
151*8d67ca89SAndroid Build Coastguard Worker          "__fswahw32",
152*8d67ca89SAndroid Build Coastguard Worker          "__fswahb32",
153*8d67ca89SAndroid Build Coastguard Worker          # This is used by various macros in <linux/ioprio.h>.
154*8d67ca89SAndroid Build Coastguard Worker          "ioprio_value",
155*8d67ca89SAndroid Build Coastguard Worker
156*8d67ca89SAndroid Build Coastguard Worker          # Contact opensource-licensing@ before adding to this set.
157*8d67ca89SAndroid Build Coastguard Worker        ]
158*8d67ca89SAndroid Build Coastguard Worker    )
159