[llvm-dev] Compiling libc++ using GNU Arm Embedded Toolchain for arm-cortex-m4

Kacper Kowalski via llvm-dev llvm-dev at lists.llvm.org
Wed Nov 13 11:33:49 PST 2019


lately, I have been thinking about how to resolve the problem with that the
program size increases enormously when including <iostream> when compiling
with libstdc++. In this library, in <iostream> there is a static object
__ioinit initialized like so:

  // For construction of filebuffers for cout, cin, cerr, clog et. al.
  static ios_base::Init __ioinit;

This makes the program size increase enormously. The thing is that I often
compile programs for small platforms, like arm-cortex-m3 or arm-cortex-m4
(stm32, nrf52, ...). Including this header leads to the program size exceed
the FLASH memory size.

This is not a problem when you have full control over what you include. But
if you use external libraries and you don't want to mess with their
sources, or you are not able to, then it gets complicated.

To resolve this issue I found out that libc++ can be compiled with the


so I gave it a try: I started a struggle to compile libc++ and libc++ ABI
with ARMToolchain-9-2019-q4-major. Unfortunately, I failed.

This is how I build libc++:


export CC="${TOOLCHAIN_ROOT_DIR}/bin/arm-none-eabi-gcc"
export CXX="${TOOLCHAIN_ROOT_DIR}/bin/arm-none-eabi-g++"

C_AND_CXX_COMMON_FLAGS_BASE="-mcpu=cortex-m4 -mfpu=fpv4-sp-d16
-mfloat-abi=hard --specs=nosys.specs\
C_AND_CXX_COMMON_FLAGS_MORE="-mthumb -mabi=aapcs"

cmake \
    -DLLVM_ENABLE_PROJECTS='libcxxabi;libcxx' \
    -DCMAKE_INSTALL_PREFIX='${HOME}/ClangLibcxx' \
    -DCMAKE_BUILD_TYPE='Release' \

Firstly, I encounter the known problem with __atomic_load_8.
arm-cortex-m{3,4} most probably doesn't support 64bit atomic read/write,
but as long as I don't use it, changing the line in CheckAtomic.cmake:

      message(FATAL_ERROR "Host compiler appears to require libatomic, but
cannot find it.")


      message(WARNING "Host compiler appears to require libatomic, but
cannot find it.")

could push the things further.
But then I encounter that error:

    -- Targeting ARM
    CMake Error at
/home/kacper/Workspace/LLVMProject/libcxxabi/CMakeLists.txt:216 (message):
        LIBCXXABI_BUILD_32_BITS=ON is not supported on this platform.

which is confusing.

Can't the libc++abi be compiled for 32B ARM targets?

Best regards,
Kacper Kowalski
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20191113/50e98d61/attachment.html>

More information about the llvm-dev mailing list