xref: /aosp_15_r20/external/llvm-libc/hdr/stdio_overlay.h (revision 71db0c75aadcf003ffe3238005f61d7618a3fead)
1*71db0c75SAndroid Build Coastguard Worker //===-- Including stdio.h in overlay mode ---------------------------------===//
2*71db0c75SAndroid Build Coastguard Worker //
3*71db0c75SAndroid Build Coastguard Worker // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*71db0c75SAndroid Build Coastguard Worker // See https://llvm.org/LICENSE.txt for license information.
5*71db0c75SAndroid Build Coastguard Worker // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*71db0c75SAndroid Build Coastguard Worker //
7*71db0c75SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
8*71db0c75SAndroid Build Coastguard Worker 
9*71db0c75SAndroid Build Coastguard Worker #ifndef LLVM_LIBC_HDR_STDIO_OVERLAY_H
10*71db0c75SAndroid Build Coastguard Worker #define LLVM_LIBC_HDR_STDIO_OVERLAY_H
11*71db0c75SAndroid Build Coastguard Worker 
12*71db0c75SAndroid Build Coastguard Worker #ifdef LIBC_FULL_BUILD
13*71db0c75SAndroid Build Coastguard Worker #error "This header should only be included in overlay mode"
14*71db0c75SAndroid Build Coastguard Worker #endif
15*71db0c75SAndroid Build Coastguard Worker 
16*71db0c75SAndroid Build Coastguard Worker // Overlay mode
17*71db0c75SAndroid Build Coastguard Worker 
18*71db0c75SAndroid Build Coastguard Worker // glibc <stdio.h> header might provide extern inline definitions for few
19*71db0c75SAndroid Build Coastguard Worker // functions, causing external alias errors.  They are guarded by
20*71db0c75SAndroid Build Coastguard Worker // `__USE_EXTERN_INLINES` macro.  We temporarily disable `__USE_EXTERN_INLINES`
21*71db0c75SAndroid Build Coastguard Worker // macro by defining `__NO_INLINE__` before including <stdio.h>.
22*71db0c75SAndroid Build Coastguard Worker // And the same with `__USE_FORTIFY_LEVEL`, which will be temporarily disabled
23*71db0c75SAndroid Build Coastguard Worker // with `_FORTIFY_SOURCE`.
24*71db0c75SAndroid Build Coastguard Worker 
25*71db0c75SAndroid Build Coastguard Worker #ifdef _FORTIFY_SOURCE
26*71db0c75SAndroid Build Coastguard Worker #define LIBC_OLD_FORTIFY_SOURCE _FORTIFY_SOURCE
27*71db0c75SAndroid Build Coastguard Worker #undef _FORTIFY_SOURCE
28*71db0c75SAndroid Build Coastguard Worker #endif
29*71db0c75SAndroid Build Coastguard Worker 
30*71db0c75SAndroid Build Coastguard Worker #ifdef __USE_EXTERN_INLINES
31*71db0c75SAndroid Build Coastguard Worker #define LIBC_OLD_USE_EXTERN_INLINES
32*71db0c75SAndroid Build Coastguard Worker #undef __USE_EXTERN_INLINES
33*71db0c75SAndroid Build Coastguard Worker #endif
34*71db0c75SAndroid Build Coastguard Worker 
35*71db0c75SAndroid Build Coastguard Worker #ifdef __USE_FORTIFY_LEVEL
36*71db0c75SAndroid Build Coastguard Worker #define LIBC_OLD_USE_FORTIFY_LEVEL __USE_FORTIFY_LEVEL
37*71db0c75SAndroid Build Coastguard Worker #undef __USE_FORTIFY_LEVEL
38*71db0c75SAndroid Build Coastguard Worker #define __USE_FORTIFY_LEVEL 0
39*71db0c75SAndroid Build Coastguard Worker #endif
40*71db0c75SAndroid Build Coastguard Worker 
41*71db0c75SAndroid Build Coastguard Worker #ifndef __NO_INLINE__
42*71db0c75SAndroid Build Coastguard Worker #define __NO_INLINE__ 1
43*71db0c75SAndroid Build Coastguard Worker #define LIBC_SET_NO_INLINE
44*71db0c75SAndroid Build Coastguard Worker #endif
45*71db0c75SAndroid Build Coastguard Worker 
46*71db0c75SAndroid Build Coastguard Worker #include <stdio.h>
47*71db0c75SAndroid Build Coastguard Worker 
48*71db0c75SAndroid Build Coastguard Worker #ifdef LIBC_OLD_FORTIFY_SOURCE
49*71db0c75SAndroid Build Coastguard Worker #define _FORTIFY_SOURCE LIBC_OLD_FORTIFY_SOURCE
50*71db0c75SAndroid Build Coastguard Worker #undef LIBC_OLD_FORTIFY_SOURCE
51*71db0c75SAndroid Build Coastguard Worker #endif
52*71db0c75SAndroid Build Coastguard Worker 
53*71db0c75SAndroid Build Coastguard Worker #ifdef LIBC_SET_NO_INLINE
54*71db0c75SAndroid Build Coastguard Worker #undef __NO_INLINE__
55*71db0c75SAndroid Build Coastguard Worker #undef LIBC_SET_NO_INLINE
56*71db0c75SAndroid Build Coastguard Worker #endif
57*71db0c75SAndroid Build Coastguard Worker 
58*71db0c75SAndroid Build Coastguard Worker #ifdef LIBC_OLD_USE_FORTIFY_LEVEL
59*71db0c75SAndroid Build Coastguard Worker #undef __USE_FORTIFY_LEVEL
60*71db0c75SAndroid Build Coastguard Worker #define __USE_FORTIFY_LEVEL LIBC_OLD_USE_FORTIFY_LEVEL
61*71db0c75SAndroid Build Coastguard Worker #undef LIBC_OLD_USE_FORTIFY_LEVEL
62*71db0c75SAndroid Build Coastguard Worker #endif
63*71db0c75SAndroid Build Coastguard Worker 
64*71db0c75SAndroid Build Coastguard Worker #ifdef LIBC_OLD_USE_EXTERN_INLINES
65*71db0c75SAndroid Build Coastguard Worker #define __USE_EXTERN_INLINES
66*71db0c75SAndroid Build Coastguard Worker #undef LIBC_OLD_USE_EXTERN_INLINES
67*71db0c75SAndroid Build Coastguard Worker #endif
68*71db0c75SAndroid Build Coastguard Worker 
69*71db0c75SAndroid Build Coastguard Worker #endif // LLVM_LIBC_HDR_STDIO_OVERLAY_H
70