Skip to content

Commit 28682ec

Browse files
[libc] Add unistd overlay
1 parent 0adff0a commit 28682ec

33 files changed

+104
-32
lines changed

libc/hdr/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,13 @@ add_proxy_header_library(
126126
libc.include.llvm-libc-macros.sys_stat_macros
127127
)
128128

129+
add_header_library(unistd_overlay HDRS unistd_overlay.h)
129130
add_proxy_header_library(
130131
unistd_macros
131132
HDRS
132133
unistd_macros.h
134+
DEPENDS
135+
.unistd_overlay
133136
FULL_BUILD_DEPENDS
134137
libc.include.unistd
135138
libc.include.llvm-libc-macros.unistd_macros

libc/hdr/unistd_macros.h

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

1616
#else // Overlay mode
1717

18-
#include <unistd.h>
18+
#include "unistd_overlay.h"
1919

2020
#endif // LLVM_LIBC_FULL_BUILD
2121

libc/hdr/unistd_overlay.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//===-- Including unistd.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_UNISTD_OVERLAY_H
10+
#define LLVM_LIBC_HDR_UNISTD_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 <unistd.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 <stdio.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+
#ifdef __USE_EXTERN_INLINES
31+
#define LIBC_OLD_USE_EXTERN_INLINES
32+
#undef __USE_EXTERN_INLINES
33+
#endif
34+
35+
#ifdef __USE_FORTIFY_LEVEL
36+
#define LIBC_OLD_USE_FORTIFY_LEVEL __USE_FORTIFY_LEVEL
37+
#undef __USE_FORTIFY_LEVEL
38+
#define __USE_FORTIFY_LEVEL 0
39+
#endif
40+
41+
#ifndef __NO_INLINE__
42+
#define __NO_INLINE__ 1
43+
#define LIBC_SET_NO_INLINE
44+
#endif
45+
46+
#include <unistd.h>
47+
48+
#ifdef LIBC_OLD_FORTIFY_SOURCE
49+
#define _FORTIFY_SOURCE LIBC_OLD_FORTIFY_SOURCE
50+
#undef LIBC_OLD_FORTIFY_SOURCE
51+
#endif
52+
53+
#ifdef LIBC_SET_NO_INLINE
54+
#undef __NO_INLINE__
55+
#undef LIBC_SET_NO_INLINE
56+
#endif
57+
58+
#ifdef LIBC_OLD_USE_FORTIFY_LEVEL
59+
#undef __USE_FORTIFY_LEVEL
60+
#define __USE_FORTIFY_LEVEL LIBC_OLD_USE_FORTIFY_LEVEL
61+
#undef LIBC_OLD_USE_FORTIFY_LEVEL
62+
#endif
63+
64+
#ifdef LIBC_OLD_USE_EXTERN_INLINES
65+
#define __USE_EXTERN_INLINES
66+
#undef LIBC_OLD_USE_EXTERN_INLINES
67+
#endif
68+
69+
#endif // LLVM_LIBC_HDR_UNISTD_OVERLAY_H

libc/src/unistd/dup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#ifndef LLVM_LIBC_SRC_UNISTD_DUP_H
1010
#define LLVM_LIBC_SRC_UNISTD_DUP_H
1111

12+
#include "hdr/unistd_macros.h"
1213
#include "src/__support/macros/config.h"
13-
#include <unistd.h>
1414

1515
namespace LIBC_NAMESPACE_DECL {
1616

libc/src/unistd/dup2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#ifndef LLVM_LIBC_SRC_UNISTD_DUP2_H
1010
#define LLVM_LIBC_SRC_UNISTD_DUP2_H
1111

12+
#include "hdr/unistd_macros.h"
1213
#include "src/__support/macros/config.h"
13-
#include <unistd.h>
1414

1515
namespace LIBC_NAMESPACE_DECL {
1616

libc/src/unistd/dup3.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#ifndef LLVM_LIBC_SRC_UNISTD_DUP3_H
1010
#define LLVM_LIBC_SRC_UNISTD_DUP3_H
1111

12+
#include "hdr/unistd_macros.h"
1213
#include "src/__support/macros/config.h"
13-
#include <unistd.h>
1414

1515
namespace LIBC_NAMESPACE_DECL {
1616

libc/src/unistd/fork.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#ifndef LLVM_LIBC_SRC_UNISTD_FORK_H
1010
#define LLVM_LIBC_SRC_UNISTD_FORK_H
1111

12+
#include "hdr/unistd_macros.h"
1213
#include "src/__support/macros/config.h"
13-
#include <unistd.h>
1414

1515
namespace LIBC_NAMESPACE_DECL {
1616

libc/src/unistd/ftruncate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#ifndef LLVM_LIBC_SRC_UNISTD_FTRUNCATE_H
1010
#define LLVM_LIBC_SRC_UNISTD_FTRUNCATE_H
1111

12+
#include "hdr/unistd_macros.h"
1213
#include "src/__support/macros/config.h"
13-
#include <unistd.h>
1414

1515
namespace LIBC_NAMESPACE_DECL {
1616

libc/src/unistd/getcwd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#ifndef LLVM_LIBC_SRC_UNISTD_GETCWD_H
1010
#define LLVM_LIBC_SRC_UNISTD_GETCWD_H
1111

12+
#include "hdr/unistd_macros.h"
1213
#include "src/__support/macros/config.h"
13-
#include <unistd.h>
1414

1515
namespace LIBC_NAMESPACE_DECL {
1616

libc/src/unistd/geteuid.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#ifndef LLVM_LIBC_SRC_UNISTD_GETEUID_H
1010
#define LLVM_LIBC_SRC_UNISTD_GETEUID_H
1111

12+
#include "hdr/unistd_macros.h"
1213
#include "src/__support/macros/config.h"
13-
#include <unistd.h>
1414

1515
namespace LIBC_NAMESPACE_DECL {
1616

libc/src/unistd/getopt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#define LLVM_LIBC_SRC_UNISTD_GETOPT_H
1111

1212
#include "hdr/types/FILE.h"
13+
#include "hdr/unistd_macros.h"
1314
#include "src/__support/macros/config.h"
14-
#include <unistd.h>
1515

1616
namespace LIBC_NAMESPACE_DECL {
1717

libc/src/unistd/getpid.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#ifndef LLVM_LIBC_SRC_UNISTD_GETPID_H
1010
#define LLVM_LIBC_SRC_UNISTD_GETPID_H
1111

12+
#include "hdr/unistd_macros.h"
1213
#include "src/__support/macros/config.h"
13-
#include <unistd.h>
1414

1515
namespace LIBC_NAMESPACE_DECL {
1616

libc/src/unistd/getppid.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#ifndef LLVM_LIBC_SRC_UNISTD_GETPPID_H
1010
#define LLVM_LIBC_SRC_UNISTD_GETPPID_H
1111

12+
#include "hdr/unistd_macros.h"
1213
#include "src/__support/macros/config.h"
13-
#include <unistd.h>
1414

1515
namespace LIBC_NAMESPACE_DECL {
1616

libc/src/unistd/getuid.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#ifndef LLVM_LIBC_SRC_UNISTD_GETUID_H
1010
#define LLVM_LIBC_SRC_UNISTD_GETUID_H
1111

12+
#include "hdr/unistd_macros.h"
1213
#include "src/__support/macros/config.h"
13-
#include <unistd.h>
1414

1515
namespace LIBC_NAMESPACE_DECL {
1616

libc/src/unistd/isatty.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#ifndef LLVM_LIBC_SRC_UNISTD_ISATTY_H
1010
#define LLVM_LIBC_SRC_UNISTD_ISATTY_H
1111

12+
#include "hdr/unistd_macros.h"
1213
#include "src/__support/macros/config.h"
13-
#include <unistd.h>
1414

1515
namespace LIBC_NAMESPACE_DECL {
1616

libc/src/unistd/link.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#ifndef LLVM_LIBC_SRC_UNISTD_LINK_H
1010
#define LLVM_LIBC_SRC_UNISTD_LINK_H
1111

12+
#include "hdr/unistd_macros.h"
1213
#include "src/__support/macros/config.h"
13-
#include <unistd.h>
1414

1515
namespace LIBC_NAMESPACE_DECL {
1616

libc/src/unistd/linux/ftruncate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
1212
#include "src/__support/common.h"
1313

14+
#include "hdr/unistd_macros.h"
1415
#include "src/__support/macros/config.h"
1516
#include "src/errno/libc_errno.h"
1617
#include <stdint.h> // For uint64_t.
1718
#include <sys/syscall.h> // For syscall numbers.
18-
#include <unistd.h>
1919

2020
namespace LIBC_NAMESPACE_DECL {
2121

libc/src/unistd/linux/lseek.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
1515
#include "src/__support/common.h"
1616

17-
#include <sys/syscall.h> // For syscall numbers.
18-
#include <unistd.h> // For off_t.
17+
#include "include/llvm-libc-types/off_t.h" // For off_t.
18+
#include <sys/syscall.h> // For syscall numbers.
1919

2020
namespace LIBC_NAMESPACE_DECL {
2121

libc/src/unistd/linux/sysconf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
#include "src/__support/common.h"
1212

13+
#include "hdr/unistd_macros.h"
1314
#include "src/__support/macros/config.h"
1415
#include "src/errno/libc_errno.h"
1516
#include "src/sys/auxv/getauxval.h"
1617
#include <sys/auxv.h>
17-
#include <unistd.h>
1818

1919
namespace LIBC_NAMESPACE_DECL {
2020

libc/src/unistd/linux/truncate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
#include "src/__support/macros/config.h"
1414
#include "src/errno/libc_errno.h"
1515

16+
#include "hdr/unistd_macros.h"
1617
#include <stdint.h> // For uint64_t.
1718
#include <sys/syscall.h> // For syscall numbers.
18-
#include <unistd.h>
1919

2020
namespace LIBC_NAMESPACE_DECL {
2121

libc/src/unistd/lseek.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#ifndef LLVM_LIBC_SRC_UNISTD_LSEEK_H
1010
#define LLVM_LIBC_SRC_UNISTD_LSEEK_H
1111

12+
#include "hdr/unistd_macros.h"
1213
#include "src/__support/macros/config.h"
13-
#include <unistd.h>
1414

1515
namespace LIBC_NAMESPACE_DECL {
1616

libc/src/unistd/pread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#ifndef LLVM_LIBC_SRC_UNISTD_PREAD_H
1010
#define LLVM_LIBC_SRC_UNISTD_PREAD_H
1111

12+
#include "hdr/unistd_macros.h"
1213
#include "src/__support/macros/config.h"
13-
#include <unistd.h>
1414

1515
namespace LIBC_NAMESPACE_DECL {
1616

libc/src/unistd/pwrite.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#ifndef LLVM_LIBC_SRC_UNISTD_PWRITE_H
1010
#define LLVM_LIBC_SRC_UNISTD_PWRITE_H
1111

12+
#include "hdr/unistd_macros.h"
1213
#include "src/__support/macros/config.h"
13-
#include <unistd.h>
1414

1515
namespace LIBC_NAMESPACE_DECL {
1616

libc/src/unistd/read.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#ifndef LLVM_LIBC_SRC_UNISTD_READ_H
1010
#define LLVM_LIBC_SRC_UNISTD_READ_H
1111

12+
#include "hdr/unistd_macros.h"
1213
#include "src/__support/macros/config.h"
13-
#include <unistd.h>
1414

1515
namespace LIBC_NAMESPACE_DECL {
1616

libc/src/unistd/readlink.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#ifndef LLVM_LIBC_SRC_UNISTD_READLINK_H
1010
#define LLVM_LIBC_SRC_UNISTD_READLINK_H
1111

12+
#include "hdr/unistd_macros.h"
1213
#include "src/__support/macros/config.h"
13-
#include <unistd.h>
1414

1515
namespace LIBC_NAMESPACE_DECL {
1616

libc/src/unistd/readlinkat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#ifndef LLVM_LIBC_SRC_UNISTD_READLINKAT_H
1010
#define LLVM_LIBC_SRC_UNISTD_READLINKAT_H
1111

12+
#include "hdr/unistd_macros.h"
1213
#include "src/__support/macros/config.h"
13-
#include <unistd.h>
1414

1515
namespace LIBC_NAMESPACE_DECL {
1616

libc/src/unistd/swab.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#ifndef LLVM_LIBC_SRC_UNISTD_SWAB_H
1010
#define LLVM_LIBC_SRC_UNISTD_SWAB_H
1111

12+
#include "include/llvm-libc-types/ssize_t.h" // For ssize_t
1213
#include "src/__support/macros/config.h"
13-
#include <unistd.h> // For ssize_t
1414

1515
namespace LIBC_NAMESPACE_DECL {
1616

libc/src/unistd/symlink.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#ifndef LLVM_LIBC_SRC_UNISTD_SYMLINK_H
1010
#define LLVM_LIBC_SRC_UNISTD_SYMLINK_H
1111

12+
#include "hdr/unistd_macros.h"
1213
#include "src/__support/macros/config.h"
13-
#include <unistd.h>
1414

1515
namespace LIBC_NAMESPACE_DECL {
1616

libc/src/unistd/symlinkat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#ifndef LLVM_LIBC_SRC_UNISTD_SYMLINKAT_H
1010
#define LLVM_LIBC_SRC_UNISTD_SYMLINKAT_H
1111

12+
#include "hdr/unistd_macros.h"
1213
#include "src/__support/macros/config.h"
13-
#include <unistd.h>
1414

1515
namespace LIBC_NAMESPACE_DECL {
1616

libc/src/unistd/syscall.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
#ifndef LLVM_LIBC_SRC_UNISTD_SYSCALL_H
1010
#define LLVM_LIBC_SRC_UNISTD_SYSCALL_H
1111

12+
#include "hdr/unistd_macros.h"
1213
#include "src/__support/macros/config.h"
1314
#include <stdarg.h>
14-
#include <unistd.h>
1515

1616
namespace LIBC_NAMESPACE_DECL {
1717

libc/src/unistd/sysconf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#ifndef LLVM_LIBC_SRC_UNISTD_SYSCONF_H
1010
#define LLVM_LIBC_SRC_UNISTD_SYSCONF_H
1111

12+
#include "hdr/unistd_macros.h"
1213
#include "src/__support/macros/config.h"
13-
#include <unistd.h>
1414

1515
namespace LIBC_NAMESPACE_DECL {
1616

libc/src/unistd/truncate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#ifndef LLVM_LIBC_SRC_UNISTD_TRUNCATE_H
1010
#define LLVM_LIBC_SRC_UNISTD_TRUNCATE_H
1111

12+
#include "hdr/unistd_macros.h"
1213
#include "src/__support/macros/config.h"
13-
#include <unistd.h>
1414

1515
namespace LIBC_NAMESPACE_DECL {
1616

0 commit comments

Comments
 (0)