[libc-commits] [libc] [libc] Include time.h in baremetal targets (PR #85026)

Petr Hosek via libc-commits libc-commits at lists.llvm.org
Tue Mar 12 23:47:03 PDT 2024


https://github.com/petrhosek created https://github.com/llvm/llvm-project/pull/85026

These types and conversion functions are used in embedded development.

Note that we cannot include other entrypoints such such asctime because it unconditionally uses `EOVERFLOW` which is only defined in POSIX and not in C standard. This will need to be addressed first.

>From 8233a8c758eba6df376041dd127d528581a47da5 Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Tue, 12 Mar 2024 23:43:51 -0700
Subject: [PATCH] [libc] Include time.h in baremetal targets

These types and conversion functions are used in embedded development.

Note that we cannot include other entrypoints such such asctime because
it unconditionally uses `EOVERFLOW` which is only defined in POSIX and
not in C standard. This will need to be addressed first.
---
 libc/config/baremetal/api.td                | 9 +++++++++
 libc/config/baremetal/arm/entrypoints.txt   | 3 +++
 libc/config/baremetal/arm/headers.txt       | 1 +
 libc/config/baremetal/riscv/entrypoints.txt | 3 +++
 libc/config/baremetal/riscv/headers.txt     | 1 +
 5 files changed, 17 insertions(+)

diff --git a/libc/config/baremetal/api.td b/libc/config/baremetal/api.td
index 80d0e0ba22ca51..e153c52a7b98cb 100644
--- a/libc/config/baremetal/api.td
+++ b/libc/config/baremetal/api.td
@@ -68,6 +68,15 @@ def StringAPI : PublicAPI<"string.h"> {
   let Types = ["size_t"];
 }
 
+def TimeAPI : PublicAPI<"time.h"> {
+  let Types = [
+    "clock_t",
+    "time_t",
+    "struct tm",
+    "struct timespec",
+  ];
+}
+
 def UCharAPI : PublicAPI<"uchar.h"> {
   let Types = ["mbstate_t"];
 }
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index 589ec5237e98da..fa5d12412ced28 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -180,6 +180,9 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.stdlib.strtoll
     libc.src.stdlib.strtoul
     libc.src.stdlib.strtoull
+
+    # time.h entrypoints
+    libc.src.time.difftime
 )
 
 set(TARGET_LIBM_ENTRYPOINTS
diff --git a/libc/config/baremetal/arm/headers.txt b/libc/config/baremetal/arm/headers.txt
index 962981f8a2087d..3608364e45bdeb 100644
--- a/libc/config/baremetal/arm/headers.txt
+++ b/libc/config/baremetal/arm/headers.txt
@@ -13,5 +13,6 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.string
     libc.include.strings
     libc.include.sys_queue
+    libc.include.time
     libc.include.uchar
 )
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 09de1b416e0e94..58624e8b250987 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -180,6 +180,9 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.stdlib.strtoll
     libc.src.stdlib.strtoul
     libc.src.stdlib.strtoull
+
+    # time.h entrypoints
+    libc.src.time.difftime
 )
 
 set(TARGET_LIBM_ENTRYPOINTS
diff --git a/libc/config/baremetal/riscv/headers.txt b/libc/config/baremetal/riscv/headers.txt
index 962981f8a2087d..3608364e45bdeb 100644
--- a/libc/config/baremetal/riscv/headers.txt
+++ b/libc/config/baremetal/riscv/headers.txt
@@ -13,5 +13,6 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.string
     libc.include.strings
     libc.include.sys_queue
+    libc.include.time
     libc.include.uchar
 )



More information about the libc-commits mailing list