Skip to content

Commit

Permalink
Reland: [libc] Move off_t and stdio macros to proxy hdrs (#98384)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
michaelrj-google committed Jul 11, 2024
1 parent 05b7b22 commit 5aed6d6
Show file tree
Hide file tree
Showing 140 changed files with 415 additions and 233 deletions.
5 changes: 0 additions & 5 deletions libc/config/gpu/api.td
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ def FenvAPI: PublicAPI<"fenv.h"> {
}

def StdIOAPI : PublicAPI<"stdio.h"> {
let Macros = [
SimpleMacroDef<"_IOFBF", "0">,
SimpleMacroDef<"_IOLBF", "1">,
SimpleMacroDef<"_IONBF", "2">,
];
let Types = [
"FILE",
"off_t",
Expand Down
3 changes: 0 additions & 3 deletions libc/config/linux/api.td
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ def StdIOAPI : PublicAPI<"stdio.h"> {
SimpleMacroDef<"stderr", "stderr">,
SimpleMacroDef<"stdin", "stdin">,
SimpleMacroDef<"stdout", "stdout">,
SimpleMacroDef<"_IOFBF", "0">,
SimpleMacroDef<"_IOLBF", "1">,
SimpleMacroDef<"_IONBF", "2">,
];
let Types = [
"FILE",
Expand Down
10 changes: 10 additions & 0 deletions libc/hdr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ add_proxy_header_library(
libc.include.signal
)

add_proxy_header_library(
stdio_macros
HDRS
stdio_macros.h
FULL_BUILD_DEPENDS
libc.include.stdio
libc.include.llvm-libc-macros.stdio_macros
libc.include.llvm-libc-macros.file_seek_macros
)

add_proxy_header_library(
sys_epoll_macros
HDRS
Expand Down
23 changes: 23 additions & 0 deletions libc/hdr/stdio_macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//===-- Definition of macros from stdio.h --------------------------------===//
//
// 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_STDIO_MACROS_H
#define LLVM_LIBC_HDR_STDIO_MACROS_H

#ifdef LIBC_FULL_BUILD

#include "include/llvm-libc-macros/file-seek-macros.h"
#include "include/llvm-libc-macros/stdio-macros.h"

#else // Overlay mode

#include <stdio.h>

#endif // LLVM_LIBC_FULL_BUILD

#endif // LLVM_LIBC_HDR_STDIO_MACROS_H
27 changes: 27 additions & 0 deletions libc/hdr/types/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,30 @@ add_proxy_header_library(
libc.include.llvm-libc-types.struct_sigaction
libc.include.signal
)

add_proxy_header_library(
FILE
HDRS
FILE.h
FULL_BUILD_DEPENDS
libc.include.llvm-libc-types.FILE
libc.include.stdio
)

add_proxy_header_library(
off_t
HDRS
off_t.h
FULL_BUILD_DEPENDS
libc.include.llvm-libc-types.off_t
libc.include.stdio
)

add_proxy_header_library(
cookie_io_functions_t
HDRS
cookie_io_functions_t.h
FULL_BUILD_DEPENDS
libc.include.llvm-libc-types.cookie_io_functions_t
libc.include.stdio
)
22 changes: 22 additions & 0 deletions libc/hdr/types/FILE.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Proxy for FILE ----------------------------------------------------===//
//
// 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_TYPES_FILE_H
#define LLVM_LIBC_HDR_TYPES_FILE_H

#ifdef LIBC_FULL_BUILD

#include "include/llvm-libc-types/FILE.h"

#else // Overlay mode

#include <stdio.h>

#endif // LLVM_LIBC_FULL_BUILD

#endif // LLVM_LIBC_HDR_TYPES_FILE_H
22 changes: 22 additions & 0 deletions libc/hdr/types/cookie_io_functions_t.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Proxy for cookie_io_functions_t -----------------------------------===//
//
// 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_TYPES_COOKIE_IO_FUNCTIONS_T_H
#define LLVM_LIBC_HDR_TYPES_COOKIE_IO_FUNCTIONS_T_H

#ifdef LIBC_FULL_BUILD

#include "include/llvm-libc-types/cookie_io_functions_t.h"

#else // Overlay mode

#include <stdio.h>

#endif // LLVM_LIBC_FULL_BUILD

#endif // LLVM_LIBC_HDR_TYPES_COOKIE_IO_FUNCTIONS_T_H
22 changes: 22 additions & 0 deletions libc/hdr/types/off_t.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Proxy for off_t ---------------------------------------------------===//
//
// 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_TYPES_OFF_T_H
#define LLVM_LIBC_HDR_TYPES_OFF_T_H

#ifdef LIBC_FULL_BUILD

#include "include/llvm-libc-types/off_t.h"

#else // Overlay mode

#include <stdio.h>

#endif // LLVM_LIBC_FULL_BUILD

#endif // LLVM_LIBC_HDR_TYPES_OFF_T_H
4 changes: 4 additions & 0 deletions libc/include/llvm-libc-macros/stdio-macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@

#define BUFSIZ 1024

#define _IONBF 2
#define _IOLBF 1
#define _IOFBF 0

#endif // LLVM_LIBC_MACROS_STDIO_MACROS_H
6 changes: 0 additions & 6 deletions libc/newhdrgen/yaml/stdio.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
header: stdio.h
macros:
- macro_name: _IONBF
macro_value: 2
- macro_name: _IOLBF
macro_value: 1
- macro_name: _IOFBF
macro_value: 0
- macro_name: stdout
macro_value: stdout
- macro_name: stdin
Expand Down
2 changes: 2 additions & 0 deletions libc/src/__support/File/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ add_object_library(
libc.src.__support.CPP.span
libc.src.__support.threads.mutex
libc.src.__support.error_or
libc.hdr.types.off_t
libc.hdr.stdio_macros
)

add_object_library(
Expand Down
5 changes: 2 additions & 3 deletions libc/src/__support/File/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@

#include "file.h"

#include "hdr/stdio_macros.h"
#include "hdr/types/off_t.h"
#include "src/__support/CPP/new.h"
#include "src/__support/CPP/span.h"
#include "src/errno/libc_errno.h" // For error macros

#include <stdio.h>
#include <stdlib.h>

namespace LIBC_NAMESPACE {

FileIOResult File::write_unlocked(const void *data, size_t len) {
Expand Down
3 changes: 2 additions & 1 deletion libc/src/__support/File/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_FILE_FILE_H
#define LLVM_LIBC_SRC___SUPPORT_FILE_FILE_H

#include "include/llvm-libc-types/off_t.h"
#include "hdr/stdio_macros.h"
#include "hdr/types/off_t.h"
#include "src/__support/CPP/new.h"
#include "src/__support/error_or.h"
#include "src/__support/macros/properties/architectures.h"
Expand Down
10 changes: 10 additions & 0 deletions libc/src/__support/File/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ add_object_library(
file.cpp
HDRS
file.h
lseekImpl.h
DEPENDS
libc.include.fcntl
libc.include.stdio
Expand All @@ -15,6 +16,9 @@ add_object_library(
libc.src.errno.errno
libc.src.__support.error_or
libc.src.__support.File.file
libc.hdr.types.off_t
libc.hdr.types.FILE
libc.hdr.stdio_macros
)

add_object_library(
Expand All @@ -23,6 +27,8 @@ add_object_library(
stdout.cpp
DEPENDS
.file
libc.hdr.types.FILE
libc.hdr.stdio_macros
)

add_object_library(
Expand All @@ -31,6 +37,8 @@ add_object_library(
stdin.cpp
DEPENDS
.file
libc.hdr.types.FILE
libc.hdr.stdio_macros
)

add_object_library(
Expand All @@ -39,6 +47,8 @@ add_object_library(
stderr.cpp
DEPENDS
.file
libc.hdr.types.FILE
libc.hdr.stdio_macros
)

add_object_library(
Expand Down
5 changes: 3 additions & 2 deletions libc/src/__support/File/linux/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@

#include "file.h"

#include "hdr/stdio_macros.h"
#include "hdr/types/off_t.h"
#include "src/__support/CPP/new.h"
#include "src/__support/File/file.h"
#include "src/__support/File/linux/lseekImpl.h"
#include "src/__support/OSUtil/fcntl.h"
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/errno/libc_errno.h" // For error macros

#include <fcntl.h> // For mode_t and other flags to the open syscall
#include <stdio.h>
#include <fcntl.h> // For mode_t and other flags to the open syscall
#include <sys/stat.h> // For S_IS*, S_IF*, and S_IR* flags.
#include <sys/syscall.h> // For syscall numbers

Expand Down
1 change: 1 addition & 0 deletions libc/src/__support/File/linux/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//

#include "hdr/types/off_t.h"
#include "src/__support/File/file.h"

namespace LIBC_NAMESPACE {
Expand Down
2 changes: 1 addition & 1 deletion libc/src/__support/File/linux/lseekImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_FILE_LINUX_LSEEKIMPL_H
#define LLVM_LIBC_SRC___SUPPORT_FILE_LINUX_LSEEKIMPL_H

#include "hdr/types/off_t.h"
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include "src/__support/error_or.h"
#include "src/errno/libc_errno.h"

#include <stdint.h> // For uint64_t.
#include <sys/syscall.h> // For syscall numbers.
#include <unistd.h> // For off_t.

namespace LIBC_NAMESPACE {
namespace internal {
Expand Down
3 changes: 2 additions & 1 deletion libc/src/__support/File/linux/stderr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
//===----------------------------------------------------------------------===//

#include "file.h"
#include <stdio.h>
#include "hdr/stdio_macros.h"
#include "hdr/types/FILE.h"

namespace LIBC_NAMESPACE {

Expand Down
3 changes: 2 additions & 1 deletion libc/src/__support/File/linux/stdin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
//===----------------------------------------------------------------------===//

#include "file.h"
#include <stdio.h>
#include "hdr/stdio_macros.h"
#include "hdr/types/FILE.h"

namespace LIBC_NAMESPACE {

Expand Down
3 changes: 2 additions & 1 deletion libc/src/__support/File/linux/stdout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
//===----------------------------------------------------------------------===//

#include "file.h"
#include <stdio.h>
#include "hdr/stdio_macros.h"
#include "hdr/types/FILE.h"

namespace LIBC_NAMESPACE {

Expand Down
1 change: 1 addition & 0 deletions libc/src/__support/OSUtil/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ add_object_library(
libc.hdr.types.struct_flock
libc.hdr.types.struct_flock64
libc.hdr.types.struct_f_owner_ex
libc.hdr.types.off_t
)
1 change: 1 addition & 0 deletions libc/src/__support/OSUtil/linux/fcntl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "src/__support/OSUtil/fcntl.h"

#include "hdr/fcntl_macros.h"
#include "hdr/types/off_t.h"
#include "hdr/types/struct_f_owner_ex.h"
#include "hdr/types/struct_flock.h"
#include "hdr/types/struct_flock64.h"
Expand Down
2 changes: 1 addition & 1 deletion libc/src/gpu/rpc_fprintf.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#ifndef LLVM_LIBC_SRC_GPU_RPC_HOST_CALL_H
#define LLVM_LIBC_SRC_GPU_RPC_HOST_CALL_H

#include "hdr/types/FILE.h"
#include <stddef.h>
#include <stdio.h>

namespace LIBC_NAMESPACE {

Expand Down
Loading

0 comments on commit 5aed6d6

Please sign in to comment.