Skip to content

Commit 240ec5a

Browse files
[libc] Move off_t and stdio macros to proxy hdrs (#98215)
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 6b84537 commit 240ec5a

File tree

21 files changed

+103
-27
lines changed

21 files changed

+103
-27
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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,12 @@ add_proxy_header_library(
135135
libc.include.llvm-libc-types.struct_sigaction
136136
libc.include.signal
137137
)
138+
139+
add_proxy_header_library(
140+
off_t
141+
HDRS
142+
off_t.h
143+
FULL_BUILD_DEPENDS
144+
libc.include.llvm-libc-types.off_t
145+
libc.include.stdio
146+
)

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: 3 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,8 @@ 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.stdio_macros
1821
)
1922

2023
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/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/stdio/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ add_entrypoint_object(
6161
HDRS
6262
fopencookie.h
6363
DEPENDS
64-
libc.include.stdio
64+
libc.hdr.stdio_macros
65+
libc.hdr.types.off_t
6566
libc.src.__support.CPP.new
6667
libc.src.__support.File.file
6768
)
@@ -74,7 +75,7 @@ add_entrypoint_object(
7475
setbuf.h
7576
DEPENDS
7677
libc.src.errno.errno
77-
libc.include.stdio
78+
libc.hdr.types.off_t
7879
libc.src.__support.File.file
7980
libc.src.__support.File.platform_file
8081
)

libc/src/stdio/fopencookie.cpp

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

99
#include "src/stdio/fopencookie.h"
10+
#include "hdr/stdio_macros.h"
11+
#include "hdr/types/off_t.h"
1012
#include "src/__support/CPP/new.h"
1113
#include "src/__support/File/file.h"
1214

1315
#include "src/errno/libc_errno.h"
14-
#include <stdio.h>
15-
#include <stdlib.h>
1616

1717
namespace LIBC_NAMESPACE {
1818

libc/src/stdio/setbuf.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "src/stdio/setbuf.h"
10+
#include "hdr/stdio_macros.h"
1011
#include "src/__support/File/file.h"
11-
1212
#include "src/errno/libc_errno.h"
13-
#include <stdio.h>
1413

1514
namespace LIBC_NAMESPACE {
1615

utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ libc_support_library(
138138
hdrs = ["hdr/float_macros.h"],
139139
)
140140

141+
libc_support_library(
142+
name = "hdr_stdio_macros",
143+
hdrs = ["hdr/stdio_macros.h"],
144+
)
145+
141146
############################ Type Proxy Header Files ###########################
142147

143148
libc_support_library(
@@ -180,6 +185,11 @@ libc_support_library(
180185
hdrs = ["hdr/types/pid_t.h"],
181186
)
182187

188+
libc_support_library(
189+
name = "types_off_t",
190+
hdrs = ["hdr/types/off_t.h"],
191+
)
192+
183193
############################### Support libraries ##############################
184194

185195
libc_support_library(
@@ -667,6 +677,8 @@ libc_support_library(
667677
":__support_error_or",
668678
":__support_threads_mutex",
669679
":errno",
680+
":hdr_stdio_macros",
681+
":types_off_t",
670682
],
671683
)
672684

@@ -678,6 +690,7 @@ libc_support_library(
678690
":__support_error_or",
679691
":__support_osutil_syscall",
680692
":errno",
693+
":types_off_t",
681694
],
682695
)
683696

0 commit comments

Comments
 (0)