From 7643092769efdef7a868068900ea7bf60bef3414 Mon Sep 17 00:00:00 2001 From: David Spickett Date: Fri, 12 Sep 2025 11:36:22 +0000 Subject: [PATCH] [libcxx][CI] Prepare ARM Picolib builds for upgrade to clang 21 Some time between Clang 19 and Clang 21, changes were made to the bare metal toolchain driver, and on top of that we (Linaro) updated our host OS to Ubuntu Jammy. This has caused the tests to not build with clang-21. 1. The host version of ld (2.38) not being able to parse certain DWARFv5 constructs. Normally I would switch to lld instead. However when I did this, I found that Picolib's ARM linker script uses ALIGN_WITH_INPUT, which lld does not support. So instead I'm sticking with ld and falling back to DWARFv4. Until such time as we upgrade the host to Ubuntu Noble. (if you're wondering how we can use ld in the first place, given the host is AArch64, the AArch64 ld is also capable of linking ARM 32-bit binaries) 2. Many missing symbol errors. This is solved in two parts: * Adding libunwind to the testing linker flags. * Putting the libraries in a group so that the ordering does not matter. And finally for exception_guard.odr.sh.cpp, I have moved the object files to before the linker flags. ld is sensitive to the order of objects on the command line, and this should not break other configurations. I've tested these with 19.1.7 too so my plan is to land these changes first, then proceed with upgrading to 21.x. --- libcxx/cmake/caches/Armv7M-picolibc.cmake | 4 ++-- libcxx/test/configs/armv7m-picolibc-libc++.cfg.in | 6 +++--- libcxx/test/libcxx/utilities/exception_guard.odr.sh.cpp | 2 +- libcxx/utils/ci/build-picolibc.sh | 2 +- libcxxabi/test/configs/armv7m-picolibc-libc++abi.cfg.in | 6 +++--- libunwind/test/configs/armv7m-picolibc-libunwind.cfg.in | 6 +++--- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/libcxx/cmake/caches/Armv7M-picolibc.cmake b/libcxx/cmake/caches/Armv7M-picolibc.cmake index 0f8189b457285..7ad2bb6db9856 100644 --- a/libcxx/cmake/caches/Armv7M-picolibc.cmake +++ b/libcxx/cmake/caches/Armv7M-picolibc.cmake @@ -1,8 +1,8 @@ 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_CXX_FLAGS "-mfloat-abi=soft -gdwarf-4" CACHE STRING "") set(CMAKE_C_COMPILER_TARGET "armv7m-none-eabi" CACHE STRING "") -set(CMAKE_C_FLAGS "-mfloat-abi=soft" CACHE STRING "") +set(CMAKE_C_FLAGS "-mfloat-abi=soft -gdwarf-4" 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 "") diff --git a/libcxx/test/configs/armv7m-picolibc-libc++.cfg.in b/libcxx/test/configs/armv7m-picolibc-libc++.cfg.in index 9bff5021494ef..c1a1a99972a22 100644 --- a/libcxx/test/configs/armv7m-picolibc-libc++.cfg.in +++ b/libcxx/test/configs/armv7m-picolibc-libc++.cfg.in @@ -5,7 +5,7 @@ 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-dir} -I %{target-include-dir} -I %{libcxx-dir}/test/support' + '-nostdinc++ -I %{include-dir} -I %{target-include-dir} -I %{libcxx-dir}/test/support -gdwarf-4' # Disable warnings in the implementation: # "large atomic operation may incur significant performance penalty; the @@ -13,8 +13,8 @@ config.substitutions.append(('%{compile_flags}', ' -Wno-atomic-alignment' )) config.substitutions.append(('%{link_flags}', - '-nostdlib -nostdlib++ -L %{lib-dir} -lc++ -lc++abi' - ' -lc -lm -lclang_rt.builtins -lsemihost -lcrt0-semihost' + + '-nostdlib -nostdlib++ -L %{lib-dir} -Wl,--start-group -lc++ -lc++abi' + ' -lunwind -lc -lm -lclang_rt.builtins -lsemihost -lcrt0-semihost -Wl,--end-group' + ' -T {}'.format(libc_linker_script) + ' -Wl,--defsym=__flash=0x0' ' -Wl,--defsym=__flash_size=0x400000' diff --git a/libcxx/test/libcxx/utilities/exception_guard.odr.sh.cpp b/libcxx/test/libcxx/utilities/exception_guard.odr.sh.cpp index f6b8a29d36821..a1a4ad84e61d9 100644 --- a/libcxx/test/libcxx/utilities/exception_guard.odr.sh.cpp +++ b/libcxx/test/libcxx/utilities/exception_guard.odr.sh.cpp @@ -14,7 +14,7 @@ // RUN: %{cxx} %s %{flags} %{compile_flags} -c -o %t.except.o -O1 -fexceptions // RUN: %{cxx} %s %{flags} %{compile_flags} -c -o %t.noexcept.o -O1 -fno-exceptions -// RUN: %{cxx} %{flags} %{link_flags} -o %t.exe %t.except.o %t.noexcept.o +// RUN: %{cxx} %{flags} -o %t.exe %t.except.o %t.noexcept.o %{link_flags} // RUN: %{run} #include <__utility/exception_guard.h> diff --git a/libcxx/utils/ci/build-picolibc.sh b/libcxx/utils/ci/build-picolibc.sh index 521c1bef9fc7e..f480368dacbf1 100755 --- a/libcxx/utils/ci/build-picolibc.sh +++ b/libcxx/utils/ci/build-picolibc.sh @@ -78,7 +78,7 @@ rm -rf "${picolibc_source_dir}/picolibc-${picolibc_commit}" cat < "${picolibc_build_dir}/meson-cross-build.txt" [binaries] -c = ['${CC:-cc}', '--target=${target}', '-mfloat-abi=soft', '-nostdlib'] +c = ['${CC:-cc}', '--target=${target}', '-mfloat-abi=soft', '-nostdlib', '-gdwarf-4'] ar = 'llvm-ar' as = 'llvm-as' ld = 'lld' diff --git a/libcxxabi/test/configs/armv7m-picolibc-libc++abi.cfg.in b/libcxxabi/test/configs/armv7m-picolibc-libc++abi.cfg.in index b4744f935ad85..12e15fbfc6efe 100644 --- a/libcxxabi/test/configs/armv7m-picolibc-libc++abi.cfg.in +++ b/libcxxabi/test/configs/armv7m-picolibc-libc++abi.cfg.in @@ -5,11 +5,11 @@ 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 %{cxx-include} -I %{cxx-target-include} %{maybe-include-libunwind} -I %{libcxx}/test/support -I %{libcxx}/src -D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS' + '-nostdinc++ -I %{include} -I %{cxx-include} -I %{cxx-target-include} %{maybe-include-libunwind} -I %{libcxx}/test/support -I %{libcxx}/src -D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS -gdwarf-4' )) config.substitutions.append(('%{link_flags}', - '-nostdlib -nostdlib++ -L %{lib} -lc++ -lc++abi' - ' -lc -lm -lclang_rt.builtins -lsemihost -lcrt0-semihost' + + '-nostdlib -nostdlib++ -L %{lib} -Wl,--start-group -lc++ -lc++abi' + ' -lunwind -lc -lm -lclang_rt.builtins -lsemihost -lcrt0-semihost -Wl,--end-group' + ' -T {}'.format(libc_linker_script) + ' -Wl,--defsym=__flash=0x0' ' -Wl,--defsym=__flash_size=0x400000' diff --git a/libunwind/test/configs/armv7m-picolibc-libunwind.cfg.in b/libunwind/test/configs/armv7m-picolibc-libunwind.cfg.in index e8f68a51fc53f..494fb13945f56 100644 --- a/libunwind/test/configs/armv7m-picolibc-libunwind.cfg.in +++ b/libunwind/test/configs/armv7m-picolibc-libunwind.cfg.in @@ -5,11 +5,11 @@ 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}' + '-nostdinc++ -I %{include} -gdwarf-4' )) config.substitutions.append(('%{link_flags}', - '-nostdlib -nostdlib++ -L %{lib} -lunwind' - ' -lc -lm -lclang_rt.builtins -lsemihost -lcrt0-semihost' + + '-nostdlib -nostdlib++ -L %{lib} -Wl,--start-group -lunwind' + ' -lc -lm -lclang_rt.builtins -lsemihost -lcrt0-semihost -Wl,--end-group' + ' -T {}'.format(libc_linker_script) + ' -Wl,--defsym=__flash=0x0' ' -Wl,--defsym=__flash_size=0x400000'