diff --git a/libcxx/cmake/caches/Armv6M-picolibc.cmake b/libcxx/cmake/caches/Armv6M-picolibc.cmake new file mode 100644 --- /dev/null +++ b/libcxx/cmake/caches/Armv6M-picolibc.cmake @@ -0,0 +1,38 @@ +set(CMAKE_ASM_COMPILER_TARGET "armv6m-none-eabi" CACHE STRING "") +set(CMAKE_CXX_COMPILER_TARGET "armv6m-none-eabi" CACHE STRING "") +set(CMAKE_CXX_FLAGS "-mfloat-abi=soft" CACHE STRING "") +set(CMAKE_C_COMPILER_TARGET "armv6m-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(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 "") +set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "") diff --git a/libcxx/docs/index.rst b/libcxx/docs/index.rst --- a/libcxx/docs/index.rst +++ b/libcxx/docs/index.rst @@ -121,15 +121,16 @@ Libc++ also supports common platforms and architectures: -=============== ========================= ============================ -Target platform Target architecture Notes -=============== ========================= ============================ -macOS 10.9+ i386, x86_64, arm64 Building the shared library itself requires targetting macOS 10.13+ -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 -Windows i386, x86_64 Both MSVC and MinGW style environments, ABI in MSVC environments is :doc:`unstable ` -AIX 7.2TL5+ powerpc, powerpc64 -=============== ========================= ============================ +===================== ========================= ============================ +Target platform Target architecture Notes +===================== ========================= ============================ +macOS 10.9+ i386, x86_64, arm64 Building the shared library itself requires targetting macOS 10.13+ +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 +Windows i386, x86_64 Both MSVC and MinGW style environments, ABI in MSVC environments is :doc:`unstable ` +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 diff --git a/libcxx/include/__atomic/cxx_atomic_impl.h b/libcxx/include/__atomic/cxx_atomic_impl.h --- a/libcxx/include/__atomic/cxx_atomic_impl.h +++ b/libcxx/include/__atomic/cxx_atomic_impl.h @@ -317,6 +317,13 @@ #define __cxx_atomic_is_lock_free(__s) __c11_atomic_is_lock_free(__s) +_LIBCPP_DIAGNOSTIC_PUSH +#ifdef __arm__ +// Disable warning "large atomic operation may incur significant performance +// penalty; the access size (4 bytes) exceeds the max lock-free size (0 bytes)" +_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Watomic-alignment") +#endif + _LIBCPP_HIDE_FROM_ABI inline void __cxx_atomic_thread_fence(memory_order __order) _NOEXCEPT { __c11_atomic_thread_fence(static_cast<__memory_order_underlying_t>(__order)); @@ -516,6 +523,8 @@ std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order)); } +_LIBCPP_DIAGNOSTIC_POP + #endif // _LIBCPP_HAS_GCC_ATOMIC_IMP, _LIBCPP_HAS_C_ATOMIC_IMP #ifdef _LIBCPP_ATOMIC_ONLY_USE_BUILTINS diff --git a/libcxx/utils/ci/BOT_OWNERS.txt b/libcxx/utils/ci/BOT_OWNERS.txt --- a/libcxx/utils/ci/BOT_OWNERS.txt +++ b/libcxx/utils/ci/BOT_OWNERS.txt @@ -10,7 +10,7 @@ N: Linaro Toolchain Working Group E: linaro-toolchain@lists.linaro.org -D: Armv7, Armv8, AArch64 +D: Arm platforms N: LLVM on Power E: powerllvm@ca.ibm.com diff --git a/libcxx/utils/ci/build-picolibc.sh b/libcxx/utils/ci/build-picolibc.sh new file mode 100755 --- /dev/null +++ b/libcxx/utils/ci/build-picolibc.sh @@ -0,0 +1,95 @@ +#!/usr/bin/env bash +#===----------------------------------------------------------------------===## +# +# 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 +# +#===----------------------------------------------------------------------===## + +set -e + +PROGNAME="$(basename "${0}")" + +function error() { printf "error: %s\n" "$*" >&2; exit 1; } + +function usage() { +cat < Path to the directory to use for building. + +--install-dir Path to the directory to install the library to. +EOF +} + +while [[ $# -gt 0 ]]; do + case ${1} in + -h|--help) + usage + exit 0 + ;; + --build-dir) + build_dir="${2}" + shift; shift + ;; + --install-dir) + install_dir="${2}" + shift; shift + ;; + *) + error "Unknown argument '${1}'" + ;; + esac +done + +for arg in build_dir install_dir; do + if [ -z ${!arg+x} ]; then + error "Missing required argument '--${arg//_/-}'" + elif [ "${!arg}" == "" ]; then + error "Argument to --${arg//_/-} must not be empty" + fi +done + + +echo "--- Downloading picolibc" +picolibc_source_dir="${build_dir}/picolibc-source" +picolibc_build_dir="${build_dir}/picolibc-build" +mkdir -p "${picolibc_source_dir}" +mkdir -p "${picolibc_build_dir}" +# Download the version of picolibc that was the latest at the time this script was written. +curl -L "https://github.com/picolibc/picolibc/archive/refs/tags/1.8.2.tar.gz" | tar -xz --strip-components=1 -C "${picolibc_source_dir}" + + +cat < "${picolibc_build_dir}/meson-cross-build.txt" +[binaries] +c = ['$CC', '--target=armv6m-none-eabi', '-mfloat-abi=soft', '-nostdlib'] +ar = 'llvm-ar' +as = 'llvm-as' +ld = 'lld' +strip = 'llvm-strip' +[host_machine] +system = 'none' +cpu_family = 'arm' +cpu = 'arm' +endian = 'little' +[properties] +skip_sanity_check = true +EOF + +venv_dir="${build_dir}/meson-venv" +python3 -m venv "${venv_dir}" +# Install the version of meson that was the latest at the time this script was written. +"${venv_dir}/bin/pip" install "meson==1.1.1" + +"${venv_dir}/bin/meson" setup \ + -Dincludedir=include -Dlibdir=lib -Dspecsdir=none -Dmultilib=false \ + --prefix "${install_dir}" \ + --cross-file "${picolibc_build_dir}/meson-cross-build.txt" \ + "${picolibc_build_dir}" \ + "${picolibc_source_dir}" + +"${venv_dir}/bin/meson" install -C "${picolibc_build_dir}" diff --git a/libcxx/utils/ci/buildkite-pipeline.yml b/libcxx/utils/ci/buildkite-pipeline.yml --- a/libcxx/utils/ci/buildkite-pipeline.yml +++ b/libcxx/utils/ci/buildkite-pipeline.yml @@ -993,6 +993,20 @@ limit: 2 timeout_in_minutes: 120 + - label: "Armv6-M picolibc" + command: "libcxx/utils/ci/run-buildbot armv6m-picolibc" + artifact_paths: + - "**/test-results.xml" + - "**/*.abilist" + agents: + queue: "libcxx-builders-linaro-arm" + arch: "aarch64" + retry: + automatic: + - exit_status: -1 # Agent was lost + limit: 2 + timeout_in_minutes: 120 + - group: "AIX" steps: - label: "AIX (32-bit)" diff --git a/libcxx/utils/ci/run-buildbot b/libcxx/utils/ci/run-buildbot --- a/libcxx/utils/ci/run-buildbot +++ b/libcxx/utils/ci/run-buildbot @@ -603,6 +603,24 @@ generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Armv7Thumb-no-exceptions.cmake" check-runtimes ;; +armv6m-picolibc) + clean + + # To make it easier to get this builder up and running, build picolibc + # from scratch. Anecdotally, the build-picolibc script takes about 16 seconds. + # This could be optimised by building picolibc into the Docker container. + ${MONOREPO_ROOT}/libcxx/utils/ci/build-picolibc.sh \ + --build-dir "${BUILD_DIR}" \ + --install-dir "${INSTALL_DIR}" + + flags="--sysroot=${INSTALL_DIR}" + generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Armv6M-picolibc.cmake" \ + -DCMAKE_C_FLAGS="${flags}" \ + -DCMAKE_CXX_FLAGS="${flags}" + + echo "--- Installing libc++, libc++abi and libunwind to a fake location" + ${NINJA} -vC "${BUILD_DIR}" install-cxx install-cxxabi install-unwind +;; clang-cl-dll) clean # TODO: Currently, building with the experimental library breaks running