Skip to content

Conversation

bassiounix
Copy link
Contributor

@bassiounix bassiounix commented Oct 12, 2025

RFC https://discourse.llvm.org/t/rfc-bounds-checking-interfaces-for-llvm-libc/87685

Add errno_t type required by Annex K interface in LLVM libc.

Copy link
Contributor Author

bassiounix commented Oct 12, 2025

@llvmbot
Copy link
Member

llvmbot commented Oct 12, 2025

@llvm/pr-subscribers-libc

Author: Muhammad Bassiouni (bassiounix)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/163094.diff

6 Files Affected:

  • (modified) libc/hdr/types/CMakeLists.txt (+9)
  • (added) libc/hdr/types/errno_t.h (+18)
  • (modified) libc/include/CMakeLists.txt (+1)
  • (modified) libc/include/errno.h.def (+2)
  • (modified) libc/include/llvm-libc-types/CMakeLists.txt (+2)
  • (added) libc/include/llvm-libc-types/errno_t.h (+18)
diff --git a/libc/hdr/types/CMakeLists.txt b/libc/hdr/types/CMakeLists.txt
index 21971a4004760..89414f419a7f0 100644
--- a/libc/hdr/types/CMakeLists.txt
+++ b/libc/hdr/types/CMakeLists.txt
@@ -162,6 +162,15 @@ add_proxy_header_library(
     libc.include.fcntl
 )
 
+add_proxy_header_library(
+  errno_t
+  HDRS
+    errno_t.h
+  FULL_BUILD_DEPENDS
+    libc.include.llvm-libc-types.errno_t
+    libc.include.errno
+)
+
 add_proxy_header_library(
   fenv_t
   HDRS
diff --git a/libc/hdr/types/errno_t.h b/libc/hdr/types/errno_t.h
new file mode 100644
index 0000000000000..91706b05c9155
--- /dev/null
+++ b/libc/hdr/types/errno_t.h
@@ -0,0 +1,18 @@
+//===-- Proxy for errno_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_ERRNO_T_H
+#define LLVM_LIBC_HDR_TYPES_ERRNO_T_H
+
+#define LIBC_HAS_ANNEX_K
+
+#include "include/llvm-libc-types/errno_t.h"
+
+#undef LIBC_HAS_ANNEX_K
+
+#endif // LLVM_LIBC_HDR_TYPES_ERRNO_T_H
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index afa90e6c8b655..a6715392fe7a1 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -302,6 +302,7 @@ add_header_macro(
   DEPENDS
     .llvm-libc-macros.generic_error_number_macros
     .llvm-libc-macros.error_number_macros
+    .llvm-libc-types.errno_t
 )
 
 add_header_macro(
diff --git a/libc/include/errno.h.def b/libc/include/errno.h.def
index aa1f6c9e48444..35341c60e38b2 100644
--- a/libc/include/errno.h.def
+++ b/libc/include/errno.h.def
@@ -33,4 +33,6 @@ __END_C_DECLS
 
 #define errno (*__llvm_libc_errno())
 
+#include "llvm-libc-types/errno_t.h"
+
 #endif // LLVM_LIBC_ERRNO_H
diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index 70da983be9090..670ab71468661 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -296,3 +296,5 @@ add_header(EFI_SYSTEM_TABLE
     .EFI_TABLE_HEADER
     .char16_t
 )
+
+add_header(errno_t HDR errno_t.h)
diff --git a/libc/include/llvm-libc-types/errno_t.h b/libc/include/llvm-libc-types/errno_t.h
new file mode 100644
index 0000000000000..f99fe1266ccd1
--- /dev/null
+++ b/libc/include/llvm-libc-types/errno_t.h
@@ -0,0 +1,18 @@
+//===-- Definition of type errno_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_INCLUDE_LLVM_LIBC_TYPES_ERRNO_T_H
+#define LLVM_LIBC_INCLUDE_LLVM_LIBC_TYPES_ERRNO_T_H
+
+#ifdef LIBC_HAS_ANNEX_K
+
+typedef int errno_t;
+
+#endif // LIBC_HAS_ANNEX_K
+
+#endif // LLVM_LIBC_INCLUDE_LLVM_LIBC_TYPES_ERRNO_T_H

@bassiounix bassiounix marked this pull request as ready for review October 12, 2025 19:26
@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-12-_libc_annex_k_add_errno_t branch from d526d47 to b00886e Compare October 13, 2025 18:15
@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-12-_libc_annex_k_add_errno_t branch from be83e0f to d405dd7 Compare October 16, 2025 23:01
@bassiounix bassiounix changed the base branch from main to users/bassiounix/spr/10-12-_libc_annex_k_add_annex_k_support_macros October 16, 2025 23:01
@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-12-_libc_annex_k_add_annex_k_support_macros branch from 11870cc to 2a3f07f Compare October 16, 2025 23:01
Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM

#ifndef LLVM_LIBC_HDR_TYPES_ERRNO_T_H
#define LLVM_LIBC_HDR_TYPES_ERRNO_T_H

#define LIBC_HAS_ANNEX_K
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think these guards are necessary since there are equivalent ones inside of the type header.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are not guards. I am defining this macro and undef it to use this type inside the code base to be able to build libc. That's what I understood about the hdr/ includes from the docs. Please correct me if I'm wrong.

@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-12-_libc_annex_k_add_errno_t branch 2 times, most recently from 9b69087 to 5c7b9a7 Compare October 18, 2025 13:50
@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-12-_libc_annex_k_add_annex_k_support_macros branch from 62b1efa to 1d013b7 Compare October 18, 2025 13:50
@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-12-_libc_annex_k_add_annex_k_support_macros branch from 1d013b7 to b16ae89 Compare October 18, 2025 14:40
@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-12-_libc_annex_k_add_errno_t branch from 5c7b9a7 to 6442985 Compare October 18, 2025 14:40
@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-12-_libc_annex_k_add_annex_k_support_macros branch from b16ae89 to dff862b Compare October 18, 2025 15:02
@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-12-_libc_annex_k_add_errno_t branch from 6442985 to 8bcde7f Compare October 18, 2025 15:02
Base automatically changed from users/bassiounix/spr/10-12-_libc_annex_k_add_annex_k_support_macros to main October 22, 2025 18:25
@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-12-_libc_annex_k_add_errno_t branch from 8bcde7f to 370104d Compare October 22, 2025 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants