From fcc31d02570524ab813d6b7116418cddd68f0095 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Desbiens?= Date: Tue, 11 Aug 2026 19:46:16 -0400 Subject: [PATCH] Brought the Cortex-R52 examples under the LLVM check, and fixed two blockers #600 added a line reporting which example builds the LLVM check passes over, and cortex_r52 was on it: its examples are driven by CMake rather than by a build_threadx.sh pair, so the linking stage never touched them. Covering them turned up two reasons they could not have been built with anything but GNU. .arch armv8-r has no portable spelling. GNU as accepts it, and LLVM's integrated assembler rejects every variant -- armv8-r, armv8r, armv8-r+crc -- with "Unknown Arch: armv8-r". There is nothing to substitute, so the directive is gone from entry.S and tx_initialize_low_level.S; -mcpu=cortex-r52 already selects the architecture, both toolchain files pass it, and the directive only restated it. Worth noting where this hid: the assembly stage walks ports/*/gnu/src, so example assembly had never been assembled by LLVM at all. -Wl,--no-warn-rwx-segments is GNU ld only, added in binutils 2.39. ld.lld does not warn about RWX segments and rejects the flag outright, failing the link with "unknown argument". It is now selected on CMAKE_C_COMPILER_ID rather than spelled into all six targets, and the reason it exists at all -- a bare-metal image has one flat DRAM region and leaves access control to the MPU -- moves to the one place that sets it. cmake/cortex_r52_clang.cmake is the toolchain file. It names the tools as found on PATH, which is what CI uses, then pins $HOME/toolchains if that directory exists, mirroring how cortex_r52.cmake pins the GNU toolchain and for the same reason. Falling back rather than requiring the pinned path keeps the file usable on a machine that keeps clang elsewhere. THREADX_TOOLCHAIN stays "gnu": there is no clang port directory, this builds the gnu sources with a different compiler, which is what the whole check does for every other Arm port. check_clang.sh gains a fourth stage for CMake-driven examples, and no longer reports cortex_r52 as a gap. It reads the image list out of the generated ninja graph rather than repeating it, so adding a target cannot escape the check, and filters out the cmake_object_order_depends_target_* phonies -- counting those reported ten images where there are five. Verified with Arm Toolchain for Embedded 22.1.0, the version the workflow pins. All five images link, and all five then run and pass on FVP_BaseR_AEMv8R: boot_check, demo_m2, demo_m3, demo_threadx and demo_mpu. That is a step beyond the AArch64 examples, which are link-verified only. The full check reports 711 of 711 assembly sources, 185 of 185 common C sources for each of nine cores, 42 of 42 script-driven examples and 5 of 5 CMake images, leaving only cortex_a5_smp, cortex_a7_smp and cortex_a9_smp listed as having no driver. GNU is unaffected: the same five images build with no warnings and the FVP test suite passes 5 of 5. Assisted-by: Claude Code (Opus 5) --- cmake/cortex_r52_clang.cmake | 84 +++++++++++++++++++ .../fvp_baser_aemv8r/CMakeLists.txt | 26 ++++-- .../example_build/fvp_baser_aemv8r/entry.S | 7 +- .../tx_initialize_low_level.S | 7 +- scripts/check_clang.sh | 80 ++++++++++++++++-- 5 files changed, 189 insertions(+), 15 deletions(-) create mode 100644 cmake/cortex_r52_clang.cmake diff --git a/cmake/cortex_r52_clang.cmake b/cmake/cortex_r52_clang.cmake new file mode 100644 index 000000000..2105ecbe2 --- /dev/null +++ b/cmake/cortex_r52_clang.cmake @@ -0,0 +1,84 @@ +# Copyright (c) 2026 Eclipse ThreadX contributors +# SPDX-License-Identifier: MIT +# Some portions generated by Claude Code (Opus 5). +# +# Toolchain file for Arm Cortex-R52 (Armv8-R, AArch32) using Arm Toolchain for +# Embedded, which is LLVM based and is the successor to Arm Compiler 6. +# +# There is no separate clang port directory: this builds the gnu port sources +# with a different compiler, which is the same thing scripts/check_clang.sh does +# for every other Arm port. THREADX_TOOLCHAIN stays "gnu" for that reason. +# +# cmake -S . -B build -G Ninja \ +# -DCMAKE_TOOLCHAIN_FILE=cmake/cortex_r52_clang.cmake \ +# -DTX_R52_BUILD_FVP_EXAMPLE=ON + +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_SYSTEM_PROCESSOR cortex-r52) + +set(THREADX_ARCH "cortex_r52") +set(THREADX_TOOLCHAIN "gnu") + +# Tool names as found on PATH, which is what CI uses: the workflow unpacks the +# toolchain into the workspace and scripts/check_clang.sh passes its location +# through as ATFE_TOOLCHAIN_PATH. +set(CMAKE_C_COMPILER clang) +set(CMAKE_CXX_COMPILER clang++) +set(CMAKE_ASM_COMPILER clang) +set(CMAKE_AR llvm-ar) +set(CMAKE_RANLIB llvm-ranlib) +set(OBJCOPY llvm-objcopy) +set(OBJDUMP llvm-objdump) +set(SIZE llvm-size) + +# Then pin a specific install if one is present, the way cortex_r52.cmake pins +# the GNU toolchain and for the same reason: a local build should not depend on +# PATH ordering. Absent that directory this falls back to the names above rather +# than failing, so the file works on a machine that keeps clang elsewhere. +# Override with -DATFE_TOOLCHAIN_PATH=. +if(NOT DEFINED ATFE_TOOLCHAIN_PATH) + set(ATFE_TOOLCHAIN_PATH "$ENV{HOME}/toolchains/ATfE-22.1.0-Linux-x86_64/bin") +endif() +if(EXISTS "${ATFE_TOOLCHAIN_PATH}/clang") + set(CMAKE_C_COMPILER "${ATFE_TOOLCHAIN_PATH}/clang") + set(CMAKE_CXX_COMPILER "${ATFE_TOOLCHAIN_PATH}/clang++") + set(CMAKE_ASM_COMPILER "${ATFE_TOOLCHAIN_PATH}/clang") + set(CMAKE_AR "${ATFE_TOOLCHAIN_PATH}/llvm-ar") + set(CMAKE_RANLIB "${ATFE_TOOLCHAIN_PATH}/llvm-ranlib") + set(OBJCOPY "${ATFE_TOOLCHAIN_PATH}/llvm-objcopy") + set(OBJDUMP "${ATFE_TOOLCHAIN_PATH}/llvm-objdump") + set(SIZE "${ATFE_TOOLCHAIN_PATH}/llvm-size") +endif() + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) + +# Link the try-compile as a static library, so probing the compiler does not +# need a linker script or a target C library. +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + +if(NOT DEFINED TX_R52_FLOAT_ABI) + set(TX_R52_FLOAT_ABI "soft" CACHE STRING "R52 float ABI: soft | hard") +endif() + +set(MCPU_FLAGS "--target=arm-none-eabi -marm -mcpu=cortex-r52") +if(TX_R52_FLOAT_ABI STREQUAL "hard") + set(VFP_FLAGS "-mfpu=fpv5-d16 -mfloat-abi=hard") +else() + set(VFP_FLAGS "-mfloat-abi=soft") +endif() + +set(CMAKE_C_FLAGS "${MCPU_FLAGS} ${VFP_FLAGS} -fdata-sections -ffunction-sections -mlong-calls" CACHE INTERNAL "c compiler flags") +set(CMAKE_CXX_FLAGS "${MCPU_FLAGS} ${VFP_FLAGS} -fdata-sections -ffunction-sections -fno-rtti -fno-exceptions -mlong-calls" CACHE INTERNAL "cxx compiler flags") +set(CMAKE_ASM_FLAGS "${MCPU_FLAGS} ${VFP_FLAGS} -x assembler-with-cpp" CACHE INTERNAL "asm compiler flags") +set(CMAKE_EXE_LINKER_FLAGS "${MCPU_FLAGS} ${VFP_FLAGS} -fuse-ld=lld -Wl,--gc-sections" CACHE INTERNAL "exe link flags") + +set(CMAKE_C_FLAGS_DEBUG "-Og -g" CACHE INTERNAL "c debug compiler flags") +set(CMAKE_CXX_FLAGS_DEBUG "-Og -g" CACHE INTERNAL "cxx debug compiler flags") +set(CMAKE_ASM_FLAGS_DEBUG "-g" CACHE INTERNAL "asm debug compiler flags") + +set(CMAKE_C_FLAGS_RELEASE "-O3" CACHE INTERNAL "c release compiler flags") +set(CMAKE_CXX_FLAGS_RELEASE "-O3" CACHE INTERNAL "cxx release compiler flags") +set(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "asm release compiler flags") diff --git a/ports/cortex_r52/gnu/example_build/fvp_baser_aemv8r/CMakeLists.txt b/ports/cortex_r52/gnu/example_build/fvp_baser_aemv8r/CMakeLists.txt index dc451bd39..c0824b264 100644 --- a/ports/cortex_r52/gnu/example_build/fvp_baser_aemv8r/CMakeLists.txt +++ b/ports/cortex_r52/gnu/example_build/fvp_baser_aemv8r/CMakeLists.txt @@ -6,6 +6,18 @@ set(FVP_DIR ${CMAKE_CURRENT_LIST_DIR}) +# A bare-metal image has one flat DRAM region and no OS page permissions; access +# control belongs to the MPU, so an RWX segment is expected here rather than a +# mistake. GNU ld has warned about them since binutils 2.39 and takes this flag +# to stay quiet. ld.lld does not warn and rejects the flag outright, failing the +# link with "unknown argument", so the suppression is chosen by toolchain +# instead of being spelled into every target. +if(CMAKE_C_COMPILER_ID STREQUAL "GNU") + set(R52_LINK_QUIET_RWX -Wl,--no-warn-rwx-segments) +else() + set(R52_LINK_QUIET_RWX) +endif() + # Console sources. Both backends are always compiled; console.c selects one at # compile time and --gc-sections drops the unused one, which keeps every image # building in either configuration without per-target source juggling. @@ -30,9 +42,7 @@ target_link_options(boot_check.elf PRIVATE -T${FVP_DIR}/link.lds -nostartfiles -Wl,-Map=boot_check.map - # A bare-metal image has one flat DRAM region and no OS page permissions; - # access control belongs to the MPU, so the RWX-segment note is expected. - -Wl,--no-warn-rwx-segments + ${R52_LINK_QUIET_RWX} ) # AR1/M2 -- cooperative two-thread demo. Links ThreadX and exercises the @@ -56,7 +66,7 @@ target_link_options(demo_m2.elf PRIVATE -T${FVP_DIR}/link.lds -nostartfiles -Wl,-Map=demo_m2.map - -Wl,--no-warn-rwx-segments + ${R52_LINK_QUIET_RWX} ) # AR1/M3 -- periodic tick and preemptive scheduling. Adds GICv3, the generic @@ -87,7 +97,7 @@ target_link_options(demo_m3.elf PRIVATE -T${FVP_DIR}/link.lds -nostartfiles -Wl,-Map=demo_m3.map - -Wl,--no-warn-rwx-segments + ${R52_LINK_QUIET_RWX} ) # AR1/M4 -- the standard eight-thread ThreadX demo. demo_threadx.c is the @@ -118,7 +128,7 @@ target_link_options(demo_threadx.elf PRIVATE -T${FVP_DIR}/link.lds -nostartfiles -Wl,-Map=demo_threadx.map - -Wl,--no-warn-rwx-segments + ${R52_LINK_QUIET_RWX} ) # AR1/M5 -- lazy VFP context save and restore. Only meaningful when the @@ -149,7 +159,7 @@ if(TX_R52_ENABLE_VFP) -T${FVP_DIR}/link.lds -nostartfiles -Wl,-Map=demo_m5.map - -Wl,--no-warn-rwx-segments + ${R52_LINK_QUIET_RWX} ) endif() @@ -184,7 +194,7 @@ target_link_options(demo_mpu.elf PRIVATE -T${FVP_DIR}/link.lds -nostartfiles -Wl,-Map=demo_mpu.map - -Wl,--no-warn-rwx-segments + ${R52_LINK_QUIET_RWX} ) # Every image built here, in the order they should be exercised. diff --git a/ports/cortex_r52/gnu/example_build/fvp_baser_aemv8r/entry.S b/ports/cortex_r52/gnu/example_build/fvp_baser_aemv8r/entry.S index 0b89ee82c..01f171dcc 100644 --- a/ports/cortex_r52/gnu/example_build/fvp_baser_aemv8r/entry.S +++ b/ports/cortex_r52/gnu/example_build/fvp_baser_aemv8r/entry.S @@ -41,7 +41,12 @@ #include "platform.h" - .arch armv8-r + /* No .arch directive here. GNU as accepts "armv8-r", LLVM's integrated + assembler accepts no spelling of it at all -- not armv8-r, not armv8r -- + and fails with "Unknown Arch". The architecture is already selected by + -mcpu=cortex-r52 on the command line, which both toolchains require and + both toolchain files pass, so the directive only restated it. */ + .syntax unified .arm diff --git a/ports/cortex_r52/gnu/example_build/fvp_baser_aemv8r/tx_initialize_low_level.S b/ports/cortex_r52/gnu/example_build/fvp_baser_aemv8r/tx_initialize_low_level.S index cb473a43e..c8d3f1883 100644 --- a/ports/cortex_r52/gnu/example_build/fvp_baser_aemv8r/tx_initialize_low_level.S +++ b/ports/cortex_r52/gnu/example_build/fvp_baser_aemv8r/tx_initialize_low_level.S @@ -23,7 +23,12 @@ /**************************************************************************/ /**************************************************************************/ - .arch armv8-r + /* No .arch directive here. GNU as accepts "armv8-r", LLVM's integrated + assembler accepts no spelling of it at all -- not armv8-r, not armv8r -- + and fails with "Unknown Arch". The architecture is already selected by + -mcpu=cortex-r52 on the command line, which both toolchains require and + both toolchain files pass, so the directive only restated it. */ + .syntax unified .arm diff --git a/scripts/check_clang.sh b/scripts/check_clang.sh index c32d15892..c0cae4014 100755 --- a/scripts/check_clang.sh +++ b/scripts/check_clang.sh @@ -14,10 +14,11 @@ # SPDX-License-Identifier: MIT and CC0-1.0 ############################################################################## -# Builds the Arm ports with an LLVM based toolchain, in three stages: assemble +# Builds the Arm ports with an LLVM based toolchain, in four stages: assemble # every assembly source of every Arm gnu port, compile the common C sources for -# one core per architecture profile, then link the example builds that have a -# script driver. Only that last stage needs a target C library. +# one core per architecture profile, link the example builds that have a script +# driver, then link those driven by CMake. Only the two linking stages need a +# target C library. # # scripts/check_clang.sh # clang from PATH # scripts/check_clang.sh --clang /path/to/clang @@ -149,6 +150,11 @@ declare -A PORT_TARGET=( # accordingly, so cortex_r5 does not stand in for it. C_CORES="cortex_m0 cortex_m4 cortex_m23 cortex_m33 cortex_m55 cortex_a7 cortex_a53 cortex_r5 cortex_r52" +# Example builds driven by CMake rather than by a build_threadx.sh pair. These +# are covered by their own stage below, so the script-driven loop passes over +# them without reporting them as a gap. +CMAKE_EXAMPLE_CORES="cortex_r52" + # Example builds that are not expected to link, with the reason. Named by # their port directory, which covers both ports/ and ports_smp/. Listed # explicitly rather than silently skipped, so the gaps stay visible. @@ -249,10 +255,14 @@ if [ "$no_examples" -eq 0 ]; then # linux or mips32 as a gap here would be noise, not information. [ -n "${PORT_TARGET[$core]:-}" ] || continue + # Covered by the CMake stage below rather than here. + case " $CMAKE_EXAMPLE_CORES " in + *" $core "*) continue ;; + esac + # A driverless example is not covered by this stage, so say so rather # than dropping out in silence. A port that is simply absent from the - # count reads as covered: the CMake based example builds under - # ports/cortex_r52 looked like part of the 35 while never being built. + # count reads as covered. if [ ! -f "$dir/build_threadx.sh" ]; then example_nodriver="$example_nodriver $core" continue @@ -289,6 +299,66 @@ if [ "$no_examples" -eq 0 ]; then say " no script driver, so outside this stage:$example_nodriver" fi fi +# -------------------------------------------------------------------------- +# The Cortex-R52 examples are built by CMake, so they need a toolchain file +# rather than TOOLCHAIN=atfe. Same compiler, same linker, same purpose as the +# stage above: confirm the images still link when the toolchain is not GNU. +if [ "$no_examples" -eq 0 ]; then + say "" + say "== CMake example builds, linked with lld ==" + + if ! command -v cmake >/dev/null 2>&1 || ! command -v ninja >/dev/null 2>&1; then + say " skipped: cmake and ninja are both required" + else + for core in $CMAKE_EXAMPLE_CORES; do + build_dir="$(mktemp -d)" + # ATFE_TOOLCHAIN_PATH follows --clang, so the stage uses the same + # compiler as every other stage rather than whatever is on PATH. + if cmake -S . -B "$build_dir" -G Ninja \ + -DCMAKE_TOOLCHAIN_FILE="cmake/${core}_clang.cmake" \ + -DATFE_TOOLCHAIN_PATH="$(cd "$(dirname "$CC")" && pwd)" \ + -DTX_R52_BUILD_FVP_EXAMPLE=ON \ + -DTX_R52_ENABLE_MPU=ON >"$build_dir/configure.log" 2>&1; then + # Read the image list from the generated graph instead of + # repeating it here, so adding a target cannot silently escape + # this check. The images are EXCLUDE_FROM_ALL, so "ninja" alone + # would build none of them. + # + # The cmake_object_order_depends_target_* entries are CMake's + # own ordering phonies, one per real image and named after it. + # Counting those doubled the total and reported ten images built + # where there are five. + images="$(ninja -C "$build_dir" -t targets all 2>/dev/null \ + | grep -oE '^[A-Za-z0-9_]+\.elf' \ + | grep -v '^cmake_' | sort -u)" + if [ -z "$images" ]; then + fail "$core: no .elf targets found in the CMake graph" + failures=$((failures + 1)) + else + built=0; total=0 + for image in $images; do + total=$((total + 1)) + if ninja -C "$build_dir" "$image" \ + >"$build_dir/$image.log" 2>&1; then + built=$((built + 1)) + else + fail "$core: $image did not build" + tail -6 "$build_dir/$image.log" | sed 's/^/ /' + failures=$((failures + 1)) + fi + done + say " $core: $built of $total images linked" + fi + else + fail "$core: CMake configure failed" + tail -6 "$build_dir/configure.log" | sed 's/^/ /' + failures=$((failures + 1)) + fi + rm -rf "$build_dir" + done + fi +fi + # -------------------------------------------------------------------------- say "" if [ "$failures" -eq 0 ]; then