Rework of -target/-mcpu/-mfpu options for LLVM CLANG#2498
Conversation
Due to various issues reported so far: Open-CMSIS-Pack/cmsis-toolbox#583 arm/arm-toolchain#861 the -target/-mcpu/-mfpu options in CLANG.17.0.1.cmake have been reworked based on the ATfE manual pages: https://developer.arm.com/documentation/107976/22-1-0/Compile-for-a-specific-Arm-architecture-or-Arm-processor/-mcpu-command-line-options-for-M-profile-processors?lang=en https://developer.arm.com/documentation/107976/22-1-0/Compile-for-a-specific-Arm-architecture-or-Arm-processor/-mcpu-command-line-options-for-A-profile-processors https://developer.arm.com/documentation/107976/22-1-0/Compile-for-a-specific-Arm-architecture-or-Arm-processor/-mcpu-command-line-options-for-R-profile-processors
There was a problem hiding this comment.
Pull request overview
This pull request reworks how the LLVM Embedded Toolchain (Clang) CPU/arch-related flags are derived in CLANG.17.0.1.cmake, aiming to resolve reported backend crashes/hardfaults by adjusting the use of -target, -mcpu, and -mfpu according to Arm toolchain guidance.
Changes:
- Reworked per-CPU mappings to prefer encoding FP/MVE/DSP capabilities into
-mcpufeature strings and, in many cases, omit-mfpu. - Adjusted target triple selection logic (notably for Cortex-A/M/R vs other arches) and added conditional handling for
-mabi. - Added validation/error branches for unsupported FPU/MVE combinations for Cortex-M52/M55/M85 and related CPUs.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Removed redundant checks for FP_FVE in MVE conditions to simplify error handling for cortex-m CPUs.
actually the option -mabi is very much irrelevant to this cmake file, because: 1) -mabi option is only meant for aarch64 state 2) -mabi=aapcs is default and aarch64 cortex-a actually doesn't really support the option without FPU: "Targeting A-profile processors in AArch64 state without an FPU is considered an [LLVM project] feature" https://developer.arm.com/documentation/107976/22-1-0/Compile-for-a-specific-Arm-architecture-or-Arm-processor/-mcpu-command-line-options-for-A-profile-processors?lang=en But make the changes regarding -mabi option in this commit to be better compliant to the manual page above
yes, you are right Co-authored-by: Daniel Brondani <daniel.brondani@arm.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2498 +/- ##
=======================================
Coverage 65.24% 65.24%
=======================================
Files 147 147
Lines 26675 26675
Branches 16166 16166
=======================================
Hits 17405 17405
Misses 7074 7074
Partials 2196 2196
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
|
The incorrect FP_FVE condition check in the first commit was due to |
brondani
left a comment
There was a problem hiding this comment.
I see a couple of shortcomings that have a wider scope and could/should be fixed as part of the related issues:
INT_MVEshould beMVE, related to:
Open-CMSIS-Pack/cbuild2cmake#485PACBTIfor Cortex-M52, M55, M85, related to:
#2285
The rest looks good to me.
Due to various issues reported so far:
the -target/-mcpu/-mfpu options in CLANG.17.0.1.cmake have been reworked based on the ATfE manual pages:
Fixes
mcpu=cortex-m55 -mfpu=fpv5-sp-d16can lead to fatal error in backend #2491Changes
options for Cortex-M/A/R covered by CMSIS-Toolbox.
Changes have been tested with all Cortex-M built targets in https://github.com/Arm-Examples/AVH-Hello
No more crash issue tested with https://github.com/Arm-Examples/cmsis-mlek-examples
No more hardfault issue tested with Tensorflow_LiteRT_HelloWorld on STM32F7-Disco
Checklist