Skip to content

Commit 5aed6d6

Browse files
Reland: [libc] Move off_t and stdio macros to proxy hdrs (#98384)
reland of #98215 Additionally adds proxy headers for FILE and the fopencookie types The arm32 build has been failing due to redefinitions of the off_t type. This patch fixes this by moving off_t to a proper proxy header. To do this, it also moves stdio macros to a proxy header to hopefully avoid including this proxy header alongside this public stdio.h.
1 parent 05b7b22 commit 5aed6d6

File tree

140 files changed

+415
-233
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+415
-233
lines changed

libc/config/gpu/api.td

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ def FenvAPI: PublicAPI<"fenv.h"> {
5959
}
6060

6161
def StdIOAPI : PublicAPI<"stdio.h"> {
62-
let Macros = [
63-
SimpleMacroDef<"_IOFBF", "0">,
64-
SimpleMacroDef<"_IOLBF", "1">,
65-
SimpleMacroDef<"_IONBF", "2">,
66-
];
6762
let Types = [
6863
"FILE",
6964
"off_t",

libc/config/linux/api.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ def StdIOAPI : PublicAPI<"stdio.h"> {
7676
SimpleMacroDef<"stderr", "stderr">,
7777
SimpleMacroDef<"stdin", "stdin">,
7878
SimpleMacroDef<"stdout", "stdout">,
79-
SimpleMacroDef<"_IOFBF", "0">,
80-
SimpleMacroDef<"_IOLBF", "1">,
81-
SimpleMacroDef<"_IONBF", "2">,
8279
];
8380
let Types = [
8481
"FILE",

libc/hdr/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ add_proxy_header_library(
6969
libc.include.signal
7070
)
7171

72+
add_proxy_header_library(
73+
stdio_macros
74+
HDRS
75+
stdio_macros.h
76+
FULL_BUILD_DEPENDS
77+
libc.include.stdio
78+
libc.include.llvm-libc-macros.stdio_macros
79+
libc.include.llvm-libc-macros.file_seek_macros
80+
)
81+
7282
add_proxy_header_library(
7383
sys_epoll_macros
7484
HDRS

libc/hdr/stdio_macros.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===-- Definition of macros from stdio.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_STDIO_MACROS_H
10+
#define LLVM_LIBC_HDR_STDIO_MACROS_H
11+
12+
#ifdef LIBC_FULL_BUILD
13+
14+
#include "include/llvm-libc-macros/file-seek-macros.h"
15+
#include "include/llvm-libc-macros/stdio-macros.h"
16+
17+
#else // Overlay mode
18+
19+
#include <stdio.h>
20+
21+
#endif // LLVM_LIBC_FULL_BUILD
22+
23+
#endif // LLVM_LIBC_HDR_STDIO_MACROS_H

libc/hdr/types/CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,30 @@ add_proxy_header_library(
135135
libc.include.llvm-libc-types.struct_sigaction
136136
libc.include.signal
137137
)
138+
139+
add_proxy_header_library(
140+
FILE
141+
HDRS
142+
FILE.h
143+
FULL_BUILD_DEPENDS
144+
libc.include.llvm-libc-types.FILE
145+
libc.include.stdio
146+
)
147+
148+
add_proxy_header_library(
149+
off_t
150+
HDRS
151+
off_t.h
152+
FULL_BUILD_DEPENDS
153+
libc.include.llvm-libc-types.off_t
154+
libc.include.stdio
155+
)
156+
157+
add_proxy_header_library(
158+
cookie_io_functions_t
159+
HDRS
160+
cookie_io_functions_t.h
161+
FULL_BUILD_DEPENDS
162+
libc.include.llvm-libc-types.cookie_io_functions_t
163+
libc.include.stdio
164+
)

libc/hdr/types/FILE.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Proxy for FILE ----------------------------------------------------===//
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_TYPES_FILE_H
10+
#define LLVM_LIBC_HDR_TYPES_FILE_H
11+
12+
#ifdef LIBC_FULL_BUILD
13+
14+
#include "include/llvm-libc-types/FILE.h"
15+
16+
#else // Overlay mode
17+
18+
#include <stdio.h>
19+
20+
#endif // LLVM_LIBC_FULL_BUILD
21+
22+
#endif // LLVM_LIBC_HDR_TYPES_FILE_H
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Proxy for cookie_io_functions_t -----------------------------------===//
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_TYPES_COOKIE_IO_FUNCTIONS_T_H
10+
#define LLVM_LIBC_HDR_TYPES_COOKIE_IO_FUNCTIONS_T_H
11+
12+
#ifdef LIBC_FULL_BUILD
13+
14+
#include "include/llvm-libc-types/cookie_io_functions_t.h"
15+
16+
#else // Overlay mode
17+
18+
#include <stdio.h>
19+
20+
#endif // LLVM_LIBC_FULL_BUILD
21+
22+
#endif // LLVM_LIBC_HDR_TYPES_COOKIE_IO_FUNCTIONS_T_H

libc/hdr/types/off_t.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Proxy for off_t ---------------------------------------------------===//
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_TYPES_OFF_T_H
10+
#define LLVM_LIBC_HDR_TYPES_OFF_T_H
11+
12+
#ifdef LIBC_FULL_BUILD
13+
14+
#include "include/llvm-libc-types/off_t.h"
15+
16+
#else // Overlay mode
17+
18+
#include <stdio.h>
19+
20+
#endif // LLVM_LIBC_FULL_BUILD
21+
22+
#endif // LLVM_LIBC_HDR_TYPES_OFF_T_H

libc/include/llvm-libc-macros/stdio-macros.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@
1515

1616
#define BUFSIZ 1024
1717

18+
#define _IONBF 2
19+
#define _IOLBF 1
20+
#define _IOFBF 0
21+
1822
#endif // LLVM_LIBC_MACROS_STDIO_MACROS_H

libc/newhdrgen/yaml/stdio.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
header: stdio.h
22
macros:
3-
- macro_name: _IONBF
4-
macro_value: 2
5-
- macro_name: _IOLBF
6-
macro_value: 1
7-
- macro_name: _IOFBF
8-
macro_value: 0
93
- macro_name: stdout
104
macro_value: stdout
115
- macro_name: stdin

libc/src/__support/File/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ add_object_library(
1616
libc.src.__support.CPP.span
1717
libc.src.__support.threads.mutex
1818
libc.src.__support.error_or
19+
libc.hdr.types.off_t
20+
libc.hdr.stdio_macros
1921
)
2022

2123
add_object_library(

libc/src/__support/File/file.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88

99
#include "file.h"
1010

11+
#include "hdr/stdio_macros.h"
12+
#include "hdr/types/off_t.h"
1113
#include "src/__support/CPP/new.h"
1214
#include "src/__support/CPP/span.h"
1315
#include "src/errno/libc_errno.h" // For error macros
1416

15-
#include <stdio.h>
16-
#include <stdlib.h>
17-
1817
namespace LIBC_NAMESPACE {
1918

2019
FileIOResult File::write_unlocked(const void *data, size_t len) {

libc/src/__support/File/file.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
#ifndef LLVM_LIBC_SRC___SUPPORT_FILE_FILE_H
1010
#define LLVM_LIBC_SRC___SUPPORT_FILE_FILE_H
1111

12-
#include "include/llvm-libc-types/off_t.h"
12+
#include "hdr/stdio_macros.h"
13+
#include "hdr/types/off_t.h"
1314
#include "src/__support/CPP/new.h"
1415
#include "src/__support/error_or.h"
1516
#include "src/__support/macros/properties/architectures.h"

libc/src/__support/File/linux/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ add_object_library(
55
file.cpp
66
HDRS
77
file.h
8+
lseekImpl.h
89
DEPENDS
910
libc.include.fcntl
1011
libc.include.stdio
@@ -15,6 +16,9 @@ add_object_library(
1516
libc.src.errno.errno
1617
libc.src.__support.error_or
1718
libc.src.__support.File.file
19+
libc.hdr.types.off_t
20+
libc.hdr.types.FILE
21+
libc.hdr.stdio_macros
1822
)
1923

2024
add_object_library(
@@ -23,6 +27,8 @@ add_object_library(
2327
stdout.cpp
2428
DEPENDS
2529
.file
30+
libc.hdr.types.FILE
31+
libc.hdr.stdio_macros
2632
)
2733

2834
add_object_library(
@@ -31,6 +37,8 @@ add_object_library(
3137
stdin.cpp
3238
DEPENDS
3339
.file
40+
libc.hdr.types.FILE
41+
libc.hdr.stdio_macros
3442
)
3543

3644
add_object_library(
@@ -39,6 +47,8 @@ add_object_library(
3947
stderr.cpp
4048
DEPENDS
4149
.file
50+
libc.hdr.types.FILE
51+
libc.hdr.stdio_macros
4252
)
4353

4454
add_object_library(

libc/src/__support/File/linux/file.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88

99
#include "file.h"
1010

11+
#include "hdr/stdio_macros.h"
12+
#include "hdr/types/off_t.h"
1113
#include "src/__support/CPP/new.h"
1214
#include "src/__support/File/file.h"
1315
#include "src/__support/File/linux/lseekImpl.h"
1416
#include "src/__support/OSUtil/fcntl.h"
1517
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
1618
#include "src/errno/libc_errno.h" // For error macros
1719

18-
#include <fcntl.h> // For mode_t and other flags to the open syscall
19-
#include <stdio.h>
20+
#include <fcntl.h> // For mode_t and other flags to the open syscall
2021
#include <sys/stat.h> // For S_IS*, S_IF*, and S_IR* flags.
2122
#include <sys/syscall.h> // For syscall numbers
2223

libc/src/__support/File/linux/file.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "hdr/types/off_t.h"
910
#include "src/__support/File/file.h"
1011

1112
namespace LIBC_NAMESPACE {

libc/src/__support/File/linux/lseekImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
#ifndef LLVM_LIBC_SRC___SUPPORT_FILE_LINUX_LSEEKIMPL_H
1010
#define LLVM_LIBC_SRC___SUPPORT_FILE_LINUX_LSEEKIMPL_H
1111

12+
#include "hdr/types/off_t.h"
1213
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
1314
#include "src/__support/common.h"
1415
#include "src/__support/error_or.h"
1516
#include "src/errno/libc_errno.h"
1617

1718
#include <stdint.h> // For uint64_t.
1819
#include <sys/syscall.h> // For syscall numbers.
19-
#include <unistd.h> // For off_t.
2020

2121
namespace LIBC_NAMESPACE {
2222
namespace internal {

libc/src/__support/File/linux/stderr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "file.h"
10-
#include <stdio.h>
10+
#include "hdr/stdio_macros.h"
11+
#include "hdr/types/FILE.h"
1112

1213
namespace LIBC_NAMESPACE {
1314

libc/src/__support/File/linux/stdin.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "file.h"
10-
#include <stdio.h>
10+
#include "hdr/stdio_macros.h"
11+
#include "hdr/types/FILE.h"
1112

1213
namespace LIBC_NAMESPACE {
1314

libc/src/__support/File/linux/stdout.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "file.h"
10-
#include <stdio.h>
10+
#include "hdr/stdio_macros.h"
11+
#include "hdr/types/FILE.h"
1112

1213
namespace LIBC_NAMESPACE {
1314

libc/src/__support/OSUtil/linux/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ add_object_library(
2121
libc.hdr.types.struct_flock
2222
libc.hdr.types.struct_flock64
2323
libc.hdr.types.struct_f_owner_ex
24+
libc.hdr.types.off_t
2425
)

libc/src/__support/OSUtil/linux/fcntl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "src/__support/OSUtil/fcntl.h"
1010

1111
#include "hdr/fcntl_macros.h"
12+
#include "hdr/types/off_t.h"
1213
#include "hdr/types/struct_f_owner_ex.h"
1314
#include "hdr/types/struct_flock.h"
1415
#include "hdr/types/struct_flock64.h"

libc/src/gpu/rpc_fprintf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#ifndef LLVM_LIBC_SRC_GPU_RPC_HOST_CALL_H
1010
#define LLVM_LIBC_SRC_GPU_RPC_HOST_CALL_H
1111

12+
#include "hdr/types/FILE.h"
1213
#include <stddef.h>
13-
#include <stdio.h>
1414

1515
namespace LIBC_NAMESPACE {
1616

0 commit comments

Comments
 (0)