Skip to content

Commit

Permalink
[libc++] Add initial support for picolibc
Browse files Browse the repository at this point in the history
Picolibc is a C Standard Library that is commonly used in embedded
environments. This patch adds initial support for this configuration
along with pre-commit CI. As of this patch, the test suite only builds
the tests and nothing is run. A follow-up patch will make the test suite
actually run the tests.

Differential Revision: https://reviews.llvm.org/D154246
  • Loading branch information
mplatings authored and ldionne committed Nov 29, 2023
1 parent 7eb3103 commit 8aeaceb
Show file tree
Hide file tree
Showing 63 changed files with 441 additions and 14 deletions.
38 changes: 38 additions & 0 deletions libcxx/cmake/caches/Armv7M-picolibc.cmake
@@ -0,0 +1,38 @@
set(CMAKE_ASM_COMPILER_TARGET "armv7m-none-eabi" CACHE STRING "")
set(CMAKE_CXX_COMPILER_TARGET "armv7m-none-eabi" CACHE STRING "")
set(CMAKE_CXX_FLAGS "-mfloat-abi=soft" CACHE STRING "")
set(CMAKE_C_COMPILER_TARGET "armv7m-none-eabi" CACHE STRING "")
set(CMAKE_C_FLAGS "-mfloat-abi=soft" CACHE STRING "")
set(CMAKE_SYSTEM_NAME Generic CACHE STRING "")
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY CACHE STRING "")
set(COMPILER_RT_BAREMETAL_BUILD ON CACHE BOOL "")
set(COMPILER_RT_BUILD_LIBFUZZER OFF CACHE BOOL "")
set(COMPILER_RT_BUILD_PROFILE OFF CACHE BOOL "")
set(COMPILER_RT_BUILD_SANITIZERS OFF CACHE BOOL "")
set(COMPILER_RT_BUILD_XRAY OFF CACHE BOOL "")
set(COMPILER_RT_DEFAULT_TARGET_ONLY ON CACHE BOOL "")
set(LIBCXXABI_BAREMETAL ON CACHE BOOL "")
set(LIBCXXABI_ENABLE_ASSERTIONS OFF CACHE BOOL "")
set(LIBCXXABI_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
set(LIBCXXABI_ENABLE_STATIC ON CACHE BOOL "")
set(LIBCXXABI_ENABLE_THREADS OFF CACHE BOOL "")
set(LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
set(LIBCXX_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
set(LIBCXX_ENABLE_FILESYSTEM OFF CACHE STRING "")
set(LIBCXX_ENABLE_MONOTONIC_CLOCK OFF CACHE BOOL "")
set(LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
set(LIBCXX_ENABLE_RTTI OFF CACHE BOOL "")
set(LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
set(LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
set(LIBCXX_ENABLE_THREADS OFF CACHE BOOL "")
set(LIBCXX_ENABLE_WIDE_CHARACTERS OFF CACHE BOOL "")
set(LIBCXX_INCLUDE_BENCHMARKS OFF CACHE BOOL "")
set(LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
set(LIBUNWIND_ENABLE_SHARED OFF CACHE BOOL "")
set(LIBUNWIND_ENABLE_STATIC ON CACHE BOOL "")
set(LIBUNWIND_ENABLE_THREADS OFF CACHE BOOL "")
set(LIBUNWIND_IS_BAREMETAL ON CACHE BOOL "")
set(LIBUNWIND_REMEMBER_HEAP_ALLOC ON CACHE BOOL "")
set(LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "")
21 changes: 11 additions & 10 deletions libcxx/docs/index.rst
Expand Up @@ -124,16 +124,17 @@ GCC 12 In C++11 or later only latest stable release pe

Libc++ also supports common platforms and architectures:

=============== ========================= ============================
Target platform Target architecture Notes
=============== ========================= ============================
macOS 10.13+ i386, x86_64, arm64
FreeBSD 12+ i386, x86_64, arm
Linux i386, x86_64, arm, arm64 Only glibc-2.24 and later and no other libc is officially supported
Android 5.0+ i386, x86_64, arm, arm64
Windows i386, x86_64 Both MSVC and MinGW style environments, ABI in MSVC environments is :doc:`unstable <DesignDocs/ABIVersioning>`
AIX 7.2TL5+ powerpc, powerpc64
=============== ========================= ============================
===================== ========================= ============================
Target platform Target architecture Notes
===================== ========================= ============================
macOS 10.13+ i386, x86_64, arm64
FreeBSD 12+ i386, x86_64, arm
Linux i386, x86_64, arm, arm64 Only glibc-2.24 and later and no other libc is officially supported
Android 5.0+ i386, x86_64, arm, arm64
Windows i386, x86_64 Both MSVC and MinGW style environments, ABI in MSVC environments is :doc:`unstable <DesignDocs/ABIVersioning>`
AIX 7.2TL5+ powerpc, powerpc64
Embedded (picolibc) arm Support for building with picolibc is currently work-in-progress
===================== ========================= ============================

Generally speaking, libc++ should work on any platform that provides a fairly complete
C Standard Library. It is also possible to turn off parts of the library for use on
Expand Down
42 changes: 42 additions & 0 deletions libcxx/test/configs/armv7m-picolibc-libc++.cfg.in
@@ -0,0 +1,42 @@
lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg')

libc_linker_script = '@CMAKE_INSTALL_PREFIX@/lib/picolibcpp.ld'

config.substitutions.append(('%{flags}', '--sysroot=@CMAKE_INSTALL_PREFIX@'))

config.substitutions.append(('%{compile_flags}',
'-nostdinc++ -I %{include} -I %{target-include} -I %{libcxx}/test/support'

# Disable warnings in cxx_atomic_impl.h:
# "large atomic operation may incur significant performance penalty; the
# access size (4 bytes) exceeds the max lock-free size (0 bytes)"
' -Wno-atomic-alignment'

# Various libc++ headers check for the definition of _NEWLIB_VERSION
# which for picolibc is defined in picolibc.h.
' -include picolibc.h'
))
config.substitutions.append(('%{link_flags}',
'-nostdlib -nostdlib++ -L %{lib} -lc++ -lc++abi'
' -lc -lm -lclang_rt.builtins -lsemihost -lcrt0-semihost' +
' -T {}'.format(libc_linker_script) +
' -Wl,--defsym=__flash=0x0'
' -Wl,--defsym=__flash_size=0x400000'
' -Wl,--defsym=__ram=0x21000000'
' -Wl,--defsym=__ram_size=0x1000000'
' -Wl,--defsym=__stack_size=0x1000'
))
config.substitutions.append(('%{exec}',
'true' # TODO use qemu-system-arm
))
config.available_features.add('libcxx-fake-executor')

import os, site
site.addsitedir(os.path.join('@LIBCXX_SOURCE_DIR@', 'utils'))
import libcxx.test.params, libcxx.test.config
libcxx.test.config.configure(
libcxx.test.params.DEFAULT_PARAMETERS,
libcxx.test.features.DEFAULT_FEATURES,
config,
lit_config
)
Expand Up @@ -8,6 +8,7 @@
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: target={{.+}}-windows-gnu
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics

// static constexpr bool is_always_lock_free = implementation-defined;
// bool is_lock_free() const volatile noexcept;
Expand Down
3 changes: 3 additions & 0 deletions libcxx/test/libcxx/clang_modules_include.gen.py
Expand Up @@ -39,6 +39,9 @@
// TODO: Investigate this failure
// UNSUPPORTED{BLOCKLIT}: LIBCXX-FREEBSD-FIXME
// TODO: Investigate this failure
// UNSUPPORTED{BLOCKLIT}: LIBCXX-PICOLIBC-FIXME
{lit_header_restrictions.get(header, '')}
#include <{header}>
Expand Down
2 changes: 2 additions & 0 deletions libcxx/test/libcxx/selftest/dsl/dsl.sh.py
Expand Up @@ -6,6 +6,8 @@
#
# ===----------------------------------------------------------------------===##

# XFAIL: libcxx-fake-executor

# Note: We prepend arguments with 'x' to avoid thinking there are too few
# arguments in case an argument is an empty string.
# RUN: %{python} %s x%S x%T x%{substitutions}
Expand Down
1 change: 1 addition & 0 deletions libcxx/test/libcxx/selftest/pass.cpp/run-error.pass.cpp
Expand Up @@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: libcxx-fake-executor
// XFAIL: *

// Make sure the test DOES NOT pass if it fails at runtime.
Expand Down
1 change: 1 addition & 0 deletions libcxx/test/libcxx/selftest/pass.mm/run-error.pass.mm
Expand Up @@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//

// REQUIRES: objective-c++
// UNSUPPORTED: libcxx-fake-executor

// XFAIL: *

Expand Down
8 changes: 6 additions & 2 deletions libcxx/test/libcxx/system_reserved_names.gen.py
Expand Up @@ -63,7 +63,8 @@
#endif
// Test that libc++ doesn't use names that collide with FreeBSD system macros.
#ifndef __FreeBSD__
// newlib and picolibc also define these macros
#if !defined(__FreeBSD__) && !defined(_NEWLIB_VERSION)
# define __null_sentinel SYSTEM_RESERVED_NAME
# define __generic SYSTEM_RESERVED_NAME
#endif
Expand Down Expand Up @@ -101,7 +102,10 @@
# define __pre SYSTEM_RESERVED_NAME
#endif
#define __input SYSTEM_RESERVED_NAME
// Newlib & picolibc use __input as a parameter name of a64l & l64a
#ifndef _NEWLIB_VERSION
# define __input SYSTEM_RESERVED_NAME
#endif
#define __output SYSTEM_RESERVED_NAME
#define __acquire SYSTEM_RESERVED_NAME
Expand Down
Expand Up @@ -8,6 +8,7 @@
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: target={{.+}}-windows-gnu
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics

// floating-point-type operator=(floating-point-type) volatile noexcept;
// floating-point-type operator=(floating-point-type) noexcept;
Expand Down
Expand Up @@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics

// bool compare_exchange_strong(T& expected, T desired,
// memory_order success, memory_order failure) volatile noexcept;
Expand Down
Expand Up @@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics

// bool compare_exchange_weak(T& expected, T desired,
// memory_order success, memory_order failure) volatile noexcept;
Expand Down
Expand Up @@ -8,6 +8,7 @@
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: target={{.+}}-windows-gnu
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics

// constexpr atomic() noexcept;
// constexpr atomic(floating-point-type) noexcept;
Expand Down
Expand Up @@ -11,6 +11,7 @@
// XFAIL: tsan
// XFAIL: target={{x86_64-.*}} && msan
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics

// T exchange(T, memory_order = memory_order::seq_cst) volatile noexcept;
// T exchange(T, memory_order = memory_order::seq_cst) noexcept;
Expand Down
Expand Up @@ -13,6 +13,7 @@
// Hangs with msan.
// UNSUPPORTED: msan
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics

// floating-point-type fetch_add(floating-point-type,
// memory_order = memory_order::seq_cst) volatile noexcept;
Expand Down
Expand Up @@ -13,6 +13,7 @@
// Hangs with msan.
// UNSUPPORTED: msan
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics

// floating-point-type fetch_sub(floating-point-type,
// memory_order = memory_order::seq_cst) volatile noexcept;
Expand Down
Expand Up @@ -10,6 +10,7 @@
// Clang's support for atomic operations on long double is broken. See https://github.com/llvm/llvm-project/issues/72893
// XFAIL: tsan
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics

// floating-point-type load(memory_order = memory_order::seq_cst) volatile noexcept;
// floating-point-type load(memory_order = memory_order::seq_cst) noexcept;
Expand Down
Expand Up @@ -8,6 +8,7 @@
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: target={{.+}}-windows-gnu
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics

// static constexpr bool is_always_lock_free = implementation-defined;
// bool is_lock_free() const volatile noexcept;
Expand Down
Expand Up @@ -9,6 +9,7 @@
// XFAIL: availability-synchronization_library-missing
// UNSUPPORTED: c++03, c++11, c++14, c++17
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics

// void notify_all() volatile noexcept;
// void notify_all() noexcept;
Expand Down
Expand Up @@ -9,6 +9,7 @@
// XFAIL: availability-synchronization_library-missing
// UNSUPPORTED: c++03, c++11, c++14, c++17
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics

// void notify_one() volatile noexcept;
// void notify_one() noexcept;
Expand Down
Expand Up @@ -8,6 +8,7 @@
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: target={{.+}}-windows-gnu
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics

// operator floating-point-type() volatile noexcept;
// operator floating-point-type() noexcept;
Expand Down
Expand Up @@ -9,6 +9,7 @@
// UNSUPPORTED: target={{.+}}-windows-gnu
// XFAIL: LIBCXX-AIX-FIXME
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics
// Hangs with msan.
// UNSUPPORTED: msan

Expand Down
Expand Up @@ -9,6 +9,7 @@
// UNSUPPORTED: target={{.+}}-windows-gnu
// XFAIL: LIBCXX-AIX-FIXME
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics
// Hangs with msan.
// UNSUPPORTED: msan

Expand Down
Expand Up @@ -9,6 +9,7 @@
// Clang's support for atomic operations on long double is broken. See https://github.com/llvm/llvm-project/issues/72893
// XFAIL: tsan
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics

// void store(floating-point-type, memory_order = memory_order::seq_cst) volatile noexcept;
// void store(floating-point-type, memory_order = memory_order::seq_cst) noexcept;
Expand Down
Expand Up @@ -11,6 +11,7 @@
// XFAIL: tsan
// XFAIL: target={{x86_64-.*}} && msan
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics

// void wait(T old, memory_order order = memory_order::seq_cst) const volatile noexcept;
// void wait(T old, memory_order order = memory_order::seq_cst) const noexcept;
Expand Down
Expand Up @@ -6,6 +6,8 @@
//
//===----------------------------------------------------------------------===//

// XFAIL: !has-64-bit-atomics

// <atomic>

// template <>
Expand Down
Expand Up @@ -6,6 +6,8 @@
//
//===----------------------------------------------------------------------===//

// XFAIL: !has-64-bit-atomics

// <atomic>

// template<class T>
Expand Down
Expand Up @@ -6,6 +6,8 @@
//
//===----------------------------------------------------------------------===//

// XFAIL: !has-64-bit-atomics

// <atomic>

// template<class T>
Expand Down
Expand Up @@ -6,6 +6,8 @@
//
//===----------------------------------------------------------------------===//

// XFAIL: !has-64-bit-atomics

// <atomic>

// template<class T>
Expand Down
Expand Up @@ -6,6 +6,8 @@
//
//===----------------------------------------------------------------------===//

// XFAIL: !has-64-bit-atomics

// <atomic>

// template<class T>
Expand Down
Expand Up @@ -6,6 +6,8 @@
//
//===----------------------------------------------------------------------===//

// XFAIL: !has-64-bit-atomics

// <atomic>

// template<class T>
Expand Down
Expand Up @@ -6,6 +6,8 @@
//
//===----------------------------------------------------------------------===//

// XFAIL: !has-64-bit-atomics

// <atomic>

// template<class T>
Expand Down
Expand Up @@ -6,6 +6,8 @@
//
//===----------------------------------------------------------------------===//

// XFAIL: !has-64-bit-atomics

// <atomic>

// template<class T>
Expand Down
Expand Up @@ -6,6 +6,8 @@
//
//===----------------------------------------------------------------------===//

// XFAIL: !has-64-bit-atomics

// <atomic>

// template<class T>
Expand Down
Expand Up @@ -6,6 +6,8 @@
//
//===----------------------------------------------------------------------===//

// XFAIL: !has-64-bit-atomics

// <atomic>

// template<class T>
Expand Down

0 comments on commit 8aeaceb

Please sign in to comment.