From 997f0edb4f237bb231ffac7bac00b51dde50ea8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Desbiens?= Date: Wed, 27 May 2026 11:59:06 -0400 Subject: [PATCH] fix(core_v_mcu): remove clz.c workaround; use riscv32-unknown-elf toolchain bsp/clz.c provided a weak __clzsi2 fallback to work around the missing rv32 multilib in the riscv-collab riscv64-unknown-elf toolchain. Since cmake/riscv32-unknown-elf-rv32imc.cmake now uses the dedicated riscv32- unknown-elf-gcc toolchain (riscv-collab riscv32-elf release), which ships a native rv32/ilp32 libgcc with all required helpers, the workaround is no longer needed. Remove bsp/clz.c and its entry in CMakeLists.txt. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../example_build/core_v_mcu/CMakeLists.txt | 1 - .../gnu/example_build/core_v_mcu/bsp/clz.c | 29 ------------------- 2 files changed, 30 deletions(-) delete mode 100644 ports/risc-v32/gnu/example_build/core_v_mcu/bsp/clz.c diff --git a/ports/risc-v32/gnu/example_build/core_v_mcu/CMakeLists.txt b/ports/risc-v32/gnu/example_build/core_v_mcu/CMakeLists.txt index 6946b3474..662914d1a 100644 --- a/ports/risc-v32/gnu/example_build/core_v_mcu/CMakeLists.txt +++ b/ports/risc-v32/gnu/example_build/core_v_mcu/CMakeLists.txt @@ -21,7 +21,6 @@ set(SRCS ${CORE_V_MCU_DIR}/crt0.S ${CORE_V_MCU_DIR}/vectors.S ${CORE_V_MCU_DIR}/tx_initialize_low_level.S - ${CORE_V_MCU_DIR}/bsp/clz.c ${CORE_V_MCU_DIR}/bsp/irq.c ${CORE_V_MCU_DIR}/bsp/timer_irq.c ${CORE_V_MCU_DIR}/bsp/fll.c diff --git a/ports/risc-v32/gnu/example_build/core_v_mcu/bsp/clz.c b/ports/risc-v32/gnu/example_build/core_v_mcu/bsp/clz.c deleted file mode 100644 index ef3cb23ba..000000000 --- a/ports/risc-v32/gnu/example_build/core_v_mcu/bsp/clz.c +++ /dev/null @@ -1,29 +0,0 @@ -/* clz.c — portable fallback for __clzsi2 (count leading zeros, 32-bit) - * - * The riscv-collab bare-metal toolchain (riscv64-unknown-elf from /opt/riscv) - * is built without multilib and does not ship an rv32/ilp32 libgcc. As a - * result __clzsi2, which GCC emits for __builtin_clz() on targets without a - * hardware CLZ instruction, is missing at link time. - * - * This file provides a weak definition so that the build is self-contained - * with any RISC-V bare-metal toolchain. When a toolchain does ship the symbol - * in libgcc (e.g. the Ubuntu gcc-riscv64-unknown-elf package), the libgcc copy - * will take precedence over this weak one. - */ - -#include - -__attribute__((weak)) -int __clzsi2(uint32_t x) -{ - if (x == 0U) - return 32; - - int n = 0; - if ((x & 0xFFFF0000U) == 0U) { n += 16; x <<= 16; } - if ((x & 0xFF000000U) == 0U) { n += 8; x <<= 8; } - if ((x & 0xF0000000U) == 0U) { n += 4; x <<= 4; } - if ((x & 0xC0000000U) == 0U) { n += 2; x <<= 2; } - if ((x & 0x80000000U) == 0U) { n += 1; } - return n; -}