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.

0 commit comments

Comments
 (0)