<div dir="ltr"><div>Hello,</div><div><br></div><div>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:</div><div><br></div><div>  ...<br></div><div>  // For construction of filebuffers for cout, cin, cerr, clog et. al.<br>  static ios_base::Init __ioinit;</div><div>  ...</div><div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>To resolve this issue I found out that libc++ can be compiled with the flags:</div><div><br>    -D_LIBCPP_HAS_NO_STDOUT:BOOL=ON<br>    -D_LIBCPP_HAS_NO_STDIN:BOOL=ON</div><div><br></div><div>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.</div><div><br></div><div>This is how I build libc++:</div><div><br></div><div>TOOLCHAIN_ROOT_DIR="${HOME}/ARMToolchain-9-2019-q4-major"<br><br>export CC="${TOOLCHAIN_ROOT_DIR}/bin/arm-none-eabi-gcc"<br>export CXX="${TOOLCHAIN_ROOT_DIR}/bin/arm-none-eabi-g++"<br><br>C_AND_CXX_COMMON_FLAGS_BASE="-mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard --specs=nosys.specs\<br>    --sysroot=${TOOLCHAIN_ROOT_DIR} -I${TOOLCHAIN_ROOT_DIR}/arm-none-eabi/include\<br>    -L${TOOLCHAIN_ROOT_DIR}/lib -L${TOOLCHAIN_ROOT_DIR}/lib/gcc/arm-none-eabi/9.2.1"<br>C_AND_CXX_COMMON_FLAGS_MORE="-mthumb -mabi=aapcs"<br>C_AND_CXX_COMMON_FLAGS="$C_AND_CXX_COMMON_FLAGS_BASE $C_AND_CXX_COMMON_FLAGS_MORE"<br><br>cmake \<br>    -DCMAKE_CROSS_COMPILING:BOOL=ON \<br>    -DLLVM_ENABLE_PROJECTS='libcxxabi;libcxx' \<br>    -DCMAKE_INSTALL_PREFIX='${HOME}/ClangLibcxx' \<br>    -DCMAKE_BUILD_TYPE='Release' \<br>    -DLLVM_ENABLE_ASSERTIONS:BOOL=ON \<br>    -DLLVM_TARGET_ARCH='ARM' \<br>    -DLLVM_TARGETS_TO_BUILD='ARM' \<br>    -DLIBCXX_BUILD_32_BITS:BOOL=ON \<br>    -DLLVM_BUILD_32_BITS:BOOL=ON \<br>    -DLLVM_ENABLE_STATIC:BOOL=ON \<br>    -DLLVM_ENABLE_SHARED:BOOL=OFF \<br>    -DLLVM_DISABLE_PIC:BOOL=OFF \<br>    -D_LIBCPP_HAS_NO_STDOUT:BOOL=ON \<br>    -D_LIBCPP_HAS_NO_STDIN:BOOL=ON \<br>    -DCMAKE_C_FLAGS="$C_AND_CXX_COMMON_FLAGS" \<br>    -DCMAKE_CXX_FLAGS="$C_AND_CXX_COMMON_FLAGS" \<br>    ../llvm</div><div><br></div><div>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:</div><div><br>      message(FATAL_ERROR "Host compiler appears to require libatomic, but cannot find it.")</div><div><br></div><div>to:</div><div><br></div><div><div>      message(WARNING "Host compiler appears to require libatomic, but cannot find it.")</div><div><br></div><div>could push the things further.</div><div>But then I encounter that error:</div><div><br></div><div>    -- Targeting ARM<br>    CMake Error at /home/kacper/Workspace/LLVMProject/libcxxabi/CMakeLists.txt:216 (message):<br>        LIBCXXABI_BUILD_32_BITS=ON is not supported on this platform.</div><div><br></div><div>which is confusing.</div><div><br></div><div>Can't the libc++abi be compiled for 32B ARM targets?</div><div><br></div><div>Best regards,</div><div>Kacper Kowalski<br></div></div></div>