[libc-commits] [libc] [libc] Add definitions to embedded AArch32/AArch64 (PR #142597)
via libc-commits
libc-commits at lists.llvm.org
Tue Jun 3 07:57:43 PDT 2025
https://github.com/saturn691 updated https://github.com/llvm/llvm-project/pull/142597
>From 7e2c2b63fb95bdb2b934afc20e88f026a4a0138f Mon Sep 17 00:00:00 2001
From: William Huynh <William.Huynh at arm.com>
Date: Tue, 3 Jun 2025 13:56:16 +0100
Subject: [PATCH 1/5] Add definitions to embedded AArch32/AArch64
---
libc/docs/headers/time.rst | 132 ++++++++++----------
libc/include/llvm-libc-macros/time-macros.h | 9 ++
2 files changed, 76 insertions(+), 65 deletions(-)
diff --git a/libc/docs/headers/time.rst b/libc/docs/headers/time.rst
index de82d80a2bec4..9733a176fbb25 100644
--- a/libc/docs/headers/time.rst
+++ b/libc/docs/headers/time.rst
@@ -42,72 +42,74 @@ Implementation Status
* To check date and time functions enabled for embedded system:
+ - `barebone-aarch64 <https://github.com/llvm/llvm-project/tree/main/libc/config/baremetal/aarch64/entrypoints.txt>`_
+
- `barebone-aarch32 <https://github.com/llvm/llvm-project/tree/main/libc/config/baremetal/arm/entrypoints.txt>`_
- barebone-riscv32 - to be added
-+---------------------+-----------------------------------------------+-------------------+-------------------+-------------------+-------------------+
-| <Func> | Linux | Windows | MacOS | Embedded | GPU |
-| +---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
-| | x86_64 | aarch64 | aarch32 | riscv64/riscv32 | x86_64 | aarch64 | x86_64 | aarch64 | aarch32 | riscv32 | AMD | nVidia |
-+=====================+=========+=========+=========+=================+=========+=========+=========+=========+=========+=========+=========+=========+
-| asctime | |check| | |check| | | |check| | | | | | | | | |
-+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
-| asctime_r | |check| | |check| | | |check| | | | | | | | | |
-+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
-| ctime | |check| | |check| | | |check| | | | | | | | | |
-+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
-| ctime_r | |check| | |check| | | |check| | | | | | | | | |
-+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
-| clock | |check| | |check| | | |check| | | | | | | | | |
-+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
-| clock_getcpuclockid | | | | | | | | | | | | |
-+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
-| clock_getres | | | | | | | | | | | | |
-+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
-| clock_gettime | |check| | |check| | | |check| | | | | | | | | |
-+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
-| clock_nanosleep | | | | | | | | | | | | |
-+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
-| clock_settime | | | | | | | | | | | | |
-+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
-| ctime | | | | | | | | | | | | |
-+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
-| ctime_r | | | | | | | | | | | | |
-+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
-| difftime | |check| | |check| | | |check| | | | | | | | | |
-+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
-| getdate | | | | | | | | | | | | |
-+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
-| gettimeofday | |check| | |check| | | |check| | | | | | | | | |
-+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
-| gmtime | |check| | |check| | | |check| | | | | | | | | |
-+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
-| gmtime_r | |check| | |check| | | |check| | | | | | | | | |
-+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
-| localtime | | | | | | | | | | | | |
-+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
-| localtime_r | | | | | | | | | | | | |
-+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
-| mktime | |check| | |check| | | |check| | | | | | | | | |
-+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
-| nanosleep | |check| | |check| | | |check| | | | | | | | | |
-+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
-| strftime | | | | | | | | | | | | |
-+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
-| strptime | | | | | | | | | | | | |
-+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
-| time | |check| | |check| | | |check| | | | | | | | | |
-+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
-| timer_create | | | | | | | | | | | | |
-+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
-| timer_delete | | | | | | | | | | | | |
-+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
-| timer_gettime | | | | | | | | | | | | |
-+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
-| timer_getoverrun | | | | | | | | | | | | |
-+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
-| timer_settime | | | | | | | | | | | | |
-+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
-| tzset | | | | | | | | | | | | |
-+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+
++---------------------+-----------------------------------------------+-------------------+-------------------+-----------------------------+---------+---------+
+| <Func> | Linux | Windows | MacOS | Embedded | GPU |
+| +---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| | x86_64 | aarch64 | aarch32 | riscv64/riscv32 | x86_64 | aarch64 | x86_64 | aarch64 | aarch64 | aarch32 | riscv32 | AMD | nVidia |
++=====================+=========+=========+=========+=================+=========+=========+=========+=========+=========+=========+=========+=========+=========+
+| asctime | |check| | |check| | | |check| | | | | | | | | | |
++---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| asctime_r | |check| | |check| | | |check| | | | | | | | | | |
++---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| ctime | |check| | |check| | | |check| | | | | | | | | | |
++---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| ctime_r | |check| | |check| | | |check| | | | | | | | | | |
++---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| clock | |check| | |check| | | |check| | | | | | | | | | |
++---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| clock_getcpuclockid | | | | | | | | | | | | | |
++---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| clock_getres | | | | | | | | | | | | | |
++---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| clock_gettime | |check| | |check| | | |check| | | | | | | | | | |
++---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| clock_nanosleep | | | | | | | | | | | | | |
++---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| clock_settime | | | | | | | | | | | | | |
++---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| ctime | | | | | | | | | | | | | |
++---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| ctime_r | | | | | | | | | | | | | |
++---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| difftime | |check| | |check| | | |check| | | | | | | | | | |
++---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| getdate | | | | | | | | | | | | | |
++---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| gettimeofday | |check| | |check| | | |check| | | | | | | | | | |
++---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| gmtime | |check| | |check| | | |check| | | | | | | | | | |
++---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| gmtime_r | |check| | |check| | | |check| | | | | | | | | | |
++---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| localtime | | | | | | | | | | | | | |
++---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| localtime_r | | | | | | | | | | | | | |
++---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| mktime | |check| | |check| | | |check| | | | | | | | | | |
++---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| nanosleep | |check| | |check| | | |check| | | | | | | | | | |
++---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| strftime | | | | | | | | | | | | | |
++---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| strptime | | | | | | | | | | | | | |
++---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| time | |check| | |check| | | |check| | | | | | | | | | |
++---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| timer_create | | | | | | | | | | | | | |
++---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| timer_delete | | | | | | | | | | | | | |
++---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| timer_gettime | | | | | | | | | | | | | |
++---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| timer_getoverrun | | | | | | | | | | | | | |
++---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| timer_settime | | | | | | | | | | | | | |
++---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| tzset | | | | | | | | | | | | | |
++---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
\ No newline at end of file
diff --git a/libc/include/llvm-libc-macros/time-macros.h b/libc/include/llvm-libc-macros/time-macros.h
index 445d8b3e837ed..d5b71605aaf12 100644
--- a/libc/include/llvm-libc-macros/time-macros.h
+++ b/libc/include/llvm-libc-macros/time-macros.h
@@ -5,7 +5,16 @@
#include "gpu/time-macros.h"
#elif defined(__linux__)
#include "linux/time-macros.h"
+#elif defined(__arm__) || defined(_M_ARM) || defined(__aarch64__)
+#ifdef __CLK_TCK
+#define CLOCKS_PER_SEC __CLK_TCK
+#else
+// Semihosting uses centiseconds as default
+#define CLOCKS_PER_SEC 100
#endif
+#endif
+
+#define CLK_TCK CLOCKS_PER_SEC
#define TIME_UTC 1
#define TIME_MONOTONIC 2
>From 4c7a8ba464ec79cac86605a384f5d302dfed77b9 Mon Sep 17 00:00:00 2001
From: William Huynh <William.Huynh at arm.com>
Date: Tue, 3 Jun 2025 15:16:02 +0100
Subject: [PATCH 2/5] fixup! Add definitions to embedded AArch32/AArch64
---
.../llvm-libc-macros/baremetal/CMakeLists.txt | 5 ++++
.../llvm-libc-macros/baremetal/time-macros.h | 24 +++++++++++++++++++
libc/include/llvm-libc-macros/time-macros.h | 7 +-----
3 files changed, 30 insertions(+), 6 deletions(-)
create mode 100644 libc/include/llvm-libc-macros/baremetal/CMakeLists.txt
create mode 100644 libc/include/llvm-libc-macros/baremetal/time-macros.h
diff --git a/libc/include/llvm-libc-macros/baremetal/CMakeLists.txt b/libc/include/llvm-libc-macros/baremetal/CMakeLists.txt
new file mode 100644
index 0000000000000..198bdccce813a
--- /dev/null
+++ b/libc/include/llvm-libc-macros/baremetal/CMakeLists.txt
@@ -0,0 +1,5 @@
+add_header(
+ time_macros
+ HDR
+ time-macros.h
+)
\ No newline at end of file
diff --git a/libc/include/llvm-libc-macros/baremetal/time-macros.h b/libc/include/llvm-libc-macros/baremetal/time-macros.h
new file mode 100644
index 0000000000000..4971d50a11f43
--- /dev/null
+++ b/libc/include/llvm-libc-macros/baremetal/time-macros.h
@@ -0,0 +1,24 @@
+//===-- Definition of macros from time.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_MACROS_BAREMETAL_TIME_MACROS_H
+#define LLVM_LIBC_MACROS_BAREMETAL_TIME_MACROS_H
+
+#ifdef __CLK_TCK
+#define CLOCKS_PER_SEC __CLK_TCK
+#else
+#if defined(__arm__) || defined(_M_ARM) || defined(__aarch64__) || \
+ defined(__arm64__) || defined(_M_ARM64)
+// Semihosting uses centiseconds as default
+#define CLOCKS_PER_SEC 100
+#else
+#define CLOCKS_PER_SEC 1000000
+#endif
+#endif
+
+#endif // LLVM_LIBC_MACROS_BAREMETAL_TIME_MACROS_H
diff --git a/libc/include/llvm-libc-macros/time-macros.h b/libc/include/llvm-libc-macros/time-macros.h
index d5b71605aaf12..09d60f4203335 100644
--- a/libc/include/llvm-libc-macros/time-macros.h
+++ b/libc/include/llvm-libc-macros/time-macros.h
@@ -5,13 +5,8 @@
#include "gpu/time-macros.h"
#elif defined(__linux__)
#include "linux/time-macros.h"
-#elif defined(__arm__) || defined(_M_ARM) || defined(__aarch64__)
-#ifdef __CLK_TCK
-#define CLOCKS_PER_SEC __CLK_TCK
#else
-// Semihosting uses centiseconds as default
-#define CLOCKS_PER_SEC 100
-#endif
+#include "baremetal/time-macros.h"
#endif
#define CLK_TCK CLOCKS_PER_SEC
>From 2049c08f26762d46c126a6cc73e99e32cebc29e4 Mon Sep 17 00:00:00 2001
From: William Huynh <William.Huynh at arm.com>
Date: Tue, 3 Jun 2025 15:28:55 +0100
Subject: [PATCH 3/5] fixup! fixup! Add definitions to embedded AArch32/AArch64
---
libc/include/llvm-libc-macros/baremetal/CMakeLists.txt | 2 +-
libc/include/llvm-libc-macros/baremetal/time-macros.h | 4 +++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/libc/include/llvm-libc-macros/baremetal/CMakeLists.txt b/libc/include/llvm-libc-macros/baremetal/CMakeLists.txt
index 198bdccce813a..ea08c63c00301 100644
--- a/libc/include/llvm-libc-macros/baremetal/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/baremetal/CMakeLists.txt
@@ -2,4 +2,4 @@ add_header(
time_macros
HDR
time-macros.h
-)
\ No newline at end of file
+)
diff --git a/libc/include/llvm-libc-macros/baremetal/time-macros.h b/libc/include/llvm-libc-macros/baremetal/time-macros.h
index 4971d50a11f43..1bddbf5e49ef5 100644
--- a/libc/include/llvm-libc-macros/baremetal/time-macros.h
+++ b/libc/include/llvm-libc-macros/baremetal/time-macros.h
@@ -14,7 +14,9 @@
#else
#if defined(__arm__) || defined(_M_ARM) || defined(__aarch64__) || \
defined(__arm64__) || defined(_M_ARM64)
-// Semihosting uses centiseconds as default
+// This default implementation of this function shall use semihosting
+// Semihosting uses centiseconds as default.
+// https://github.com/ARM-software/abi-aa/blob/main/semihosting/semihosting.rst#sys-clock-0x10
#define CLOCKS_PER_SEC 100
#else
#define CLOCKS_PER_SEC 1000000
>From abc603d4688309f1395bac5ce64afb473be86142 Mon Sep 17 00:00:00 2001
From: William Huynh <William.Huynh at arm.com>
Date: Tue, 3 Jun 2025 15:36:35 +0100
Subject: [PATCH 4/5] fixup! fixup! fixup! Add definitions to embedded
AArch32/AArch64
---
libc/include/llvm-libc-macros/baremetal/time-macros.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/include/llvm-libc-macros/baremetal/time-macros.h b/libc/include/llvm-libc-macros/baremetal/time-macros.h
index 1bddbf5e49ef5..3537376c4bca8 100644
--- a/libc/include/llvm-libc-macros/baremetal/time-macros.h
+++ b/libc/include/llvm-libc-macros/baremetal/time-macros.h
@@ -15,7 +15,7 @@
#if defined(__arm__) || defined(_M_ARM) || defined(__aarch64__) || \
defined(__arm64__) || defined(_M_ARM64)
// This default implementation of this function shall use semihosting
-// Semihosting uses centiseconds as default.
+// Semihosting measures time in centiseconds
// https://github.com/ARM-software/abi-aa/blob/main/semihosting/semihosting.rst#sys-clock-0x10
#define CLOCKS_PER_SEC 100
#else
>From 0d46c46f34514e28ac5a97778d181354986b4291 Mon Sep 17 00:00:00 2001
From: William Huynh <William.Huynh at arm.com>
Date: Tue, 3 Jun 2025 15:57:30 +0100
Subject: [PATCH 5/5] fixup! fixup! fixup! fixup! Add definitions to embedded
AArch32/AArch64
---
libc/include/llvm-libc-macros/time-macros.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/include/llvm-libc-macros/time-macros.h b/libc/include/llvm-libc-macros/time-macros.h
index 09d60f4203335..bd4714bf4ea54 100644
--- a/libc/include/llvm-libc-macros/time-macros.h
+++ b/libc/include/llvm-libc-macros/time-macros.h
@@ -5,7 +5,7 @@
#include "gpu/time-macros.h"
#elif defined(__linux__)
#include "linux/time-macros.h"
-#else
+#elif defined(__ELF__)
#include "baremetal/time-macros.h"
#endif
More information about the libc-commits
mailing list