[libc-commits] [libc] [libc] Add unistd overlay (PR #118882)
via libc-commits
libc-commits at lists.llvm.org
Thu Dec 5 13:56:21 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Tristan Ross (RossComputerGuy)
<details>
<summary>Changes</summary>
Fixes failures like this which I experienced:
```
FAILED: src/unistd/linux/CMakeFiles/libc.src.unistd.linux.read.dir/read.cpp.o
/nix/store/2r2xi5pbg29bsmqywsm5zgl8l7adky4i-gcc-wrapper-13.3.0/bin/g++ -DLIBC_NAMESPACE=__llvm_libc -D_DEBUG -I/build/libc-src-20.0.0-unstable-2024-12-05/libc -isystem /build/libc-src-20.0.0-unstable-2024-12-05/libc/build/include -g -std=gnu++17 -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_ADD_NULL_CHECKS -DLIBC_COPT_PUBLIC_PACKAGING -MD -MT src/unistd/linux/CMakeFiles/libc.src.unistd.linux.read.dir/read.cpp.o -MF src/unistd/linux/CMakeFiles/libc.src.unistd.linux.read.dir/read.cpp.o.d -o src/unistd/linux/CMakeFiles/libc.src.unistd.linux.read.dir/read.cpp.o -c /build/libc-src-20.0.0-unstable-2024-12-05/libc/src/unistd/linux/read.cpp
次のファイルから読み込み: /build/libc-src-20.0.0-unstable-2024-12-05/libc/src/__support/OSUtil/linux/syscall.h:13,
次から読み込み: /build/libc-src-20.0.0-unstable-2024-12-05/libc/src/__support/OSUtil/syscall.h:15,
次から読み込み: /build/libc-src-20.0.0-unstable-2024-12-05/libc/src/unistd/linux/read.cpp:11:
/build/libc-src-20.0.0-unstable-2024-12-05/libc/src/unistd/linux/read.cpp:20:29: エラー: ‘ssize_t __llvm_libc::read(int, void*, size_t)’ が外部シンボル ‘read’ の別名となっています
20 | LLVM_LIBC_FUNCTION(ssize_t, read, (int fd, void *buf, size_t count)) {
| ^~~~
/build/libc-src-20.0.0-unstable-2024-12-05/libc/src/__support/common.h:46:34: 備考: in definition of macro ‘LLVM_LIBC_FUNCTION_IMPL’
46 | decltype(LIBC_NAMESPACE::name) name [[gnu::alias(#name)]]; \
| ^~~~
/build/libc-src-20.0.0-unstable-2024-12-05/libc/src/unistd/linux/read.cpp:20:1: 備考: in expansion of macro ‘LLVM_LIBC_FUNCTION’
20 | LLVM_LIBC_FUNCTION(ssize_t, read, (int fd, void *buf, size_t count)) {
| ^~~~~~~~~~~~~~~~~~
```
---
Full diff: https://github.com/llvm/llvm-project/pull/118882.diff
7 Files Affected:
- (modified) libc/hdr/unistd_macros.h (+1-1)
- (added) libc/hdr/unistd_overlay.h (+69)
- (modified) libc/src/unistd/getcwd.h (+1-1)
- (modified) libc/src/unistd/pread.h (+1-1)
- (modified) libc/src/unistd/read.h (+1-1)
- (modified) libc/src/unistd/readlink.h (+1-1)
- (modified) libc/src/unistd/readlinkat.h (+1-1)
``````````diff
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 {
``````````
</details>
https://github.com/llvm/llvm-project/pull/118882
More information about the libc-commits
mailing list