Skip to content

Commit abc49cc

Browse files
author
Job Henandez Lara
authored
[libc] remove #include <fcntl.h> and add proxy or type (#113836)
1 parent 481bce0 commit abc49cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+156
-80
lines changed

libc/hdr/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,13 @@ add_proxy_header_library(
5151
libc.include.llvm-libc-macros.generic_error_number_macros
5252
)
5353

54+
add_header_library(fcntl_overlay HDRS fcntl_overlay.h)
5455
add_proxy_header_library(
5556
fcntl_macros
5657
HDRS
5758
fcntl_macros.h
59+
DEPENDS
60+
.fcntl_overlay
5861
FULL_BUILD_DEPENDS
5962
libc.include.llvm-libc-macros.fcntl_macros
6063
libc.include.fcntl

libc/hdr/fcntl_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 <fcntl.h>
18+
#include "hdr/fcntl_overlay.h"
1919

2020
#endif // LLVM_LIBC_FULL_BUILD
2121

libc/hdr/fcntl_overlay.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===-- Including fcntl.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_FCNTL_OVERLAY_H
10+
#define LLVM_LIBC_HDR_FCNTL_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 <fcntl.h> header might provide extern inline definitions for few
19+
// functions, causing external alias errors. They are guarded by
20+
// `__USE_FORTIFY_LEVEL`, which will be temporarily disabled
21+
// with `_FORTIFY_SOURCE`.
22+
23+
#ifdef __USE_FORTIFY_LEVEL
24+
#define LIBC_OLD_USE_FORTIFY_LEVEL __USE_FORTIFY_LEVEL
25+
#undef __USE_FORTIFY_LEVEL
26+
#define __USE_FORTIFY_LEVEL 0
27+
#endif
28+
29+
#include <fcntl.h>
30+
31+
#ifdef LIBC_OLD_USE_FORTIFY_LEVEL
32+
#undef __USE_FORTIFY_LEVEL
33+
#define __USE_FORTIFY_LEVEL LIBC_OLD_USE_FORTIFY_LEVEL
34+
#undef LIBC_OLD_USE_FORTIFY_LEVEL
35+
#endif
36+
37+
#endif // LLVM_LIBC_HDR_FCNTL_OVERLAY_H

libc/hdr/types/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ add_proxy_header_library(
4646
libc.include.llvm-libc-types.struct_timespec
4747
)
4848

49+
add_proxy_header_library(
50+
mode_t
51+
HDRS
52+
mode_t.h
53+
DEPENDS
54+
../fcntl_overlay
55+
FULL_BUILD_DEPENDS
56+
libc.include.llvm-libc-types.mode_t
57+
libc.include.fcntl
58+
)
59+
4960
add_proxy_header_library(
5061
fenv_t
5162
HDRS

libc/hdr/types/mode_t.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Definition of macros from mode_t.h --------------------------------===//
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_MODE_T_H
10+
#define LLVM_LIBC_HDR_MODE_T_H
11+
12+
#ifdef LIBC_FULL_BUILD
13+
14+
#include "include/llvm-libc-types/mode_t.h"
15+
16+
#else // Overlay mode
17+
18+
#include "hdr/fcntl_overlay.h"
19+
20+
#endif // LLVM_LIBC_FULL_BUILD
21+
22+
#endif // LLVM_LIBC_HDR_MODE_T_H

libc/src/__support/File/linux/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ add_object_library(
77
file.h
88
lseekImpl.h
99
DEPENDS
10-
libc.include.fcntl
10+
libc.hdr.fcntl_macros
1111
libc.include.sys_syscall
1212
libc.include.sys_stat
1313
libc.src.__support.CPP.new
@@ -55,7 +55,7 @@ add_object_library(
5555
SRCS
5656
dir.cpp
5757
DEPENDS
58-
libc.include.fcntl
58+
libc.hdr.fcntl_macros
5959
libc.include.sys_syscall
6060
libc.src.__support.OSUtil.osutil
6161
libc.src.__support.error_or

libc/src/__support/File/linux/dir.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "src/__support/error_or.h"
1313
#include "src/__support/macros/config.h"
1414

15-
#include <fcntl.h> // For open flags
15+
#include "hdr/fcntl_macros.h" // For open flags
1616
#include <sys/syscall.h> // For syscall numbers
1717

1818
namespace LIBC_NAMESPACE_DECL {

libc/src/__support/File/linux/file.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "src/__support/macros/config.h"
1919
#include "src/errno/libc_errno.h" // For error macros
2020

21-
#include <fcntl.h> // For mode_t and other flags to the open syscall
21+
#include "hdr/fcntl_macros.h" // For mode_t and other flags to the open syscall
2222
#include <sys/stat.h> // For S_IS*, S_IF*, and S_IR* flags.
2323
#include <sys/syscall.h> // For syscall numbers
2424

libc/src/__support/threads/linux/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ add_object_library(
7979
.futex_utils
8080
libc.config.app_h
8181
libc.include.sys_syscall
82-
libc.include.fcntl
82+
libc.hdr.fcntl_macros
8383
libc.src.errno.errno
8484
libc.src.__support.CPP.atomic
8585
libc.src.__support.CPP.stringstream

libc/src/__support/threads/linux/thread.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <arm_acle.h>
2323
#endif
2424

25-
#include <fcntl.h>
25+
#include "hdr/fcntl_macros.h"
2626
#include <linux/param.h> // For EXEC_PAGESIZE.
2727
#include <linux/prctl.h> // For PR_SET_NAME
2828
#include <linux/sched.h> // For CLONE_* flags.

libc/src/fcntl/creat.h

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

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

1515
namespace LIBC_NAMESPACE_DECL {
1616

libc/src/fcntl/linux/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ add_entrypoint_object(
55
HDRS
66
../creat.h
77
DEPENDS
8-
libc.include.fcntl
8+
libc.hdr.fcntl_macros
99
libc.src.__support.OSUtil.osutil
1010
libc.src.errno.errno
1111
)
@@ -17,7 +17,7 @@ add_entrypoint_object(
1717
HDRS
1818
../fcntl.h
1919
DEPENDS
20-
libc.include.fcntl
20+
libc.hdr.fcntl_macros
2121
libc.src.__support.OSUtil.osutil
2222
)
2323

@@ -28,7 +28,7 @@ add_entrypoint_object(
2828
HDRS
2929
../open.h
3030
DEPENDS
31-
libc.include.fcntl
31+
libc.hdr.types.mode_t
3232
libc.src.__support.OSUtil.osutil
3333
libc.src.errno.errno
3434
)
@@ -40,7 +40,7 @@ add_entrypoint_object(
4040
HDRS
4141
../openat.h
4242
DEPENDS
43-
libc.include.fcntl
43+
libc.hdr.types.mode_t
4444
libc.src.__support.OSUtil.osutil
4545
libc.src.errno.errno
4646
)

libc/src/fcntl/linux/creat.cpp

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

16-
#include <fcntl.h>
16+
#include "hdr/fcntl_macros.h"
1717
#include <sys/syscall.h> // For syscall numbers.
1818

1919
namespace LIBC_NAMESPACE_DECL {

libc/src/fcntl/linux/open.cpp

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

16-
#include <fcntl.h>
16+
#include "hdr/types/mode_t.h"
1717
#include <stdarg.h>
1818
#include <sys/syscall.h> // For syscall numbers.
1919

libc/src/fcntl/linux/openat.cpp

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

16-
#include <fcntl.h>
16+
#include "hdr/types/mode_t.h"
1717
#include <stdarg.h>
1818
#include <sys/syscall.h> // For syscall numbers.
1919

libc/src/fcntl/open.h

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

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

1515
namespace LIBC_NAMESPACE_DECL {
1616

libc/src/fcntl/openat.h

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

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

1515
namespace LIBC_NAMESPACE_DECL {
1616

libc/src/spawn/linux/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ add_entrypoint_object(
55
HDRS
66
../posix_spawn.h
77
DEPENDS
8-
libc.include.fcntl
8+
libc.hdr.types.mode_t
99
libc.include.spawn
1010
libc.include.sys_syscall
1111
libc.include.signal

libc/src/spawn/linux/posix_spawn.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "src/__support/macros/config.h"
1515
#include "src/spawn/file_actions.h"
1616

17-
#include <fcntl.h>
17+
#include "hdr/types/mode_t.h"
1818
#include <signal.h> // For SIGCHLD
1919
#include <spawn.h>
2020
#include <sys/syscall.h> // For syscall numbers.

libc/src/stdio/linux/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ add_entrypoint_object(
55
HDRS
66
../remove.h
77
DEPENDS
8-
libc.include.fcntl
8+
libc.hdr.fcntl_macros
99
libc.include.unistd
1010
libc.include.sys_syscall
1111
libc.src.__support.OSUtil.osutil

libc/src/stdio/linux/remove.cpp

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

14+
#include "hdr/fcntl_macros.h" // For AT_* macros.
1415
#include "src/__support/macros/config.h"
1516
#include "src/errno/libc_errno.h"
16-
#include <fcntl.h> // For AT_* macros.
1717
#include <sys/syscall.h> // For syscall numbers.
1818

1919
namespace LIBC_NAMESPACE_DECL {

libc/src/sys/stat/linux/CMakeLists.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ add_entrypoint_object(
55
HDRS
66
../chmod.h
77
DEPENDS
8-
libc.include.fcntl
8+
libc.hdr.types.mode_t
99
libc.include.sys_stat
1010
libc.include.sys_syscall
1111
libc.src.__support.OSUtil.osutil
@@ -19,6 +19,7 @@ add_entrypoint_object(
1919
HDRS
2020
../fchmod.h
2121
DEPENDS
22+
libc.hdr.types.mode_t
2223
libc.include.sys_stat
2324
libc.include.sys_syscall
2425
libc.src.__support.OSUtil.osutil
@@ -45,7 +46,7 @@ add_entrypoint_object(
4546
HDRS
4647
../mkdir.h
4748
DEPENDS
48-
libc.include.fcntl
49+
libc.hdr.types.mode_t
4950
libc.include.sys_stat
5051
libc.include.sys_syscall
5152
libc.src.__support.OSUtil.osutil
@@ -84,7 +85,7 @@ add_entrypoint_object(
8485
../stat.h
8586
DEPENDS
8687
.kernel_statx
87-
libc.include.fcntl
88+
libc.hdr.fcntl_macros
8889
libc.include.sys_stat
8990
libc.src.errno.errno
9091
)
@@ -97,7 +98,7 @@ add_entrypoint_object(
9798
../lstat.h
9899
DEPENDS
99100
.kernel_statx
100-
libc.include.fcntl
101+
libc.hdr.fcntl_macros
101102
libc.include.sys_stat
102103
libc.src.errno.errno
103104
)
@@ -110,7 +111,7 @@ add_entrypoint_object(
110111
../fstat.h
111112
DEPENDS
112113
.kernel_statx
113-
libc.include.fcntl
114+
libc.hdr.fcntl_macros
114115
libc.include.sys_stat
115116
libc.src.errno.errno
116117
)

libc/src/sys/stat/linux/chmod.cpp

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

14+
#include "hdr/types/mode_t.h"
1415
#include "src/__support/macros/config.h"
1516
#include "src/errno/libc_errno.h"
16-
#include <fcntl.h>
1717
#include <sys/stat.h>
1818
#include <sys/syscall.h> // For syscall numbers.
1919

libc/src/sys/stat/linux/fchmod.cpp

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

14+
#include "hdr/types/mode_t.h"
1415
#include "src/__support/macros/config.h"
1516
#include "src/errno/libc_errno.h"
16-
#include <fcntl.h>
1717
#include <sys/stat.h>
1818
#include <sys/syscall.h> // For syscall numbers.
1919

libc/src/sys/stat/linux/fstat.cpp

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

1414
#include "src/__support/common.h"
1515

16-
#include <fcntl.h>
16+
#include "hdr/fcntl_macros.h"
1717
#include <sys/stat.h>
1818

1919
namespace LIBC_NAMESPACE_DECL {

libc/src/sys/stat/linux/lstat.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
1515
#include "src/__support/common.h"
1616

17-
#include <fcntl.h>
17+
#include "hdr/fcntl_macros.h"
1818
#include <sys/stat.h>
1919

2020
namespace LIBC_NAMESPACE_DECL {

libc/src/sys/stat/linux/mkdir.cpp

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

14+
#include "hdr/types/mode_t.h"
1415
#include "src/__support/macros/config.h"
1516
#include "src/errno/libc_errno.h"
16-
#include <fcntl.h>
1717
#include <sys/stat.h>
1818
#include <sys/syscall.h> // For syscall numbers.
1919

libc/src/sys/stat/linux/stat.cpp

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

1414
#include "src/__support/common.h"
1515

16-
#include <fcntl.h>
16+
#include "hdr/fcntl_macros.h"
1717
#include <sys/stat.h>
1818

1919
namespace LIBC_NAMESPACE_DECL {

0 commit comments

Comments
 (0)