Skip to content

Commit fbf14e2

Browse files
committed
Add a common wchar_overlay.h header.
1 parent fb05a90 commit fbf14e2

File tree

6 files changed

+58
-84
lines changed

6 files changed

+58
-84
lines changed

libc/hdr/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,14 @@ add_proxy_header_library(
161161
libc.include.sys_auxv
162162
)
163163

164+
add_header_library(wchar_overlay HDRS wchar_overlay.h)
165+
164166
add_proxy_header_library(
165167
wchar_macros
166168
HDRS
167169
wchar_macros.h
170+
DEPENDS
171+
.wchar_overlay
168172
FULL_BUILD_DEPENDS
169173
libc.include.llvm-libc-macros.wchar_macros
170174
libc.include.wchar

libc/hdr/types/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ add_proxy_header_library(
230230
wchar_t
231231
HDRS
232232
wchar_t.h
233+
DEPENDS
234+
libc.hdr.wchar_overlay
233235
FULL_BUILD_DEPENDS
234236
libc.include.llvm-libc-types.wchar_t
235237
libc.include.wchar
@@ -239,6 +241,8 @@ add_proxy_header_library(
239241
wint_t
240242
HDRS
241243
wint_t.h
244+
DEPENDS
245+
libc.hdr.wchar_overlay
242246
FULL_BUILD_DEPENDS
243247
libc.include.llvm-libc-types.wint_t
244248
libc.include.wchar

libc/hdr/types/wchar_t.h

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,7 @@
1616

1717
#else // overlay mode
1818

19-
// glibc <wchar.h header might provide extern inline definitions for few
20-
// functions, causing external alias errors. They are guarded by
21-
// `__USE_EXTERN_INLINES` macro. We temporarily disable `__USE_EXTERN_INLINES`
22-
// macro by defining `__NO_INLINE__` before including <wchar.h>.
23-
// And the same with `__USE_FORTIFY_LEVEL`, which will be temporarily disabled
24-
// with `_FORTIFY_SOURCE`.
25-
26-
#ifdef _FORTIFY_SOURCE
27-
#define LIBC_OLD_FORTIFY_SOURCE _FORTIFY_SOURCE
28-
#undef _FORTIFY_SOURCE
29-
#endif
30-
31-
#ifndef __NO_INLINE__
32-
#define __NO_INLINE__ 1
33-
#define LIBC_SET_NO_INLINE
34-
#endif
35-
36-
#include <wchar.h>
37-
38-
#ifdef LIBC_OLD_FORTIFY_SOURCE
39-
#define _FORTIFY_SOURCE LIBC_OLD_FORTIFY_SOURCE
40-
#undef LIBC_OLD_FORTIFY_SOURCE
41-
#endif
42-
43-
#ifdef LIBC_SET_NO_INLINE
44-
#undef __NO_INLINE__
45-
#undef LIBC_SET_NO_INLINE
46-
#endif
19+
#include "hdr/wchar_overlay.h"
4720

4821
#endif // LLVM_LIBC_FULL_BUILD
4922

libc/hdr/types/wint_t.h

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,7 @@
1616

1717
#else // overlay mode
1818

19-
// glibc <wchar.h header might provide extern inline definitions for few
20-
// functions, causing external alias errors. They are guarded by
21-
// `__USE_EXTERN_INLINES` macro. We temporarily disable `__USE_EXTERN_INLINES`
22-
// macro by defining `__NO_INLINE__` before including <wchar.h>.
23-
// And the same with `__USE_FORTIFY_LEVEL`, which will be temporarily disabled
24-
// with `_FORTIFY_SOURCE`.
25-
26-
#ifdef _FORTIFY_SOURCE
27-
#define LIBC_OLD_FORTIFY_SOURCE _FORTIFY_SOURCE
28-
#undef _FORTIFY_SOURCE
29-
#endif
30-
31-
#ifndef __NO_INLINE__
32-
#define __NO_INLINE__ 1
33-
#define LIBC_SET_NO_INLINE
34-
#endif
35-
36-
#include <wchar.h>
37-
38-
#ifdef LIBC_OLD_FORTIFY_SOURCE
39-
#define _FORTIFY_SOURCE LIBC_OLD_FORTIFY_SOURCE
40-
#undef LIBC_OLD_FORTIFY_SOURCE
41-
#endif
42-
43-
#ifdef LIBC_SET_NO_INLINE
44-
#undef __NO_INLINE__
45-
#undef LIBC_SET_NO_INLINE
46-
#endif
19+
#include "hdr/wchar_overlay.h"
4720

4821
#endif // LLVM_LIBC_FULL_BUILD
4922

libc/hdr/wchar_macros.h

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,7 @@
1515

1616
#else // Overlay mode
1717

18-
// glibc <wchar.h header might provide extern inline definitions for few
19-
// functions, causing external alias errors. They are guarded by
20-
// `__USE_EXTERN_INLINES` macro. We temporarily disable `__USE_EXTERN_INLINES`
21-
// macro by defining `__NO_INLINE__` before including <wchar.h>.
22-
// And the same with `__USE_FORTIFY_LEVEL`, which will be temporarily disabled
23-
// with `_FORTIFY_SOURCE`.
24-
25-
#ifdef _FORTIFY_SOURCE
26-
#define LIBC_OLD_FORTIFY_SOURCE _FORTIFY_SOURCE
27-
#undef _FORTIFY_SOURCE
28-
#endif
29-
30-
#ifndef __NO_INLINE__
31-
#define __NO_INLINE__ 1
32-
#define LIBC_SET_NO_INLINE
33-
#endif
34-
35-
#include <wchar.h>
36-
37-
#ifdef LIBC_OLD_FORTIFY_SOURCE
38-
#define _FORTIFY_SOURCE LIBC_OLD_FORTIFY_SOURCE
39-
#undef LIBC_OLD_FORTIFY_SOURCE
40-
#endif
41-
42-
#ifdef LIBC_SET_NO_INLINE
43-
#undef __NO_INLINE__
44-
#undef LIBC_SET_NO_INLINE
45-
#endif
18+
#include "hdr/wchar_overlay.h"
4619

4720
#endif // LLVM_LIBC_FULL_BUILD
4821

libc/hdr/wchar_overlay.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//===-- Including wchar.h in overlay mode ---------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_HDR_WCHAR_OVERLAY_H
10+
#define LLVM_LIBC_HDR_WCHAR_OVERLAY_H
11+
12+
#ifdef LIBC_FULL_BUILD
13+
#error "This header should only be included in overlay mode"
14+
#endif
15+
16+
// Overlay mode
17+
18+
// glibc <wchar.h header might provide extern inline definitions for few
19+
// functions, causing external alias errors. They are guarded by
20+
// `__USE_EXTERN_INLINES` macro. We temporarily disable `__USE_EXTERN_INLINES`
21+
// macro by defining `__NO_INLINE__` before including <wchar.h>.
22+
// And the same with `__USE_FORTIFY_LEVEL`, which will be temporarily disabled
23+
// with `_FORTIFY_SOURCE`.
24+
25+
#ifdef _FORTIFY_SOURCE
26+
#define LIBC_OLD_FORTIFY_SOURCE _FORTIFY_SOURCE
27+
#undef _FORTIFY_SOURCE
28+
#endif
29+
30+
#ifndef __NO_INLINE__
31+
#define __NO_INLINE__ 1
32+
#define LIBC_SET_NO_INLINE
33+
#endif
34+
35+
#include <wchar.h>
36+
37+
#ifdef LIBC_OLD_FORTIFY_SOURCE
38+
#define _FORTIFY_SOURCE LIBC_OLD_FORTIFY_SOURCE
39+
#undef LIBC_OLD_FORTIFY_SOURCE
40+
#endif
41+
42+
#ifdef LIBC_SET_NO_INLINE
43+
#undef __NO_INLINE__
44+
#undef LIBC_SET_NO_INLINE
45+
#endif
46+
47+
#endif // LLVM_LIBC_HDR_WCHAR_OVERLAY_H

0 commit comments

Comments
 (0)