← Back to Pull requests

[libc] Application and testing support in baremetal Armv7-M CMake cache file #233497

Merged
vhscampos merged 1 files (48 lines) on Nov 09, 2026 14:52 UTC
View on GitHub
vhscampos vhscampos commented on Oct 19, 2026 16:57 UTC
Author

This patch adds support for linking and running applications, including
tests, targeting baremetal Armv7-M to the corresponding CMake cache
file.

The cache file takes into consideration if compiler-rt is enabled or
not. If it is, then linking applications is possible, and the relevant
CMake variables are set to enable test runs. If not, then only the libc
build is possible and enabled.

Particular libc configuration options, memory mappings, and QEMU options
are based on what Arm Toolchain for Embedded uses in its fully working
downstream testing.

Diff: 48 lines (+47 / -1) across 1 files Reviewer: michaelrj-google Review duration: 30114m
All Vouch review confidence checks passed
Residual risk 0.04 = Change Risk (0.26) × (1 − Review Confidence (0.84)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.26 · 48 lines diff across 1 files
0.26
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.77 · 4 substantive comment(s)
0.77
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
84%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.233
Real PR Conversation Timeline
6 items
llvmorg-github-actions[bot] llvmorg-github-actions[bot] commented on Oct 19, 2026 16:58 UTC
Bot

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Victor Campos (vhscampos)

<details>
<summary>Changes</summary>

This patch adds support for linking and running applications, including
tests, targeting baremetal Armv7-M to the corresponding CMake cache
file.

The cache file takes into consideration if compiler-rt is enabled or
not. If it is, then linking applications is possible, and the relevant
CMake variables are set to enable test runs. If not, then only the libc
build is possible and enabled.

Particular libc configuration options, memory mappings, and QEMU options
are based on what Arm Toolchain for Embedded uses in its fully working
downstream testing.

---

&lt;sub&gt;Stack created with &lt;a href="https://github.com/github/gh-stack"&gt;GitHub Stacks CLI&lt;/a&gt; • &lt;a href="https://gh.io/stacks-feedback"&gt;Give Feedback 💬&lt;/a&gt;&lt;/sub&gt;

---
Full diff: https://github.com/llvm/llvm-project/pull/233497.diff

1 Files Affected:

  • (modified) libc/cmake/caches/armv7m-none-eabi.cmake (+47-1)
  • ``````

    diff --git a/libc/cmake/caches/armv7m-none-eabi.cmake b/libc/cmake/caches/armv7m-none-eabi.cmake
    index ec7c64d5c839c..3eaac2b1e0ba4 100644
    --- a/libc/cmake/caches/armv7m-none-eabi.cmake
    +++ b/libc/cmake/caches/armv7m-none-eabi.cmake
    @@ -1,8 +1,54 @@
     set(CMAKE_SYSTEM_PROCESSOR arm CACHE STRING "")
     set(RUNTIMES_TARGET_TRIPLE "armv7m-none-eabi" CACHE STRING "")
    +set(LLVM_LIBC_FULL_BUILD ON CACHE BOOL "")
     
     foreach(lang C;CXX;ASM)
    -  set(CMAKE_${lang}_FLAGS "-march=armv7m -mcpu=cortex-m4 -mfloat-abi=soft -Wno-atomic-alignment" CACHE STRING "")
    +  set(CMAKE_${lang}_FLAGS "-march=armv7-m -mcpu=cortex-m4 -mfloat-abi=soft -mfpu=none" CACHE STRING "")
     endforeach()
     
    +# Offload the errno definition to libc
    +set(LIBC_CONF_ERRNO_MODE LIBC_ERRNO_MODE_SHARED CACHE STRING "")
    +# Enable floating-point conversions in printf. This became practical with the
    +# introduction of float320.
    +set(LIBC_CONF_PRINTF_DISABLE_FLOAT OFF CACHE BOOL "")
    +set(LIBC_CONF_PRINTF_FLOAT_TO_STR_USE_FLOAT320 ON CACHE BOOL "")
    +# Discard unused printf functionality
    +set(LIBC_CONF_PRINTF_MODULAR ON CACHE BOOL "")
    +
    +# Configs for testing and applications are only done if compiler-rt is enabled,
    +# as the latter is a dependency for full programs.
    +if(compiler-rt IN_LIST LLVM_ENABLE_RUNTIMES)
    +  set(LLVM_INCLUDE_TESTS ON CACHE BOOL "")
    +  set(LIBC_TEST_BUILTINS_TARGET "clang_rt.builtins-armv7m" CACHE STRING "")
    +
    +  # Memory mappings
    +  set(__boot_flash 0x00000000)
    +  set(__boot_flash_size 0x1000)
    +  set(__flash 0x21000000)
    +  set(__flash_size 0x600000)
    +  set(__ram 0x21600000)
    +  set(__ram_size 0xA00000)
    +  set(__stack_size 0x1000)
    +  set(SYMBOLS
    +    __boot_flash
    +    __boot_flash_size
    +    __flash
    +    __flash_size
    +    __ram
    +    __ram_size
    +    __stack_size
    +  )
    +
    +  set(DEFSYM_ARGS "")
    +  foreach(symbol IN LISTS SYMBOLS)
    +    list(APPEND DEFSYM_ARGS "-Wl,--defsym=${symbol}=${${symbol}}")
    +  endforeach()
    +
    +  set(LINKER_SCRIPT "${CMAKE_CURRENT_LIST_DIR}/../../test/UnitTest/llvm-libc-baremetal.ld")
    +
    +  set(LIBC_TEST_LINK_OPTIONS_DEFAULT "-T;${LINKER_SCRIPT};${DEFSYM_ARGS}" CACHE STRING "")
    +
    +  set(LIBC_TEST_CMD "qemu-system-arm -M mps2-an386 -cpu cortex-m4 -chardev stdio,mux=on,id=stdio0 -semihosting-config enable=on,chardev=stdio0 -monitor none -serial none -nographic -kernel @BINARY@" CACHE STRING "")
    +endif()
    +
     include(${CMAKE_CURRENT_LIST_DIR}/baremetal_common.cmake)
    
    
    ``````

    </details>

    voltur01 voltur01 commented on code on Oct 22, 2026 15:21 UTC
    Code Review
    libc/cmake/caches/armv7m-none-eabi.cmake:1
    @@ -1,8 +1,54 @@
     set(CMAKE_SYSTEM_PROCESSOR arm CACHE STRING "")
     set(RUNTIMES_TARGET_TRIPLE "armv7m-none-eabi" CACHE STRING "")
    +set(LLVM_LIBC_FULL_BUILD ON CACHE BOOL "")
     
     foreach(lang C;CXX;ASM)
    -  set(CMAKE_${lang}_FLAGS "-march=armv7m -mcpu=cortex-m4 -mfloat-abi=soft -Wno-atomic-alignment" CACHE STRING "")
    +  set(CMAKE_${lang}_FLAGS "-march=armv7-m -mcpu=cortex-m4 -mfloat-abi=soft -mfpu=none" CACHE STRING "")
     endforeach()
     
    +# Offload the errno definition to libc
    +set(LIBC_CONF_ERRNO_MODE LIBC_ERRNO_MODE_SHARED CACHE STRING "")
    +# Enable floating-point conversions in printf. This became practical with the
    +# introduction of float320.
    +set(LIBC_CONF_PRINTF_DISABLE_FLOAT OFF CACHE BOOL "")
    +set(LIBC_CONF_PRINTF_FLOAT_TO_STR_USE_FLOAT320 ON CACHE BOOL "")
    +# Discard unused printf functionality
    +set(LIBC_CONF_PRINTF_MODULAR ON CACHE BOOL "")
    +
    +# Configs for testing and applications are only done if compiler-rt is enabled,
    +# as the latter is a dependency for full programs.
    +if(compiler-rt IN_LIST LLVM_ENABLE_RUNTIMES)
    +  set(LLVM_INCLUDE_TESTS ON CACHE BOOL "")
    +  set(LIBC_TEST_BUILTINS_TARGET "clang_rt.builtins-armv7m" CACHE STRING "")
    +
    +  # Memory mappings
    +  set(__boot_flash 0x00000000)
    +  set(__boot_flash_size 0x1000)
    +  set(__flash 0x21000000)
    +  set(__flash_size 0x600000)
    +  set(__ram 0x21600000)
    +  set(__ram_size 0xA00000)
    +  set(__stack_size 0x1000)

    Would it make sense to set bigger stack and boot flash sizes from the very beginning to avoid stack overwriting heap when some tests happen to use more memory in the future?

    vhscampos vhscampos commented on code on Oct 23, 2026 11:19 UTC
    Code Review
    libc/cmake/caches/armv7m-none-eabi.cmake:1
    @@ -1,8 +1,54 @@
     set(CMAKE_SYSTEM_PROCESSOR arm CACHE STRING "")
     set(RUNTIMES_TARGET_TRIPLE "armv7m-none-eabi" CACHE STRING "")
    +set(LLVM_LIBC_FULL_BUILD ON CACHE BOOL "")
     
     foreach(lang C;CXX;ASM)
    -  set(CMAKE_${lang}_FLAGS "-march=armv7m -mcpu=cortex-m4 -mfloat-abi=soft -Wno-atomic-alignment" CACHE STRING "")
    +  set(CMAKE_${lang}_FLAGS "-march=armv7-m -mcpu=cortex-m4 -mfloat-abi=soft -mfpu=none" CACHE STRING "")
     endforeach()
     
    +# Offload the errno definition to libc
    +set(LIBC_CONF_ERRNO_MODE LIBC_ERRNO_MODE_SHARED CACHE STRING "")
    +# Enable floating-point conversions in printf. This became practical with the
    +# introduction of float320.
    +set(LIBC_CONF_PRINTF_DISABLE_FLOAT OFF CACHE BOOL "")
    +set(LIBC_CONF_PRINTF_FLOAT_TO_STR_USE_FLOAT320 ON CACHE BOOL "")
    +# Discard unused printf functionality
    +set(LIBC_CONF_PRINTF_MODULAR ON CACHE BOOL "")
    +
    +# Configs for testing and applications are only done if compiler-rt is enabled,
    +# as the latter is a dependency for full programs.
    +if(compiler-rt IN_LIST LLVM_ENABLE_RUNTIMES)
    +  set(LLVM_INCLUDE_TESTS ON CACHE BOOL "")
    +  set(LIBC_TEST_BUILTINS_TARGET "clang_rt.builtins-armv7m" CACHE STRING "")
    +
    +  # Memory mappings
    +  set(__boot_flash 0x00000000)
    +  set(__boot_flash_size 0x1000)
    +  set(__flash 0x21000000)
    +  set(__flash_size 0x600000)
    +  set(__ram 0x21600000)
    +  set(__ram_size 0xA00000)
    +  set(__stack_size 0x1000)

    Done

    voltur01 voltur01 commented on Oct 23, 2026 15:29 UTC
    Contributor

    Thank you for updating the sizes! Other settings look good to me, I was able to run the tests locally using the same.

    michaelrj-google michaelrj-google approved these changes on Nov 05, 2026 00:09 UTC
    Approved Reviewer

    LGTM

    Assignees
    vhscampos vhscampos
    Labels
    risk: low confidence: 84.1% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 26.3% (LOW) · Higher = larger blast radius
    26.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 84.1% · Lower = rushed or shallow review
    84.1%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 4.2% · Safe to merge
    4.2%