Skip to content

Commit

Permalink
[libc] remove #include <fcntl.h> and add proxy or type (llvm#113836)
Browse files Browse the repository at this point in the history
  • Loading branch information
Job Henandez Lara authored Oct 28, 2024
1 parent 481bce0 commit abc49cc
Show file tree
Hide file tree
Showing 58 changed files with 156 additions and 80 deletions.
3 changes: 3 additions & 0 deletions libc/hdr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,13 @@ add_proxy_header_library(
libc.include.llvm-libc-macros.generic_error_number_macros
)

add_header_library(fcntl_overlay HDRS fcntl_overlay.h)
add_proxy_header_library(
fcntl_macros
HDRS
fcntl_macros.h
DEPENDS
.fcntl_overlay
FULL_BUILD_DEPENDS
libc.include.llvm-libc-macros.fcntl_macros
libc.include.fcntl
Expand Down
2 changes: 1 addition & 1 deletion libc/hdr/fcntl_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#else // Overlay mode

#include <fcntl.h>
#include "hdr/fcntl_overlay.h"

#endif // LLVM_LIBC_FULL_BUILD

Expand Down
37 changes: 37 additions & 0 deletions libc/hdr/fcntl_overlay.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//===-- Including fcntl.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_FCNTL_OVERLAY_H
#define LLVM_LIBC_HDR_FCNTL_OVERLAY_H

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

// Overlay mode

// glibc <fcntl.h> header might provide extern inline definitions for few
// functions, causing external alias errors. They are guarded by
// `__USE_FORTIFY_LEVEL`, which will be temporarily disabled
// with `_FORTIFY_SOURCE`.

#ifdef __USE_FORTIFY_LEVEL
#define LIBC_OLD_USE_FORTIFY_LEVEL __USE_FORTIFY_LEVEL
#undef __USE_FORTIFY_LEVEL
#define __USE_FORTIFY_LEVEL 0
#endif

#include <fcntl.h>

#ifdef LIBC_OLD_USE_FORTIFY_LEVEL
#undef __USE_FORTIFY_LEVEL
#define __USE_FORTIFY_LEVEL LIBC_OLD_USE_FORTIFY_LEVEL
#undef LIBC_OLD_USE_FORTIFY_LEVEL
#endif

#endif // LLVM_LIBC_HDR_FCNTL_OVERLAY_H
11 changes: 11 additions & 0 deletions libc/hdr/types/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ add_proxy_header_library(
libc.include.llvm-libc-types.struct_timespec
)

add_proxy_header_library(
mode_t
HDRS
mode_t.h
DEPENDS
../fcntl_overlay
FULL_BUILD_DEPENDS
libc.include.llvm-libc-types.mode_t
libc.include.fcntl
)

add_proxy_header_library(
fenv_t
HDRS
Expand Down
22 changes: 22 additions & 0 deletions libc/hdr/types/mode_t.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Definition of macros from mode_t.h --------------------------------===//
//
// 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_MODE_T_H
#define LLVM_LIBC_HDR_MODE_T_H

#ifdef LIBC_FULL_BUILD

#include "include/llvm-libc-types/mode_t.h"

#else // Overlay mode

#include "hdr/fcntl_overlay.h"

#endif // LLVM_LIBC_FULL_BUILD

#endif // LLVM_LIBC_HDR_MODE_T_H
4 changes: 2 additions & 2 deletions libc/src/__support/File/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ add_object_library(
file.h
lseekImpl.h
DEPENDS
libc.include.fcntl
libc.hdr.fcntl_macros
libc.include.sys_syscall
libc.include.sys_stat
libc.src.__support.CPP.new
Expand Down Expand Up @@ -55,7 +55,7 @@ add_object_library(
SRCS
dir.cpp
DEPENDS
libc.include.fcntl
libc.hdr.fcntl_macros
libc.include.sys_syscall
libc.src.__support.OSUtil.osutil
libc.src.__support.error_or
Expand Down
2 changes: 1 addition & 1 deletion libc/src/__support/File/linux/dir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "src/__support/error_or.h"
#include "src/__support/macros/config.h"

#include <fcntl.h> // For open flags
#include "hdr/fcntl_macros.h" // For open flags
#include <sys/syscall.h> // For syscall numbers

namespace LIBC_NAMESPACE_DECL {
Expand Down
2 changes: 1 addition & 1 deletion libc/src/__support/File/linux/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "src/__support/macros/config.h"
#include "src/errno/libc_errno.h" // For error macros

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

Expand Down
2 changes: 1 addition & 1 deletion libc/src/__support/threads/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ add_object_library(
.futex_utils
libc.config.app_h
libc.include.sys_syscall
libc.include.fcntl
libc.hdr.fcntl_macros
libc.src.errno.errno
libc.src.__support.CPP.atomic
libc.src.__support.CPP.stringstream
Expand Down
2 changes: 1 addition & 1 deletion libc/src/__support/threads/linux/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <arm_acle.h>
#endif

#include <fcntl.h>
#include "hdr/fcntl_macros.h"
#include <linux/param.h> // For EXEC_PAGESIZE.
#include <linux/prctl.h> // For PR_SET_NAME
#include <linux/sched.h> // For CLONE_* flags.
Expand Down
2 changes: 1 addition & 1 deletion libc/src/fcntl/creat.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#ifndef LLVM_LIBC_SRC_FCNTL_CREAT_H
#define LLVM_LIBC_SRC_FCNTL_CREAT_H

#include "hdr/fcntl_macros.h"
#include "src/__support/macros/config.h"
#include <fcntl.h>

namespace LIBC_NAMESPACE_DECL {

Expand Down
8 changes: 4 additions & 4 deletions libc/src/fcntl/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ add_entrypoint_object(
HDRS
../creat.h
DEPENDS
libc.include.fcntl
libc.hdr.fcntl_macros
libc.src.__support.OSUtil.osutil
libc.src.errno.errno
)
Expand All @@ -17,7 +17,7 @@ add_entrypoint_object(
HDRS
../fcntl.h
DEPENDS
libc.include.fcntl
libc.hdr.fcntl_macros
libc.src.__support.OSUtil.osutil
)

Expand All @@ -28,7 +28,7 @@ add_entrypoint_object(
HDRS
../open.h
DEPENDS
libc.include.fcntl
libc.hdr.types.mode_t
libc.src.__support.OSUtil.osutil
libc.src.errno.errno
)
Expand All @@ -40,7 +40,7 @@ add_entrypoint_object(
HDRS
../openat.h
DEPENDS
libc.include.fcntl
libc.hdr.types.mode_t
libc.src.__support.OSUtil.osutil
libc.src.errno.errno
)
2 changes: 1 addition & 1 deletion libc/src/fcntl/linux/creat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "src/__support/macros/config.h"
#include "src/errno/libc_errno.h"

#include <fcntl.h>
#include "hdr/fcntl_macros.h"
#include <sys/syscall.h> // For syscall numbers.

namespace LIBC_NAMESPACE_DECL {
Expand Down
2 changes: 1 addition & 1 deletion libc/src/fcntl/linux/open.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "src/__support/macros/config.h"
#include "src/errno/libc_errno.h"

#include <fcntl.h>
#include "hdr/types/mode_t.h"
#include <stdarg.h>
#include <sys/syscall.h> // For syscall numbers.

Expand Down
2 changes: 1 addition & 1 deletion libc/src/fcntl/linux/openat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "src/__support/macros/config.h"
#include "src/errno/libc_errno.h"

#include <fcntl.h>
#include "hdr/types/mode_t.h"
#include <stdarg.h>
#include <sys/syscall.h> // For syscall numbers.

Expand Down
2 changes: 1 addition & 1 deletion libc/src/fcntl/open.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#ifndef LLVM_LIBC_SRC_FCNTL_OPEN_H
#define LLVM_LIBC_SRC_FCNTL_OPEN_H

#include "hdr/fcntl_macros.h"
#include "src/__support/macros/config.h"
#include <fcntl.h>

namespace LIBC_NAMESPACE_DECL {

Expand Down
2 changes: 1 addition & 1 deletion libc/src/fcntl/openat.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#ifndef LLVM_LIBC_SRC_FCNTL_OPENAT_H
#define LLVM_LIBC_SRC_FCNTL_OPENAT_H

#include "hdr/fcntl_macros.h"
#include "src/__support/macros/config.h"
#include <fcntl.h>

namespace LIBC_NAMESPACE_DECL {

Expand Down
2 changes: 1 addition & 1 deletion libc/src/spawn/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ add_entrypoint_object(
HDRS
../posix_spawn.h
DEPENDS
libc.include.fcntl
libc.hdr.types.mode_t
libc.include.spawn
libc.include.sys_syscall
libc.include.signal
Expand Down
2 changes: 1 addition & 1 deletion libc/src/spawn/linux/posix_spawn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "src/__support/macros/config.h"
#include "src/spawn/file_actions.h"

#include <fcntl.h>
#include "hdr/types/mode_t.h"
#include <signal.h> // For SIGCHLD
#include <spawn.h>
#include <sys/syscall.h> // For syscall numbers.
Expand Down
2 changes: 1 addition & 1 deletion libc/src/stdio/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ add_entrypoint_object(
HDRS
../remove.h
DEPENDS
libc.include.fcntl
libc.hdr.fcntl_macros
libc.include.unistd
libc.include.sys_syscall
libc.src.__support.OSUtil.osutil
Expand Down
2 changes: 1 addition & 1 deletion libc/src/stdio/linux/remove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"

#include "hdr/fcntl_macros.h" // For AT_* macros.
#include "src/__support/macros/config.h"
#include "src/errno/libc_errno.h"
#include <fcntl.h> // For AT_* macros.
#include <sys/syscall.h> // For syscall numbers.

namespace LIBC_NAMESPACE_DECL {
Expand Down
11 changes: 6 additions & 5 deletions libc/src/sys/stat/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ add_entrypoint_object(
HDRS
../chmod.h
DEPENDS
libc.include.fcntl
libc.hdr.types.mode_t
libc.include.sys_stat
libc.include.sys_syscall
libc.src.__support.OSUtil.osutil
Expand All @@ -19,6 +19,7 @@ add_entrypoint_object(
HDRS
../fchmod.h
DEPENDS
libc.hdr.types.mode_t
libc.include.sys_stat
libc.include.sys_syscall
libc.src.__support.OSUtil.osutil
Expand All @@ -45,7 +46,7 @@ add_entrypoint_object(
HDRS
../mkdir.h
DEPENDS
libc.include.fcntl
libc.hdr.types.mode_t
libc.include.sys_stat
libc.include.sys_syscall
libc.src.__support.OSUtil.osutil
Expand Down Expand Up @@ -84,7 +85,7 @@ add_entrypoint_object(
../stat.h
DEPENDS
.kernel_statx
libc.include.fcntl
libc.hdr.fcntl_macros
libc.include.sys_stat
libc.src.errno.errno
)
Expand All @@ -97,7 +98,7 @@ add_entrypoint_object(
../lstat.h
DEPENDS
.kernel_statx
libc.include.fcntl
libc.hdr.fcntl_macros
libc.include.sys_stat
libc.src.errno.errno
)
Expand All @@ -110,7 +111,7 @@ add_entrypoint_object(
../fstat.h
DEPENDS
.kernel_statx
libc.include.fcntl
libc.hdr.fcntl_macros
libc.include.sys_stat
libc.src.errno.errno
)
2 changes: 1 addition & 1 deletion libc/src/sys/stat/linux/chmod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"

#include "hdr/types/mode_t.h"
#include "src/__support/macros/config.h"
#include "src/errno/libc_errno.h"
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/syscall.h> // For syscall numbers.

Expand Down
2 changes: 1 addition & 1 deletion libc/src/sys/stat/linux/fchmod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"

#include "hdr/types/mode_t.h"
#include "src/__support/macros/config.h"
#include "src/errno/libc_errno.h"
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/syscall.h> // For syscall numbers.

Expand Down
2 changes: 1 addition & 1 deletion libc/src/sys/stat/linux/fstat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include "src/__support/common.h"

#include <fcntl.h>
#include "hdr/fcntl_macros.h"
#include <sys/stat.h>

namespace LIBC_NAMESPACE_DECL {
Expand Down
2 changes: 1 addition & 1 deletion libc/src/sys/stat/linux/lstat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"

#include <fcntl.h>
#include "hdr/fcntl_macros.h"
#include <sys/stat.h>

namespace LIBC_NAMESPACE_DECL {
Expand Down
2 changes: 1 addition & 1 deletion libc/src/sys/stat/linux/mkdir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"

#include "hdr/types/mode_t.h"
#include "src/__support/macros/config.h"
#include "src/errno/libc_errno.h"
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/syscall.h> // For syscall numbers.

Expand Down
2 changes: 1 addition & 1 deletion libc/src/sys/stat/linux/stat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include "src/__support/common.h"

#include <fcntl.h>
#include "hdr/fcntl_macros.h"
#include <sys/stat.h>

namespace LIBC_NAMESPACE_DECL {
Expand Down
Loading

0 comments on commit abc49cc

Please sign in to comment.