Index: libc/config/CMakeLists.txt =================================================================== --- libc/config/CMakeLists.txt +++ libc/config/CMakeLists.txt @@ -1 +1,2 @@ add_subdirectory(linux) +add_subdirectory(darwin) Index: libc/config/darwin/CMakeLists.txt =================================================================== --- /dev/null +++ libc/config/darwin/CMakeLists.txt @@ -0,0 +1 @@ + Index: libc/config/darwin/platfrom_defs.h.inc =================================================================== --- /dev/null +++ libc/config/darwin/platfrom_defs.h.inc @@ -0,0 +1,15 @@ +//===----- Definition of platform specific macros for Mach-O platforms -------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +%%begin() + +#define ENTRYPOINT_SECTION_ATTRIBUTE(name) \ + __attribute__((section(".libc.entrypoint,"#name))) +#define LLVM_LIBC_ENTRYPOINT(name) ENTRYPOINT_SECTION_ATTRIBUTE(name) name + +// Note the comma in the section name!!! \ No newline at end of file Index: libc/config/darwin/x86_64/entrypoints.txt =================================================================== --- /dev/null +++ libc/config/darwin/x86_64/entrypoints.txt @@ -0,0 +1,41 @@ +set(TARGET_LIBC_ENTRYPOINTS + # errno.h entrypoints + libc.src.errno.__errno_location + + # string.h entrypoints + libc.src.string.bzero + libc.src.string.memcpy + libc.src.string.memset + libc.src.string.strcpy + libc.src.string.strcat + libc.src.string.strlen +) + +set(TARGET_LIBM_ENTRYPOINTS + # math.h entrypoints + libc.src.math.copysign + libc.src.math.copysignf + libc.src.math.ceil + libc.src.math.ceilf + libc.src.math.cosf + libc.src.math.expf + libc.src.math.exp2f + libc.src.math.fabs + libc.src.math.fabsf + libc.src.math.fabsl + libc.src.math.floor + libc.src.math.floorf + libc.src.math.frexp + libc.src.math.frexpf + libc.src.math.logb + libc.src.math.logbf + libc.src.math.modf + libc.src.math.modff + libc.src.math.round + libc.src.math.roundf + libc.src.math.sincosf + libc.src.math.sinf + libc.src.math.trunc + libc.src.math.truncf + libc.src.math.truncl +) Index: libc/config/darwin/x86_64/headers.txt =================================================================== --- /dev/null +++ libc/config/darwin/x86_64/headers.txt @@ -0,0 +1,6 @@ +set(PUBLIC_HEADERS + libc.include.errno + libc.include.math + libc.include.sys_syscall +) + Index: libc/config/linux/platfrom_defs.h.inc =================================================================== --- libc/config/linux/platfrom_defs.h.inc +++ libc/config/linux/platfrom_defs.h.inc @@ -1,4 +1,4 @@ -//===----- Definition of platform specific macros for ELF paltforms -------===// +//===----- Definition of platform specific macros for ELF platforms -------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. Index: libc/src/string/bzero.h =================================================================== --- libc/src/string/bzero.h +++ libc/src/string/bzero.h @@ -10,6 +10,7 @@ #define LLVM_LIBC_SRC_STRING_BZERO_H #include "include/string.h" +#include // size_t namespace __llvm_libc { Index: libc/src/string/memset.h =================================================================== --- libc/src/string/memset.h +++ libc/src/string/memset.h @@ -10,6 +10,7 @@ #define LLVM_LIBC_SRC_STRING_MEMSET_H #include "include/string.h" +#include // size_t namespace __llvm_libc { Index: libc/src/string/strlen.h =================================================================== --- libc/src/string/strlen.h +++ libc/src/string/strlen.h @@ -10,6 +10,7 @@ #define LLVM_LIBC_SRC_STRING_STRLEN_H #include "include/string.h" +#include // size_t namespace __llvm_libc { Index: libc/src/string/strlen.cpp =================================================================== --- libc/src/string/strlen.cpp +++ libc/src/string/strlen.cpp @@ -9,6 +9,7 @@ #include "src/string/strlen.h" #include "src/__support/common.h" +#include // size_t namespace __llvm_libc { Index: libc/test/config/darwin/CmakeLists.txt =================================================================== --- /dev/null +++ libc/test/config/darwin/CmakeLists.txt @@ -0,0 +1 @@ + Index: libc/test/config/darwin/x86_64/CMakeLists.txt =================================================================== --- /dev/null +++ libc/test/config/darwin/x86_64/CMakeLists.txt @@ -0,0 +1,9 @@ +add_libc_unittest( + libc_darwin_x86_64_strlen_test + SUITE + libc_darwin_unittests + SRCS + strlen_test.cpp + DEPENDS + libc.src.string.strlen +) Index: libc/test/config/darwin/x86_64/darwin.cpp =================================================================== --- /dev/null +++ libc/test/config/darwin/x86_64/darwin.cpp @@ -0,0 +1,24 @@ +//===-- Unittests for strlen -------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "src/string/strlen.h" +#include "utils/UnitTest/Test.h" + +TEST(StrLenTest, EmptyString) { + const char *empty = ""; + + size_t result = __llvm_libc::strlen(empty); + ASSERT_EQ((size_t)0, result); +} + +TEST(StrLenTest, AnyString) { + const char *any = "Hello World!"; + + size_t result = __llvm_libc::strlen(any); + ASSERT_EQ((size_t)12, result); +}