From 28aabfa10edfe7dc970b297c89e30303c1ea5b68 Mon Sep 17 00:00:00 2001 From: Hardy Griech Date: Wed, 15 Oct 2025 13:01:31 +0200 Subject: [PATCH 01/10] enhanced sysroot handling, sysroot did not took selected clib into account --- .../util/pico_arm_clang_common.cmake | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/cmake/preload/toolchains/util/pico_arm_clang_common.cmake b/cmake/preload/toolchains/util/pico_arm_clang_common.cmake index 5cb4e2df5..88c4e505d 100644 --- a/cmake/preload/toolchains/util/pico_arm_clang_common.cmake +++ b/cmake/preload/toolchains/util/pico_arm_clang_common.cmake @@ -43,12 +43,31 @@ endforeach() list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES PICO_CLIB) +set(_PICO_CLIB_PATH "${PICO_COMPILER_DIR}/../lib/clang-runtimes/arm-none-eabi") +if(PICO_CLIB STREQUAL "") + # use default from above +elseif(PICO_CLIB STREQUAL "llvm_libc") + if(EXISTS "${PICO_COMPILER_DIR}/../lib/clang-runtimes/llvmlibc/arm-none-eabi") + set(_PICO_CLIB_PATH "${PICO_COMPILER_DIR}/../lib/clang-runtimes/llvmlibc/arm-none-eabi") + endif() +elseif(PICO_CLIB STREQUAL "picolibc") + if(EXISTS "${PICO_COMPILER_DIR}/../lib/clang-runtimes/picolibc/arm-none-eabi") + set(_PICO_CLIB_PATH "${PICO_COMPILER_DIR}/../lib/clang-runtimes/picolibc/arm-none-eabi") + endif() +elseif(PICO_CLIB STREQUAL "newlib") + if(EXISTS "${PICO_COMPILER_DIR}/../lib/clang-runtimes/newlib/arm-none-eabi") + set(_PICO_CLIB_PATH "${PICO_COMPILER_DIR}/../lib/clang-runtimes/newlib/arm-none-eabi") + endif() +else() + message(FATAL_ERROR "PICO_CLIB must be one of newlib, picolib, llvm_libc or empty (but is '${PICO_CLIB}')") +endif() + foreach(PICO_CLANG_RUNTIME IN LISTS PICO_CLANG_RUNTIMES) # LLVM embedded-toolchain for ARM style - find_path(PICO_COMPILER_SYSROOT NAMES include/stdio.h + find_path(PICO_COMPILER_SYSROOT NAMES lib/libc.a HINTS - ${PICO_COMPILER_DIR}/../lib/clang-runtimes/arm-none-eabi/${PICO_CLANG_RUNTIME} - ${PICO_COMPILER_DIR}/../lib/clang-runtimes/${PICO_CLANG_RUNTIME} + ${_PICO_CLIB_PATH}/${PICO_CLANG_RUNTIME} + ${PICO_COMPILER_DIR}/../lib/clang-runtimes/${PICO_CLANG_RUNTIME} ) if (PICO_COMPILER_SYSROOT) @@ -66,7 +85,7 @@ foreach(PICO_CLANG_RUNTIME IN LISTS PICO_CLANG_RUNTIMES) # llvm_libc style find_path(PICO_COMPILER_SYSROOT NAMES stdio.h HINTS - ${PICO_COMPILER_DIR}/../include/${PICO_CLANG_RUNTIME} + ${PICO_COMPILER_DIR}/../include/${PICO_CLANG_RUNTIME} ) if (PICO_COMPILER_SYSROOT) if (NOT PICO_CLIB) @@ -76,6 +95,10 @@ foreach(PICO_CLANG_RUNTIME IN LISTS PICO_CLANG_RUNTIMES) break() endif() endforeach() +if (NOT PICO_COMPILER_SYSROOT) + message(FATAL_ERROR "Could not find an llvm runtime for '${PICO_CLANG_RUNTIME}'") +endif() +set(PICO_COMMON_LANG_FLAGS "${PICO_COMMON_LANG_FLAGS} --sysroot ${PICO_COMPILER_SYSROOT}") # moving this here as a reminder from pico_standard_link; it was commented out theee, but if ever needed, # it belongs here as part of LINKER_FLAGS_INIT @@ -87,11 +110,5 @@ if (PICO_CLIB STREQUAL "llvm_libc") foreach(TYPE IN ITEMS EXE SHARED MODULE) set(CMAKE_${TYPE}_LINKER_FLAGS_INIT "-nostdlib++ -nostartfiles") endforeach() -else() - if (NOT PICO_COMPILER_SYSROOT) - message(FATAL_ERROR "Could not find an llvm runtime for '${PICO_CLANG_RUNTIME}'") - endif() - - set(PICO_COMMON_LANG_FLAGS "${PICO_COMMON_LANG_FLAGS} --sysroot ${PICO_COMPILER_SYSROOT}") endif() include(${CMAKE_CURRENT_LIST_DIR}/set_flags.cmake) From 6feb9b9b01edaa981f0f6c218a5de12261f6cee1 Mon Sep 17 00:00:00 2001 From: Hardy Griech Date: Wed, 15 Oct 2025 17:57:58 +0200 Subject: [PATCH 02/10] make it compile with clang21.1.1: cmake changes for newlib/llvm_libc --- cmake/preload/toolchains/pico_arm_cortex_m33_clang.cmake | 2 +- cmake/preload/toolchains/util/pico_arm_clang_common.cmake | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cmake/preload/toolchains/pico_arm_cortex_m33_clang.cmake b/cmake/preload/toolchains/pico_arm_cortex_m33_clang.cmake index da42da46e..3b2533ee2 100644 --- a/cmake/preload/toolchains/pico_arm_cortex_m33_clang.cmake +++ b/cmake/preload/toolchains/pico_arm_cortex_m33_clang.cmake @@ -1,7 +1,7 @@ set(CMAKE_SYSTEM_PROCESSOR cortex-m33) # these are all the directories under LLVM embedded toolchain for ARM (newlib or pibolibc) and under llvm_libc -set(PICO_CLANG_RUNTIMES armv8m.main_soft_nofp armv8m.main_soft_nofp_unaligned armv8m.main-unknown-none-eabi) +set(PICO_CLANG_RUNTIMES armv8m.main_soft_nofp armv8m.main_soft_nofp_unaligned armv8m.main_soft_nofp_unaligned_size armv8m.main-unknown-none-eabi) set(PICO_COMMON_LANG_FLAGS "-mcpu=cortex-m33 --target=armv8m.main-none-eabi -mfloat-abi=softfp -march=armv8m.main+fp+dsp") set(PICO_DISASM_OBJDUMP_ARGS --mcpu=cortex-m33 --arch=armv8m.main+fp+dsp) diff --git a/cmake/preload/toolchains/util/pico_arm_clang_common.cmake b/cmake/preload/toolchains/util/pico_arm_clang_common.cmake index 88c4e505d..a6d51f4fd 100644 --- a/cmake/preload/toolchains/util/pico_arm_clang_common.cmake +++ b/cmake/preload/toolchains/util/pico_arm_clang_common.cmake @@ -99,6 +99,10 @@ if (NOT PICO_COMPILER_SYSROOT) message(FATAL_ERROR "Could not find an llvm runtime for '${PICO_CLANG_RUNTIME}'") endif() set(PICO_COMMON_LANG_FLAGS "${PICO_COMMON_LANG_FLAGS} --sysroot ${PICO_COMPILER_SYSROOT}") +# llvmlibc / newlib +set(PICO_COMMON_LANG_FLAGS "${PICO_COMMON_LANG_FLAGS} -isystem ${PICO_COMPILER_SYSROOT}/../include/c++/v1") +# llvmlibc / newlib +set(PICO_COMMON_LANG_FLAGS "${PICO_COMMON_LANG_FLAGS} -isystem ${PICO_COMPILER_SYSROOT}/../include") # moving this here as a reminder from pico_standard_link; it was commented out theee, but if ever needed, # it belongs here as part of LINKER_FLAGS_INIT From 571d2eda94743238b424140a1a75685a89785c0b Mon Sep 17 00:00:00 2001 From: Hardy Griech Date: Wed, 15 Oct 2025 17:58:40 +0200 Subject: [PATCH 03/10] make it compile with clang21.1.1: llvm_libc_interface changes --- src/rp2_common/pico_clib_interface/include/llvm_libc/time.h | 4 ++-- src/rp2_common/pico_clib_interface/llvm_libc_interface.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/rp2_common/pico_clib_interface/include/llvm_libc/time.h b/src/rp2_common/pico_clib_interface/include/llvm_libc/time.h index bb37c7eff..df3d11d29 100644 --- a/src/rp2_common/pico_clib_interface/include/llvm_libc/time.h +++ b/src/rp2_common/pico_clib_interface/include/llvm_libc/time.h @@ -9,15 +9,15 @@ #include <__llvm-libc-common.h> +#include #include #include __BEGIN_C_DECLS struct tm* localtime_r(const time_t* timer, struct tm* buf); +time_t mktime(struct tm *); __END_C_DECLS -#include_next - #endif // _PICO_LLVM_LIBC_TIME_H diff --git a/src/rp2_common/pico_clib_interface/llvm_libc_interface.c b/src/rp2_common/pico_clib_interface/llvm_libc_interface.c index dfcab015e..c852bcb2e 100644 --- a/src/rp2_common/pico_clib_interface/llvm_libc_interface.c +++ b/src/rp2_common/pico_clib_interface/llvm_libc_interface.c @@ -7,11 +7,11 @@ #include #include #include -#include -#include - #include +#include "include/llvm_libc/time.h" +#include "include/llvm_libc/sys/time.h" + #include "pico/runtime_init.h" #include "pico/stdio.h" #include "pico/time.h" From 4a775eedfd9d574da219890d42ce22b3c827573b Mon Sep 17 00:00:00 2001 From: Hardy Griech Date: Wed, 15 Oct 2025 18:48:30 +0200 Subject: [PATCH 04/10] finetuning: now it is working also with picolibc --- .../util/pico_arm_clang_common.cmake | 13 +++++--- .../pico_clib_interface/BUILD.bazel | 9 +++++- .../pico_clib_interface/CMakeLists.txt | 4 +++ .../include/picolibc/sys/cdefs.h | 32 +++++++++++++++++++ 4 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 src/rp2_common/pico_clib_interface/include/picolibc/sys/cdefs.h diff --git a/cmake/preload/toolchains/util/pico_arm_clang_common.cmake b/cmake/preload/toolchains/util/pico_arm_clang_common.cmake index a6d51f4fd..c31bf2054 100644 --- a/cmake/preload/toolchains/util/pico_arm_clang_common.cmake +++ b/cmake/preload/toolchains/util/pico_arm_clang_common.cmake @@ -99,10 +99,15 @@ if (NOT PICO_COMPILER_SYSROOT) message(FATAL_ERROR "Could not find an llvm runtime for '${PICO_CLANG_RUNTIME}'") endif() set(PICO_COMMON_LANG_FLAGS "${PICO_COMMON_LANG_FLAGS} --sysroot ${PICO_COMPILER_SYSROOT}") -# llvmlibc / newlib -set(PICO_COMMON_LANG_FLAGS "${PICO_COMMON_LANG_FLAGS} -isystem ${PICO_COMPILER_SYSROOT}/../include/c++/v1") -# llvmlibc / newlib -set(PICO_COMMON_LANG_FLAGS "${PICO_COMMON_LANG_FLAGS} -isystem ${PICO_COMPILER_SYSROOT}/../include") + +# add some system includes due to structure of ATfE-21.1.1 header structure +# required for llvmlibc / newlib, NOT for picolibc +if(EXISTS "${PICO_COMPILER_SYSROOT}/../include/c++/v1") + set(PICO_COMMON_LANG_FLAGS "${PICO_COMMON_LANG_FLAGS} -isystem ${PICO_COMPILER_SYSROOT}/../include/c++/v1") +endif() +if(EXISTS "${PICO_COMPILER_SYSROOT}/../include") + set(PICO_COMMON_LANG_FLAGS "${PICO_COMMON_LANG_FLAGS} -isystem ${PICO_COMPILER_SYSROOT}/../include") +endif() # moving this here as a reminder from pico_standard_link; it was commented out theee, but if ever needed, # it belongs here as part of LINKER_FLAGS_INIT diff --git a/src/rp2_common/pico_clib_interface/BUILD.bazel b/src/rp2_common/pico_clib_interface/BUILD.bazel index 9bb05a99c..bde8093f0 100644 --- a/src/rp2_common/pico_clib_interface/BUILD.bazel +++ b/src/rp2_common/pico_clib_interface/BUILD.bazel @@ -101,7 +101,14 @@ cc_library( # For now, picolibc doesn't need to provide any headers. alias( name = "picolibc_interface", - actual = "//bazel:empty_cc_lib", + hdrs = [ + "include/picolibc/sys/cdefs.h", + ], + includes = ["include/picolibc"], + # It's hard to properly constrain compatibility since `auto` may select this, + # so just tag as manual. + tags = ["manual"], + target_compatible_with = compatible_with_rp2(), ) cc_library( diff --git a/src/rp2_common/pico_clib_interface/CMakeLists.txt b/src/rp2_common/pico_clib_interface/CMakeLists.txt index 84d3faf62..e080bd34d 100644 --- a/src/rp2_common/pico_clib_interface/CMakeLists.txt +++ b/src/rp2_common/pico_clib_interface/CMakeLists.txt @@ -21,6 +21,10 @@ if (NOT TARGET pico_clib_interface) # PICO_STDIO_SHORT_CIRCUIT_CLIB_FUNCS=0 #) + target_include_directories(pico_picolibc_interface SYSTEM INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/include/picolibc + ) + # ---- llvm_libc ---- pico_add_library(pico_llvm_libc_interface) diff --git a/src/rp2_common/pico_clib_interface/include/picolibc/sys/cdefs.h b/src/rp2_common/pico_clib_interface/include/picolibc/sys/cdefs.h new file mode 100644 index 000000000..5492e7864 --- /dev/null +++ b/src/rp2_common/pico_clib_interface/include/picolibc/sys/cdefs.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef __PICO_PICOLIBC_SYS_CDEFS_H +#define __PICO_PICOLIBC_SYS_CDEFS_H + +#if defined(__STDC__) || defined(__cplusplus) + +#define __CONCAT1(x,y) x ## y +#define __CONCAT(x,y) __CONCAT1(x,y) +#define __STRING(x) #x +#define __XSTRING(x) __STRING(x) + +#endif + +#define __unused __attribute__((__unused__)) +#define __used __attribute__((__used__)) +#define __packed __attribute__((__packed__)) +#define __aligned(x) __attribute__((__aligned__(x))) + +#define __always_inline __inline__ __attribute__((__always_inline__)) +#define __noinline __attribute__((__noinline__)) + +#define __printflike(fmtarg, firstvararg) \ + __attribute__((__format__ (__printf__, fmtarg, firstvararg))) + +#include_next + +#endif From 9dd3ce5bcffb7896756eb715229d16b5f0a0d2f4 Mon Sep 17 00:00:00 2001 From: Hardy Griech Date: Wed, 15 Oct 2025 18:51:48 +0200 Subject: [PATCH 05/10] correct bazel config --- src/rp2_common/pico_clib_interface/BUILD.bazel | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/rp2_common/pico_clib_interface/BUILD.bazel b/src/rp2_common/pico_clib_interface/BUILD.bazel index bde8093f0..8ddc02de2 100644 --- a/src/rp2_common/pico_clib_interface/BUILD.bazel +++ b/src/rp2_common/pico_clib_interface/BUILD.bazel @@ -98,8 +98,7 @@ cc_library( target_compatible_with = compatible_with_rp2(), ) -# For now, picolibc doesn't need to provide any headers. -alias( +cc_library( name = "picolibc_interface", hdrs = [ "include/picolibc/sys/cdefs.h", From bf670a8a327efecb474d44f8f991c46d84f868cd Mon Sep 17 00:00:00 2001 From: Hardy Griech Date: Wed, 15 Oct 2025 20:13:34 +0200 Subject: [PATCH 06/10] pico needs also some support --- cmake/preload/toolchains/pico_arm_cortex_m0plus_clang.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/preload/toolchains/pico_arm_cortex_m0plus_clang.cmake b/cmake/preload/toolchains/pico_arm_cortex_m0plus_clang.cmake index 5ebde3e00..681a6c752 100644 --- a/cmake/preload/toolchains/pico_arm_cortex_m0plus_clang.cmake +++ b/cmake/preload/toolchains/pico_arm_cortex_m0plus_clang.cmake @@ -1,7 +1,7 @@ set(CMAKE_SYSTEM_PROCESSOR cortex-m0plus) # these are all the directories under LLVM embedded toolchain for ARM (newlib or pibolibc) and under llvm_libc -set(PICO_CLANG_RUNTIMES armv6m_soft_nofp armv6m-unknown-none-eabi) +set(PICO_CLANG_RUNTIMES armv6m_soft_nofp armv6m_soft_nofp_size armv6m-unknown-none-eabi) set(PICO_COMMON_LANG_FLAGS "--target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m") From d13a84ff70ac389e4ba7764426fd5d7969186863 Mon Sep 17 00:00:00 2001 From: Hardy Griech Date: Wed, 15 Oct 2025 20:30:24 +0200 Subject: [PATCH 07/10] make newlib the default --- .../toolchains/util/pico_arm_clang_common.cmake | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/cmake/preload/toolchains/util/pico_arm_clang_common.cmake b/cmake/preload/toolchains/util/pico_arm_clang_common.cmake index c31bf2054..125b8e20a 100644 --- a/cmake/preload/toolchains/util/pico_arm_clang_common.cmake +++ b/cmake/preload/toolchains/util/pico_arm_clang_common.cmake @@ -44,8 +44,11 @@ endforeach() list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES PICO_CLIB) set(_PICO_CLIB_PATH "${PICO_COMPILER_DIR}/../lib/clang-runtimes/arm-none-eabi") -if(PICO_CLIB STREQUAL "") - # use default from above +if(PICO_CLIB STREQUAL "" OR PICO_CLIB STREQUAL "newlib") + # newlib is 1st class choice + if(EXISTS "${PICO_COMPILER_DIR}/../lib/clang-runtimes/newlib/arm-none-eabi") + set(_PICO_CLIB_PATH "${PICO_COMPILER_DIR}/../lib/clang-runtimes/newlib/arm-none-eabi") + endif() elseif(PICO_CLIB STREQUAL "llvm_libc") if(EXISTS "${PICO_COMPILER_DIR}/../lib/clang-runtimes/llvmlibc/arm-none-eabi") set(_PICO_CLIB_PATH "${PICO_COMPILER_DIR}/../lib/clang-runtimes/llvmlibc/arm-none-eabi") @@ -54,10 +57,6 @@ elseif(PICO_CLIB STREQUAL "picolibc") if(EXISTS "${PICO_COMPILER_DIR}/../lib/clang-runtimes/picolibc/arm-none-eabi") set(_PICO_CLIB_PATH "${PICO_COMPILER_DIR}/../lib/clang-runtimes/picolibc/arm-none-eabi") endif() -elseif(PICO_CLIB STREQUAL "newlib") - if(EXISTS "${PICO_COMPILER_DIR}/../lib/clang-runtimes/newlib/arm-none-eabi") - set(_PICO_CLIB_PATH "${PICO_COMPILER_DIR}/../lib/clang-runtimes/newlib/arm-none-eabi") - endif() else() message(FATAL_ERROR "PICO_CLIB must be one of newlib, picolib, llvm_libc or empty (but is '${PICO_CLIB}')") endif() From f7255e7a554b4bc3443bf8da2235106e9e5e0e43 Mon Sep 17 00:00:00 2001 From: Hardy Griech Date: Wed, 15 Oct 2025 21:23:21 +0200 Subject: [PATCH 08/10] code review I --- .../toolchains/util/pico_arm_clang_common.cmake | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/cmake/preload/toolchains/util/pico_arm_clang_common.cmake b/cmake/preload/toolchains/util/pico_arm_clang_common.cmake index 125b8e20a..9edf995c6 100644 --- a/cmake/preload/toolchains/util/pico_arm_clang_common.cmake +++ b/cmake/preload/toolchains/util/pico_arm_clang_common.cmake @@ -43,19 +43,20 @@ endforeach() list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES PICO_CLIB) -set(_PICO_CLIB_PATH "${PICO_COMPILER_DIR}/../lib/clang-runtimes/arm-none-eabi") +set(_CLANG_RUNTIMES_DIR "${PICO_COMPILER_DIR}/../lib/clang-runtimes") +set(_PICO_CLIB_PATH "${_CLANG_RUNTIMES_DIR}/arm-none-eabi") if(PICO_CLIB STREQUAL "" OR PICO_CLIB STREQUAL "newlib") # newlib is 1st class choice - if(EXISTS "${PICO_COMPILER_DIR}/../lib/clang-runtimes/newlib/arm-none-eabi") - set(_PICO_CLIB_PATH "${PICO_COMPILER_DIR}/../lib/clang-runtimes/newlib/arm-none-eabi") + if(EXISTS "${_CLANG_RUNTIMES_DIR}/newlib/arm-none-eabi") + set(_PICO_CLIB_PATH "${_CLANG_RUNTIMES_DIR}/newlib/arm-none-eabi") endif() elseif(PICO_CLIB STREQUAL "llvm_libc") - if(EXISTS "${PICO_COMPILER_DIR}/../lib/clang-runtimes/llvmlibc/arm-none-eabi") - set(_PICO_CLIB_PATH "${PICO_COMPILER_DIR}/../lib/clang-runtimes/llvmlibc/arm-none-eabi") + if(EXISTS "${_CLANG_RUNTIMES_DIR}/llvmlibc/arm-none-eabi") + set(_PICO_CLIB_PATH "${_CLANG_RUNTIMES_DIR}/llvmlibc/arm-none-eabi") endif() elseif(PICO_CLIB STREQUAL "picolibc") - if(EXISTS "${PICO_COMPILER_DIR}/../lib/clang-runtimes/picolibc/arm-none-eabi") - set(_PICO_CLIB_PATH "${PICO_COMPILER_DIR}/../lib/clang-runtimes/picolibc/arm-none-eabi") + if(EXISTS "${_CLANG_RUNTIMES_DIR}/picolibc/arm-none-eabi") + set(_PICO_CLIB_PATH "${_CLANG_RUNTIMES_DIR}/picolibc/arm-none-eabi") endif() else() message(FATAL_ERROR "PICO_CLIB must be one of newlib, picolib, llvm_libc or empty (but is '${PICO_CLIB}')") @@ -66,7 +67,7 @@ foreach(PICO_CLANG_RUNTIME IN LISTS PICO_CLANG_RUNTIMES) find_path(PICO_COMPILER_SYSROOT NAMES lib/libc.a HINTS ${_PICO_CLIB_PATH}/${PICO_CLANG_RUNTIME} - ${PICO_COMPILER_DIR}/../lib/clang-runtimes/${PICO_CLANG_RUNTIME} + ${_CLANG_RUNTIMES_DIR}/${PICO_CLANG_RUNTIME} ) if (PICO_COMPILER_SYSROOT) From 465dff2808b2649ea5412e08ccef72337cb56a3a Mon Sep 17 00:00:00 2001 From: Hardy Griech Date: Thu, 16 Oct 2025 15:46:46 +0200 Subject: [PATCH 09/10] use the same runtime_init() as for newlib -> picolibc now working for clang19.1.5/21.1.1 --- .../pico_clib_interface/picolibc_interface.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/rp2_common/pico_clib_interface/picolibc_interface.c b/src/rp2_common/pico_clib_interface/picolibc_interface.c index 63d79135e..d73ef3f97 100644 --- a/src/rp2_common/pico_clib_interface/picolibc_interface.c +++ b/src/rp2_common/pico_clib_interface/picolibc_interface.c @@ -124,9 +124,19 @@ void runtime_init(void) { runtime_init_per_core_install_stack_guard(&__StackBottom); #endif - // piolibc __libc_init_array does __preint_array and __init_array - extern void __libc_init_array(void); - __libc_init_array(); + // todo maybe we want to do this in the future, but it does stuff like register_tm_clones + // which we didn't do in previous SDKs + //extern void __libc_init_array(void); + //__libc_init_array(); + + // ... so instead just do the __preinit_array + runtime_run_initializers(); + // ... and the __init_array + extern void (*__init_array_start)(void); + extern void (*__init_array_end)(void); + for (void (**p)(void) = &__init_array_start; p < &__init_array_end; ++p) { + (*p)(); + } } #if !PICO_RUNTIME_NO_INIT_PER_CORE_TLS_SETUP @@ -151,4 +161,4 @@ PICO_RUNTIME_INIT_FUNC_PER_CORE(runtime_init_pre_core_tls_setup, PICO_RUNTIME_IN // "ldr r0, =__tls_base\n" // "bx lr\n" // ); -//} \ No newline at end of file +//} From fe941af87f8de7148f3996960cacaa75a7dfb7cc Mon Sep 17 00:00:00 2001 From: Hardy Griech Date: Fri, 17 Oct 2025 14:39:17 +0200 Subject: [PATCH 10/10] catch the case that PICO_CLIB is not set --- cmake/preload/toolchains/util/pico_arm_clang_common.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/preload/toolchains/util/pico_arm_clang_common.cmake b/cmake/preload/toolchains/util/pico_arm_clang_common.cmake index 9edf995c6..c6959afe0 100644 --- a/cmake/preload/toolchains/util/pico_arm_clang_common.cmake +++ b/cmake/preload/toolchains/util/pico_arm_clang_common.cmake @@ -45,7 +45,8 @@ list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES PICO_CLIB) set(_CLANG_RUNTIMES_DIR "${PICO_COMPILER_DIR}/../lib/clang-runtimes") set(_PICO_CLIB_PATH "${_CLANG_RUNTIMES_DIR}/arm-none-eabi") -if(PICO_CLIB STREQUAL "" OR PICO_CLIB STREQUAL "newlib") + +if(NOT PICO_CLIB OR PICO_CLIB STREQUAL "" OR PICO_CLIB STREQUAL "newlib") # newlib is 1st class choice if(EXISTS "${_CLANG_RUNTIMES_DIR}/newlib/arm-none-eabi") set(_PICO_CLIB_PATH "${_CLANG_RUNTIMES_DIR}/newlib/arm-none-eabi")