Skip to content

[libc] Add unistd overlay #118882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions libc/hdr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,13 @@ add_proxy_header_library(
libc.include.llvm-libc-macros.sys_stat_macros
)

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

#else // Overlay mode

#include <unistd.h>
#include "unistd_overlay.h"

#endif // LLVM_LIBC_FULL_BUILD

Expand Down
69 changes: 69 additions & 0 deletions libc/hdr/unistd_overlay.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//===-- Including unistd.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_UNISTD_OVERLAY_H
#define LLVM_LIBC_HDR_UNISTD_OVERLAY_H

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

// Overlay mode

// glibc <unistd.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 <stdio.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

#ifdef __USE_EXTERN_INLINES
#define LIBC_OLD_USE_EXTERN_INLINES
#undef __USE_EXTERN_INLINES
#endif

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

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

#include <unistd.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

#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

#ifdef LIBC_OLD_USE_EXTERN_INLINES
#define __USE_EXTERN_INLINES
#undef LIBC_OLD_USE_EXTERN_INLINES
#endif

#endif // LLVM_LIBC_HDR_UNISTD_OVERLAY_H
2 changes: 1 addition & 1 deletion libc/src/unistd/dup.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#ifndef LLVM_LIBC_SRC_UNISTD_DUP_H
#define LLVM_LIBC_SRC_UNISTD_DUP_H

#include "hdr/unistd_macros.h"
#include "src/__support/macros/config.h"
#include <unistd.h>

namespace LIBC_NAMESPACE_DECL {

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

#include "hdr/unistd_macros.h"
#include "src/__support/macros/config.h"
#include <unistd.h>

namespace LIBC_NAMESPACE_DECL {

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

#include "hdr/unistd_macros.h"
#include "src/__support/macros/config.h"
#include <unistd.h>

namespace LIBC_NAMESPACE_DECL {

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

#include "hdr/unistd_macros.h"
#include "src/__support/macros/config.h"
#include <unistd.h>

namespace LIBC_NAMESPACE_DECL {

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

#include "hdr/unistd_macros.h"
#include "src/__support/macros/config.h"
#include <unistd.h>

namespace LIBC_NAMESPACE_DECL {

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

#include "hdr/unistd_macros.h"
#include "src/__support/macros/config.h"
#include <unistd.h>

namespace LIBC_NAMESPACE_DECL {

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

#include "hdr/unistd_macros.h"
#include "src/__support/macros/config.h"
#include <unistd.h>

namespace LIBC_NAMESPACE_DECL {

Expand Down
2 changes: 1 addition & 1 deletion libc/src/unistd/getopt.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#define LLVM_LIBC_SRC_UNISTD_GETOPT_H

#include "hdr/types/FILE.h"
#include "hdr/unistd_macros.h"
#include "src/__support/macros/config.h"
#include <unistd.h>

namespace LIBC_NAMESPACE_DECL {

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

#include "hdr/unistd_macros.h"
#include "src/__support/macros/config.h"
#include <unistd.h>

namespace LIBC_NAMESPACE_DECL {

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

#include "hdr/unistd_macros.h"
#include "src/__support/macros/config.h"
#include <unistd.h>

namespace LIBC_NAMESPACE_DECL {

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

#include "hdr/unistd_macros.h"
#include "src/__support/macros/config.h"
#include <unistd.h>

namespace LIBC_NAMESPACE_DECL {

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

#include "hdr/unistd_macros.h"
#include "src/__support/macros/config.h"
#include <unistd.h>

namespace LIBC_NAMESPACE_DECL {

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

#include "hdr/unistd_macros.h"
#include "src/__support/macros/config.h"
#include <unistd.h>

namespace LIBC_NAMESPACE_DECL {

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

#include "hdr/unistd_macros.h"
#include "src/__support/macros/config.h"
#include "src/errno/libc_errno.h"
#include <stdint.h> // For uint64_t.
#include <sys/syscall.h> // For syscall numbers.
#include <unistd.h>

namespace LIBC_NAMESPACE_DECL {

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

#include "hdr/types/off_t.h"
#include <sys/syscall.h> // For syscall numbers.
#include <unistd.h> // For off_t.

namespace LIBC_NAMESPACE_DECL {

Expand Down
2 changes: 1 addition & 1 deletion libc/src/unistd/linux/sysconf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

#include "src/__support/common.h"

#include "hdr/unistd_macros.h"
#include "src/__support/macros/config.h"
#include "src/errno/libc_errno.h"
#include "src/sys/auxv/getauxval.h"
#include <sys/auxv.h>
#include <unistd.h>

namespace LIBC_NAMESPACE_DECL {

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

#include "hdr/unistd_macros.h"
#include <stdint.h> // For uint64_t.
#include <sys/syscall.h> // For syscall numbers.
#include <unistd.h>

namespace LIBC_NAMESPACE_DECL {

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

#include "hdr/unistd_macros.h"
#include "src/__support/macros/config.h"
#include <unistd.h>

namespace LIBC_NAMESPACE_DECL {

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

#include "hdr/unistd_macros.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you apply this to the other unistd functions as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

#include "src/__support/macros/config.h"
#include <unistd.h>

namespace LIBC_NAMESPACE_DECL {

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

#include "hdr/unistd_macros.h"
#include "src/__support/macros/config.h"
#include <unistd.h>

namespace LIBC_NAMESPACE_DECL {

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

#include "hdr/unistd_macros.h"
#include "src/__support/macros/config.h"
#include <unistd.h>

namespace LIBC_NAMESPACE_DECL {

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

#include "hdr/unistd_macros.h"
#include "src/__support/macros/config.h"
#include <unistd.h>

namespace LIBC_NAMESPACE_DECL {

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

#include "hdr/unistd_macros.h"
#include "src/__support/macros/config.h"
#include <unistd.h>

namespace LIBC_NAMESPACE_DECL {

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

#include "hdr/types/ssize_t.h"
#include "src/__support/macros/config.h"
#include <unistd.h> // For ssize_t

namespace LIBC_NAMESPACE_DECL {

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

#include "hdr/unistd_macros.h"
#include "src/__support/macros/config.h"
#include <unistd.h>

namespace LIBC_NAMESPACE_DECL {

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

#include "hdr/unistd_macros.h"
#include "src/__support/macros/config.h"
#include <unistd.h>

namespace LIBC_NAMESPACE_DECL {

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

#include "hdr/unistd_macros.h"
#include "src/__support/macros/config.h"
#include <stdarg.h>
#include <unistd.h>

namespace LIBC_NAMESPACE_DECL {

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

#include "hdr/unistd_macros.h"
#include "src/__support/macros/config.h"
#include <unistd.h>

namespace LIBC_NAMESPACE_DECL {

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

#include "hdr/unistd_macros.h"
#include "src/__support/macros/config.h"
#include <unistd.h>

namespace LIBC_NAMESPACE_DECL {

Expand Down
Loading
Loading