[libc-commits] [libc] 3beb054 - [libc] Add a baremetal config.

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Tue Dec 20 11:44:07 PST 2022


Author: Siva Chandra Reddy
Date: 2022-12-20T19:43:45Z
New Revision: 3beb05417086443ad3314e7008090256b96741a2

URL: https://github.com/llvm/llvm-project/commit/3beb05417086443ad3314e7008090256b96741a2
DIFF: https://github.com/llvm/llvm-project/commit/3beb05417086443ad3314e7008090256b96741a2.diff

LOG: [libc] Add a baremetal config.

The config currently includes ctype, math, stdlib, inttypes and string
functions.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D140378

Added: 
    libc/config/baremetal/api.td
    libc/config/baremetal/entrypoints.txt
    libc/config/baremetal/headers.txt

Modified: 
    libc/cmake/modules/LLVMLibCArchitectures.cmake
    libc/test/utils/tools/WrapperGen/CMakeLists.txt
    libc/utils/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/libc/cmake/modules/LLVMLibCArchitectures.cmake b/libc/cmake/modules/LLVMLibCArchitectures.cmake
index 3c99f645e4867..4c0c89cd0dd60 100644
--- a/libc/cmake/modules/LLVMLibCArchitectures.cmake
+++ b/libc/cmake/modules/LLVMLibCArchitectures.cmake
@@ -121,6 +121,20 @@ else()
           "Unsupported libc target architecture ${LIBC_TARGET_ARCHITECTURE}")
 endif()
 
+if(LIBC_TARGET_OS STREQUAL "baremetal")
+  set(LIBC_TARGET_OS_IS_BAREMETAL TRUE)
+elseif(LIBC_TARGET_OS STREQUAL "linux")
+  set(LIBC_TARGET_OS_IS_LINUX TRUE)
+elseif(LIBC_TARGET_OS STREQUAL "darwin")
+  set(LIBC_TARGET_OS_IS_DARWIN TRUE)
+elseif(LIBC_TARGET_OS STREQUAL "windows")
+  set(LIBC_TARGET_OS_IS_WINDOWS TRUE)
+else()
+  message(FATAL_ERROR
+          "Unsupported libc target operating system ${LIBC_TARGET_OS}")
+endif()
+
+
 # If the compiler target triple is not the same as the triple specified by
 # LIBC_TARGET_TRIPLE, we will add a --target option if the compiler is clang.
 # If the compiler is GCC we just error out as there is no equivalent of an

diff  --git a/libc/config/baremetal/api.td b/libc/config/baremetal/api.td
new file mode 100644
index 0000000000000..6d5a4a440708c
--- /dev/null
+++ b/libc/config/baremetal/api.td
@@ -0,0 +1,26 @@
+include "config/public_api.td"
+
+include "spec/stdc.td"
+
+def CTypeAPI : PublicAPI<"ctype.h"> {
+}
+
+def IntTypesAPI : PublicAPI<"inttypes.h"> {
+  let Types = ["imaxdiv_t"];
+}
+
+def StdlibAPI : PublicAPI<"stdlib.h"> {
+  let Types = [
+    "div_t",
+    "ldiv_t",
+    "lldiv_t",
+    "size_t",
+    "__bsearchcompare_t",
+    "__qsortcompare_t",
+    "__atexithandler_t",
+  ];
+}
+
+def StringAPI : PublicAPI<"string.h"> {
+  let Types = ["size_t"];
+}

diff  --git a/libc/config/baremetal/entrypoints.txt b/libc/config/baremetal/entrypoints.txt
new file mode 100644
index 0000000000000..6efa4484b8ab4
--- /dev/null
+++ b/libc/config/baremetal/entrypoints.txt
@@ -0,0 +1,100 @@
+set(TARGET_LIBC_ENTRYPOINTS
+    # ctype.h entrypoints
+    libc.src.ctype.isalnum
+    libc.src.ctype.isalpha
+    libc.src.ctype.isascii
+    libc.src.ctype.isblank
+    libc.src.ctype.iscntrl
+    libc.src.ctype.isdigit
+    libc.src.ctype.isgraph
+    libc.src.ctype.islower
+    libc.src.ctype.isprint
+    libc.src.ctype.ispunct
+    libc.src.ctype.isspace
+    libc.src.ctype.isupper
+    libc.src.ctype.isxdigit
+    libc.src.ctype.toascii
+    libc.src.ctype.tolower
+    libc.src.ctype.toupper
+
+    # string.h entrypoints
+    libc.src.string.bcmp
+    libc.src.string.bcopy
+    libc.src.string.bzero
+    libc.src.string.memccpy
+    libc.src.string.memchr
+    libc.src.string.memcmp
+    libc.src.string.memcpy
+    libc.src.string.memmove
+    libc.src.string.mempcpy
+    libc.src.string.memrchr
+    libc.src.string.memset
+    libc.src.string.stpcpy
+    libc.src.string.stpncpy
+    libc.src.string.strcat
+    libc.src.string.strchr
+    libc.src.string.strcmp
+    libc.src.string.strcpy
+    libc.src.string.strcspn
+    libc.src.string.strlcat
+    libc.src.string.strlcpy
+    libc.src.string.strlen
+    libc.src.string.strncat
+    libc.src.string.strncmp
+    libc.src.string.strncpy
+    libc.src.string.strnlen
+    libc.src.string.strpbrk
+    libc.src.string.strrchr
+    libc.src.string.strspn
+    libc.src.string.strstr
+    libc.src.string.strtok
+    libc.src.string.strtok_r
+
+    # inttypes.h entrypoints
+    libc.src.inttypes.imaxabs
+    libc.src.inttypes.imaxdiv
+    libc.src.inttypes.strtoimax
+    libc.src.inttypes.strtoumax
+ 
+    # stdlib.h entrypoints
+    libc.src.stdlib.abs
+    libc.src.stdlib.atoi
+    libc.src.stdlib.atof
+    libc.src.stdlib.atol
+    libc.src.stdlib.atoll
+    libc.src.stdlib.bsearch
+    libc.src.stdlib.div
+    libc.src.stdlib.labs
+    libc.src.stdlib.ldiv
+    libc.src.stdlib.llabs
+    libc.src.stdlib.lldiv
+    libc.src.stdlib.qsort
+    libc.src.stdlib.strtod
+    libc.src.stdlib.strtof
+    libc.src.stdlib.strtol
+    libc.src.stdlib.strtold
+    libc.src.stdlib.strtoll
+    libc.src.stdlib.strtoul
+    libc.src.stdlib.strtoull
+)
+
+set(TARGET_LIBM_ENTRYPOINTS
+    # math.h entrypoints
+    libc.src.math.fabs
+    libc.src.math.fabsf
+    libc.src.math.fabsl
+    libc.src.math.fdim
+    libc.src.math.fdimf
+    libc.src.math.fdiml
+    libc.src.math.fmax
+    libc.src.math.fmaxf
+    libc.src.math.fmaxl
+    libc.src.math.fmin
+    libc.src.math.fminf
+    libc.src.math.fminl
+)
+
+set(TARGET_LLVMLIBC_ENTRYPOINTS
+  ${TARGET_LIBC_ENTRYPOINTS}
+  ${TARGET_LIBM_ENTRYPOINTS}
+)

diff  --git a/libc/config/baremetal/headers.txt b/libc/config/baremetal/headers.txt
new file mode 100644
index 0000000000000..cc436c7119f4a
--- /dev/null
+++ b/libc/config/baremetal/headers.txt
@@ -0,0 +1,8 @@
+set(TARGET_PUBLIC_HEADERS
+    libc.include.ctype
+    libc.include.errno
+    libc.include.inttypes
+    libc.include.math
+    libc.include.stdlib
+    libc.include.string
+)

diff  --git a/libc/test/utils/tools/WrapperGen/CMakeLists.txt b/libc/test/utils/tools/WrapperGen/CMakeLists.txt
index 0454f9ed81ee9..80a833999a5ad 100644
--- a/libc/test/utils/tools/WrapperGen/CMakeLists.txt
+++ b/libc/test/utils/tools/WrapperGen/CMakeLists.txt
@@ -1,3 +1,7 @@
+if(LIBC_TARGET_OS_IS_BAREMETAL)
+  return()
+endif()
+
 add_libc_tool_unittest(
   wrappergen_test
   SRCS 

diff  --git a/libc/utils/CMakeLists.txt b/libc/utils/CMakeLists.txt
index ef1754165c91a..1c312c3a1b805 100644
--- a/libc/utils/CMakeLists.txt
+++ b/libc/utils/CMakeLists.txt
@@ -2,7 +2,8 @@ add_subdirectory(MPFRWrapper)
 add_subdirectory(testutils)
 add_subdirectory(UnitTest)
 
-if(LLVM_LIBC_FULL_BUILD AND NOT LIBC_TARGET_ARCHITECTURE_IS_GPU)
+if(LLVM_LIBC_FULL_BUILD AND NOT
+  (LIBC_TARGET_ARCHITECTURE_IS_GPU OR LIBC_TARGET_OS_IS_BAREMETAL))
   add_subdirectory(IntegrationTest)
   add_subdirectory(tools)
 endif()


        


More information about the libc-commits mailing list