[libc-commits] [libc] [libc] Add loff_t type (PR #204641)
Jeff Bailey via libc-commits
libc-commits at lists.llvm.org
Tue Jun 23 09:34:31 PDT 2026
https://github.com/kaladron updated https://github.com/llvm/llvm-project/pull/204641
>From 2e9c41f292f50b0d02f5944adfe015a0a2b2a32c Mon Sep 17 00:00:00 2001
From: Jeff Bailey <jbailey at raspberryginger.com>
Date: Thu, 18 Jun 2026 17:57:50 +0100
Subject: [PATCH 1/2] [libc] Add loff_t type
Added loff_t type definition. This is a Linux extension required for
large file offsets.
* llvm-libc-types/loff_t.h: Include linux/loff_t.h on Linux.
* llvm-libc-types/linux/loff_t.h: Added Linux definition using __kernel_loff_t.
* llvm-libc-types/CMakeLists.txt: Include linux subdirectory and add dependency for loff_t.
* llvm-libc-types/linux/CMakeLists.txt: Registered loff_t.
* sys/types.yaml: Added loff_t to sys/types.
* libc/include/CMakeLists.txt: Added dependency to sys_types target.
Assisted-by: Automated tooling, human reviewed.
---
libc/include/CMakeLists.txt | 1 +
libc/include/llvm-libc-types/CMakeLists.txt | 8 +++++++
.../llvm-libc-types/linux/CMakeLists.txt | 5 +++++
libc/include/llvm-libc-types/linux/loff_t.h | 21 +++++++++++++++++++
libc/include/llvm-libc-types/loff_t.h | 21 +++++++++++++++++++
libc/include/sys/types.yaml | 1 +
6 files changed, 57 insertions(+)
create mode 100644 libc/include/llvm-libc-types/linux/CMakeLists.txt
create mode 100644 libc/include/llvm-libc-types/linux/loff_t.h
create mode 100644 libc/include/llvm-libc-types/loff_t.h
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 549dbd9e4c3f8..8d980cfbd3d0b 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -877,6 +877,7 @@ add_header_macro(
.llvm-libc-types.gid_t
.llvm-libc-types.ino_t
.llvm-libc-types.key_t
+ .llvm-libc-types.loff_t
.llvm-libc-types.mode_t
.llvm-libc-types.nlink_t
.llvm-libc-types.off_t
diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index 46b0eb7d71183..c0c600983ba12 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -1,3 +1,6 @@
+if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
+ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
+endif()
add_header(off64_t HDR off64_t.h)
add_header(size_t HDR size_t.h)
add_header(
@@ -48,6 +51,11 @@ add_header(
)
add_header(ldiv_t HDR ldiv_t.h)
add_header(lldiv_t HDR lldiv_t.h)
+if(TARGET libc.include.llvm-libc-types.${LIBC_TARGET_OS}.loff_t)
+ add_header(loff_t HDR loff_t.h DEPENDS .${LIBC_TARGET_OS}.loff_t)
+else()
+ add_header(loff_t HDR loff_t.h)
+endif()
add_header(FILE HDR FILE.h)
add_header(fd_set HDR fd_set.h DEPENDS libc.include.llvm-libc-macros.sys_select_macros)
add_header(fenv_t HDR fenv_t.h)
diff --git a/libc/include/llvm-libc-types/linux/CMakeLists.txt b/libc/include/llvm-libc-types/linux/CMakeLists.txt
new file mode 100644
index 0000000000000..ccb986a7b54c8
--- /dev/null
+++ b/libc/include/llvm-libc-types/linux/CMakeLists.txt
@@ -0,0 +1,5 @@
+add_header(
+ loff_t
+ HDR
+ loff_t.h
+)
diff --git a/libc/include/llvm-libc-types/linux/loff_t.h b/libc/include/llvm-libc-types/linux/loff_t.h
new file mode 100644
index 0000000000000..408f9bdb9754e
--- /dev/null
+++ b/libc/include/llvm-libc-types/linux/loff_t.h
@@ -0,0 +1,21 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of loff_t type for Linux.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_LINUX_LOFF_T_H
+#define LLVM_LIBC_TYPES_LINUX_LOFF_T_H
+
+#include <asm/posix_types.h>
+
+typedef __kernel_loff_t loff_t;
+
+#endif // LLVM_LIBC_TYPES_LINUX_LOFF_T_H
diff --git a/libc/include/llvm-libc-types/loff_t.h b/libc/include/llvm-libc-types/loff_t.h
new file mode 100644
index 0000000000000..c69c7463c920c
--- /dev/null
+++ b/libc/include/llvm-libc-types/loff_t.h
@@ -0,0 +1,21 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Fallback definition of loff_t type.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_LOFF_T_H
+#define LLVM_LIBC_TYPES_LOFF_T_H
+
+#if defined(__linux__)
+#include "linux/loff_t.h"
+#endif
+
+#endif // LLVM_LIBC_TYPES_LOFF_T_H
diff --git a/libc/include/sys/types.yaml b/libc/include/sys/types.yaml
index 605b0c9258841..37c58e708af34 100644
--- a/libc/include/sys/types.yaml
+++ b/libc/include/sys/types.yaml
@@ -9,6 +9,7 @@ types:
- type_name: gid_t
- type_name: ino_t
- type_name: key_t
+ - type_name: loff_t
- type_name: mode_t
- type_name: nlink_t
- type_name: off_t
>From 92ea0a971c7ee9509311cd2f9c27c9f591698412 Mon Sep 17 00:00:00 2001
From: Jeff Bailey <jbailey at raspberryginger.com>
Date: Tue, 23 Jun 2026 17:34:13 +0100
Subject: [PATCH 2/2] [libc] Fix file description in loff_t.h
Corrected the \file description in the generic loff_t.h header to
reflect that it is the main definition header (which includes the
Linux-specific one) rather than a fallback.
* llvm-libc-types/loff_t.h: Update file description.
Assisted-by: Automated tooling, human reviewed.
---
libc/include/llvm-libc-types/loff_t.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/include/llvm-libc-types/loff_t.h b/libc/include/llvm-libc-types/loff_t.h
index c69c7463c920c..4e95135fdb81a 100644
--- a/libc/include/llvm-libc-types/loff_t.h
+++ b/libc/include/llvm-libc-types/loff_t.h
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
///
/// \file
-/// Fallback definition of loff_t type.
+/// Definition of loff_t type.
///
//===----------------------------------------------------------------------===//
More information about the libc-commits
mailing list