Skip to content

Commit

Permalink
Add a common wchar_overlay.h header.
Browse files Browse the repository at this point in the history
  • Loading branch information
lntue committed Sep 19, 2024
1 parent ee996b1 commit 88c8f4d
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 84 deletions.
4 changes: 4 additions & 0 deletions libc/hdr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,14 @@ add_proxy_header_library(
libc.include.sys_auxv
)

add_header_library(wchar_overlay HDRS wchar_overlay.h)

add_proxy_header_library(
wchar_macros
HDRS
wchar_macros.h
DEPENDS
.wchar_overlay
FULL_BUILD_DEPENDS
libc.include.llvm-libc-macros.wchar_macros
libc.include.wchar
Expand Down
4 changes: 4 additions & 0 deletions libc/hdr/types/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ add_proxy_header_library(
wchar_t
HDRS
wchar_t.h
DEPENDS
libc.hdr.wchar_overlay
FULL_BUILD_DEPENDS
libc.include.llvm-libc-types.wchar_t
libc.include.wchar
Expand All @@ -212,6 +214,8 @@ add_proxy_header_library(
wint_t
HDRS
wint_t.h
DEPENDS
libc.hdr.wchar_overlay
FULL_BUILD_DEPENDS
libc.include.llvm-libc-types.wint_t
libc.include.wchar
Expand Down
29 changes: 1 addition & 28 deletions libc/hdr/types/wchar_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,7 @@

#else // overlay mode

// glibc <wchar.h header might provide extern inline definitions for few
// functions, causing external alias errors. They are guarded by
// `__USE_EXTERN_INLINES` macro. We temporarily disable `__USE_EXTERN_INLINES`
// macro by defining `__NO_INLINE__` before including <wchar.h>.
// And the same with `__USE_FORTIFY_LEVEL`, which will be temporarily disabled
// with `_FORTIFY_SOURCE`.

#ifdef _FORTIFY_SOURCE
#define LIBC_OLD_FORTIFY_SOURCE _FORTIFY_SOURCE
#undef _FORTIFY_SOURCE
#endif

#ifndef __NO_INLINE__
#define __NO_INLINE__ 1
#define LIBC_SET_NO_INLINE
#endif

#include <wchar.h>

#ifdef LIBC_OLD_FORTIFY_SOURCE
#define _FORTIFY_SOURCE LIBC_OLD_FORTIFY_SOURCE
#undef LIBC_OLD_FORTIFY_SOURCE
#endif

#ifdef LIBC_SET_NO_INLINE
#undef __NO_INLINE__
#undef LIBC_SET_NO_INLINE
#endif
#include "hdr/wchar_overlay.h"

#endif // LLVM_LIBC_FULL_BUILD

Expand Down
29 changes: 1 addition & 28 deletions libc/hdr/types/wint_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,7 @@

#else // overlay mode

// glibc <wchar.h header might provide extern inline definitions for few
// functions, causing external alias errors. They are guarded by
// `__USE_EXTERN_INLINES` macro. We temporarily disable `__USE_EXTERN_INLINES`
// macro by defining `__NO_INLINE__` before including <wchar.h>.
// And the same with `__USE_FORTIFY_LEVEL`, which will be temporarily disabled
// with `_FORTIFY_SOURCE`.

#ifdef _FORTIFY_SOURCE
#define LIBC_OLD_FORTIFY_SOURCE _FORTIFY_SOURCE
#undef _FORTIFY_SOURCE
#endif

#ifndef __NO_INLINE__
#define __NO_INLINE__ 1
#define LIBC_SET_NO_INLINE
#endif

#include <wchar.h>

#ifdef LIBC_OLD_FORTIFY_SOURCE
#define _FORTIFY_SOURCE LIBC_OLD_FORTIFY_SOURCE
#undef LIBC_OLD_FORTIFY_SOURCE
#endif

#ifdef LIBC_SET_NO_INLINE
#undef __NO_INLINE__
#undef LIBC_SET_NO_INLINE
#endif
#include "hdr/wchar_overlay.h"

#endif // LLVM_LIBC_FULL_BUILD

Expand Down
29 changes: 1 addition & 28 deletions libc/hdr/wchar_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,7 @@

#else // Overlay mode

// glibc <wchar.h header might provide extern inline definitions for few
// functions, causing external alias errors. They are guarded by
// `__USE_EXTERN_INLINES` macro. We temporarily disable `__USE_EXTERN_INLINES`
// macro by defining `__NO_INLINE__` before including <wchar.h>.
// And the same with `__USE_FORTIFY_LEVEL`, which will be temporarily disabled
// with `_FORTIFY_SOURCE`.

#ifdef _FORTIFY_SOURCE
#define LIBC_OLD_FORTIFY_SOURCE _FORTIFY_SOURCE
#undef _FORTIFY_SOURCE
#endif

#ifndef __NO_INLINE__
#define __NO_INLINE__ 1
#define LIBC_SET_NO_INLINE
#endif

#include <wchar.h>

#ifdef LIBC_OLD_FORTIFY_SOURCE
#define _FORTIFY_SOURCE LIBC_OLD_FORTIFY_SOURCE
#undef LIBC_OLD_FORTIFY_SOURCE
#endif

#ifdef LIBC_SET_NO_INLINE
#undef __NO_INLINE__
#undef LIBC_SET_NO_INLINE
#endif
#include "hdr/wchar_overlay.h"

#endif // LLVM_LIBC_FULL_BUILD

Expand Down
47 changes: 47 additions & 0 deletions libc/hdr/wchar_overlay.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//===-- Including wchar.h in overlay mode ---------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_HDR_WCHAR_OVERLAY_H
#define LLVM_LIBC_HDR_WCHAR_OVERLAY_H

#ifdef LIBC_FULL_BUILD
#error "This header should only be included in overlay mode"
#endif

// Overlay mode

// glibc <wchar.h header might provide extern inline definitions for few
// functions, causing external alias errors. They are guarded by
// `__USE_EXTERN_INLINES` macro. We temporarily disable `__USE_EXTERN_INLINES`
// macro by defining `__NO_INLINE__` before including <wchar.h>.
// And the same with `__USE_FORTIFY_LEVEL`, which will be temporarily disabled
// with `_FORTIFY_SOURCE`.

#ifdef _FORTIFY_SOURCE
#define LIBC_OLD_FORTIFY_SOURCE _FORTIFY_SOURCE
#undef _FORTIFY_SOURCE
#endif

#ifndef __NO_INLINE__
#define __NO_INLINE__ 1
#define LIBC_SET_NO_INLINE
#endif

#include <wchar.h>

#ifdef LIBC_OLD_FORTIFY_SOURCE
#define _FORTIFY_SOURCE LIBC_OLD_FORTIFY_SOURCE
#undef LIBC_OLD_FORTIFY_SOURCE
#endif

#ifdef LIBC_SET_NO_INLINE
#undef __NO_INLINE__
#undef LIBC_SET_NO_INLINE
#endif

#endif // LLVM_LIBC_HDR_WCHAR_OVERLAY_H

0 comments on commit 88c8f4d

Please sign in to comment.