-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
[libc] Add unistd overlay #118882
Conversation
@llvm/pr-subscribers-libc Author: Tristan Ross (RossComputerGuy) ChangesFixes failures like this which I experienced:
Full diff: https://github.com/llvm/llvm-project/pull/118882.diff 7 Files Affected:
diff --git a/libc/hdr/unistd_macros.h b/libc/hdr/unistd_macros.h
index 132e123280139f..5c2b24354dd3ee 100644
--- a/libc/hdr/unistd_macros.h
+++ b/libc/hdr/unistd_macros.h
@@ -15,7 +15,7 @@
#else // Overlay mode
-#include <unistd.h>
+#include "unistd_overlay.h"
#endif // LLVM_LIBC_FULL_BUILD
diff --git a/libc/hdr/unistd_overlay.h b/libc/hdr/unistd_overlay.h
new file mode 100644
index 00000000000000..f2c9ed8e34ff60
--- /dev/null
+++ b/libc/hdr/unistd_overlay.h
@@ -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
diff --git a/libc/src/unistd/getcwd.h b/libc/src/unistd/getcwd.h
index 8b63a91c26b5c7..8331944490b721 100644
--- a/libc/src/unistd/getcwd.h
+++ b/libc/src/unistd/getcwd.h
@@ -10,7 +10,7 @@
#define LLVM_LIBC_SRC_UNISTD_GETCWD_H
#include "src/__support/macros/config.h"
-#include <unistd.h>
+#include "hdr/unistd_macros.h"
namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/src/unistd/pread.h b/libc/src/unistd/pread.h
index 4723675e82a20a..e0bdc471b12219 100644
--- a/libc/src/unistd/pread.h
+++ b/libc/src/unistd/pread.h
@@ -10,7 +10,7 @@
#define LLVM_LIBC_SRC_UNISTD_PREAD_H
#include "src/__support/macros/config.h"
-#include <unistd.h>
+#include "hdr/unistd_macros.h"
namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/src/unistd/read.h b/libc/src/unistd/read.h
index 01231cb82e35e5..3d2ecd556d111e 100644
--- a/libc/src/unistd/read.h
+++ b/libc/src/unistd/read.h
@@ -10,7 +10,7 @@
#define LLVM_LIBC_SRC_UNISTD_READ_H
#include "src/__support/macros/config.h"
-#include <unistd.h>
+#include "hdr/unistd_macros.h"
namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/src/unistd/readlink.h b/libc/src/unistd/readlink.h
index a73e9740c74637..562936150512a7 100644
--- a/libc/src/unistd/readlink.h
+++ b/libc/src/unistd/readlink.h
@@ -10,7 +10,7 @@
#define LLVM_LIBC_SRC_UNISTD_READLINK_H
#include "src/__support/macros/config.h"
-#include <unistd.h>
+#include "hdr/unistd_macros.h"
namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/src/unistd/readlinkat.h b/libc/src/unistd/readlinkat.h
index 6bdd48b537fc8c..2e0e33f77586eb 100644
--- a/libc/src/unistd/readlinkat.h
+++ b/libc/src/unistd/readlinkat.h
@@ -10,7 +10,7 @@
#define LLVM_LIBC_SRC_UNISTD_READLINKAT_H
#include "src/__support/macros/config.h"
-#include <unistd.h>
+#include "hdr/unistd_macros.h"
namespace LIBC_NAMESPACE_DECL {
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
Can you also update |
8e2299c
to
50ef7fb
Compare
Alright, I've added that in. |
libc/hdr/unistd_overlay.h
Outdated
//===-- Including unistd.h in overlay mode | ||
//---------------------------------===// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: fix formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, what about the CI complaining about the bad formatting then lol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed it, I think we'll just ignore the format CI fail then lol.
@@ -9,8 +9,8 @@ | |||
#ifndef LLVM_LIBC_SRC_UNISTD_PREAD_H | |||
#define LLVM_LIBC_SRC_UNISTD_PREAD_H | |||
|
|||
#include "hdr/unistd_macros.h" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
d22d01c
to
99cd546
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like some of these need types instead of macros
libc/src/unistd/linux/lseek.cpp
Outdated
@@ -14,8 +14,8 @@ | |||
#include "src/__support/OSUtil/syscall.h" // For internal syscall function. | |||
#include "src/__support/common.h" | |||
|
|||
#include <sys/syscall.h> // For syscall numbers. | |||
#include <unistd.h> // For off_t. | |||
#include "hdr/unistd_macros.h" // For off_t. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is for off_t
it may need the correct type header instead of unistd_macros.h
libc/src/unistd/swab.h
Outdated
@@ -9,8 +9,8 @@ | |||
#ifndef LLVM_LIBC_SRC_UNISTD_SWAB_H | |||
#define LLVM_LIBC_SRC_UNISTD_SWAB_H | |||
|
|||
#include "hdr/unistd_macros.h" // For ssize_t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this also needs the correct type header
28682ec
to
e64ffcf
Compare
libc/src/unistd/linux/lseek.cpp
Outdated
@@ -14,8 +14,8 @@ | |||
#include "src/__support/OSUtil/syscall.h" // For internal syscall function. | |||
#include "src/__support/common.h" | |||
|
|||
#include <sys/syscall.h> // For syscall numbers. | |||
#include <unistd.h> // For off_t. | |||
#include "include/llvm-libc-types/off_t.h" // For off_t. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should use the proxy header at hdr/types/off_t.h
#include "include/llvm-libc-types/off_t.h" // For off_t. | |
#include "hdr/types/off_t.h" |
libc/src/unistd/swab.h
Outdated
@@ -9,8 +9,8 @@ | |||
#ifndef LLVM_LIBC_SRC_UNISTD_SWAB_H | |||
#define LLVM_LIBC_SRC_UNISTD_SWAB_H | |||
|
|||
#include "include/llvm-libc-types/ssize_t.h" // For ssize_t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
#include "include/llvm-libc-types/ssize_t.h" // For ssize_t | |
#include "hdr/types/ssize_t.h" |
e64ffcf
to
9f4c213
Compare
9f4c213
to
81b43fd
Compare
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This patch LGTM wafter the formatting fixes are done. Do you need me to merge it for you?
libc/hdr/unistd_overlay.h
Outdated
@@ -0,0 +1,69 @@ | |||
//===-- Including unistd.h in overlay mode ---------------------------------===// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this line is too long
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How should we fix it since clang-format probably is complaining about other header files with header lines that are too long? Just letting clang-format do it's thing makes it look awkward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove -
until clang-format doesn't try to wrap it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed it.
Yeah, I don't have merge perms. |
81b43fd
to
1c8f920
Compare
LGTM, I will merge once presubmits are done. |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/71/builds/12229 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/171/builds/11978 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/179/builds/11959 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/131/builds/12037 Here is the relevant piece of the build log for the reference
|
Fun, I'll get to fixing these later tonight after work. |
This reverts commit 7db970f.
Reverts #118882 Several functions are now missing necessary types in fullbuild, e.g. `off_t`, `ssize_t`. Reverting for now.
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/196/builds/2140 Here is the relevant piece of the build log for the reference
|
Fixes failures like this which I experienced: