Skip to content

Commit

Permalink
Add explicit "-mfpu=" for AArch32 commands (#322)
Browse files Browse the repository at this point in the history
Added single precision version for v8.1m.main.
  • Loading branch information
domin144 committed Oct 2, 2023
1 parent ae0ee93 commit 71b11de
Show file tree
Hide file tree
Showing 17 changed files with 61 additions and 37 deletions.
43 changes: 29 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,6 @@ endfunction()
set(multilib_yaml_content "")

# Define which library variants to build and which flags to use.
# The order is <arch> <name suffix> <compile flags> <multilib selection flags> <qemu params>
add_library_variant(
aarch64
COMPILE_FLAGS "-march=armv8-a"
Expand All @@ -937,9 +936,12 @@ add_library_variant(
RAM_SIZE 2M
STACK_SIZE 8K
)
# For AArch32, clang uses different defaults for FPU selection than GCC, both
# when "+fp" or "+fp.dp" are used and when no FPU specifier is provided in
# "-march=". Using "-mfpu=" explicitly.
add_library_variant(
armv4t
COMPILE_FLAGS "-march=armv4t"
COMPILE_FLAGS "-march=armv4t -mfpu=none"
MULTILIB_FLAGS "--target=armv4t-none-unknown-eabi -mfpu=none"
QEMU_MACHINE "none"
QEMU_CPU "ti925t"
Expand All @@ -954,7 +956,7 @@ add_library_variant(
)
add_library_variant(
armv5te
COMPILE_FLAGS "-march=armv5te"
COMPILE_FLAGS "-march=armv5te -mfpu=none"
MULTILIB_FLAGS "--target=armv5e-none-unknown-eabi -mfpu=none"
QEMU_MACHINE "none"
QEMU_CPU "arm926"
Expand All @@ -970,7 +972,7 @@ add_library_variant(
add_library_variant(
armv6m
SUFFIX soft_nofp
COMPILE_FLAGS "-mfloat-abi=soft -march=armv6m"
COMPILE_FLAGS "-mfloat-abi=soft -march=armv6m -mfpu=none"
MULTILIB_FLAGS "--target=thumbv6m-none-unknown-eabi -mfpu=none"
QEMU_MACHINE "mps2-an385"
BOOT_FLASH_ADDRESS 0x00000000
Expand All @@ -981,8 +983,6 @@ add_library_variant(
RAM_SIZE 2M
STACK_SIZE 4K
)
# clang does not correctly handle +nofp and +fp for armv7a and armv7r in march.
# Using mfpu as a workaround.
add_library_variant(
armv7a
SUFFIX soft_nofp
Expand Down Expand Up @@ -1071,7 +1071,7 @@ add_library_variant(
add_library_variant(
armv7m
SUFFIX soft_nofp
COMPILE_FLAGS "-mfloat-abi=soft -march=armv7m+nofp"
COMPILE_FLAGS "-mfloat-abi=soft -march=armv7m -mfpu=none"
MULTILIB_FLAGS "--target=thumbv7m-none-unknown-eabi -mfpu=none"
QEMU_MACHINE "mps2-an385"
QEMU_CPU "cortex-m3"
Expand Down Expand Up @@ -1137,7 +1137,7 @@ add_library_variant(
add_library_variant(
armv8m.main
SUFFIX soft_nofp
COMPILE_FLAGS "-mfloat-abi=soft -march=armv8m.main+nofp"
COMPILE_FLAGS "-mfloat-abi=soft -march=armv8m.main -mfpu=none"
MULTILIB_FLAGS "--target=thumbv8m.main-none-unknown-eabi -mfpu=none"
QEMU_MACHINE "mps2-an505"
QEMU_CPU "cortex-m33"
Expand All @@ -1152,8 +1152,8 @@ add_library_variant(
add_library_variant(
armv8m.main
SUFFIX hard_fp
COMPILE_FLAGS "-mfloat-abi=hard -march=armv8m.main+fp"
MULTILIB_FLAGS "--target=thumbv8m.main-none-unknown-eabihf -mfpu=fpv5-d16"
COMPILE_FLAGS "-mfloat-abi=hard -march=armv8m.main -mfpu=fpv5-sp-d16"
MULTILIB_FLAGS "--target=thumbv8m.main-none-unknown-eabihf -mfpu=fpv5-sp-d16"
QEMU_MACHINE "mps2-an505"
QEMU_CPU "cortex-m33"
BOOT_FLASH_ADDRESS 0x10000000
Expand All @@ -1167,7 +1167,7 @@ add_library_variant(
add_library_variant(
armv8.1m.main
SUFFIX soft_nofp_nomve
COMPILE_FLAGS "-mfloat-abi=soft -march=armv8.1m.main+nofp+nomve"
COMPILE_FLAGS "-mfloat-abi=soft -march=armv8.1m.main+nomve -mfpu=none"
MULTILIB_FLAGS "--target=thumbv8.1m.main-none-unknown-eabi -mfpu=none"
QEMU_MACHINE "mps3-an547"
QEMU_CPU "cortex-m55"
Expand All @@ -1181,8 +1181,8 @@ add_library_variant(
)
add_library_variant(
armv8.1m.main
SUFFIX hard_fp
COMPILE_FLAGS "-mfloat-abi=hard -march=armv8.1m.main+fp"
SUFFIX hard_fp_nomve
COMPILE_FLAGS "-mfloat-abi=hard -march=armv8.1m.main+nomve -mfpu=fp-armv8-fullfp16-sp-d16"
MULTILIB_FLAGS "--target=thumbv8.1m.main-none-unknown-eabihf -march=thumbv8.1m.main+fp16 -mfpu=fp-armv8-fullfp16-sp-d16"
QEMU_MACHINE "mps3-an547"
QEMU_CPU "cortex-m55"
Expand All @@ -1194,10 +1194,25 @@ add_library_variant(
RAM_SIZE 2M
STACK_SIZE 4K
)
add_library_variant(
armv8.1m.main
SUFFIX hard_fpdp_nomve
COMPILE_FLAGS "-mfloat-abi=hard -march=armv8.1m.main+nomve -mfpu=fp-armv8-fullfp16-d16"
MULTILIB_FLAGS "--target=thumbv8.1m.main-none-unknown-eabihf -march=thumbv8.1m.main+fp16 -mfpu=fp-armv8-fullfp16-d16"
QEMU_MACHINE "mps3-an547"
QEMU_CPU "cortex-m55"
BOOT_FLASH_ADDRESS 0x00000000
BOOT_FLASH_SIZE 512K
FLASH_ADDRESS 0x01000000
FLASH_SIZE 2M
RAM_ADDRESS 0x60000000
RAM_SIZE 2M
STACK_SIZE 4K
)
add_library_variant(
armv8.1m.main
SUFFIX hard_nofp_mve
COMPILE_FLAGS "-mfloat-abi=hard -march=armv8.1m.main+nofp+mve"
COMPILE_FLAGS "-mfloat-abi=hard -march=armv8.1m.main+mve -mfpu=none"
MULTILIB_FLAGS "--target=thumbv8.1m.main-none-unknown-eabihf -march=thumbv8.1m.main+dsp+mve -mfpu=none"
QEMU_MACHINE "mps3-an547"
QEMU_CPU "cortex-m55"
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ find . -type f -perm +0111 | xargs xattr -d com.apple.quarantine
To use the toolchain, on the command line you need to provide the following options:
* The target triple.
* The FPU to use.
* Disabling C++ exceptions and RTTI that are not supported by the standard library provided yet.
* The C runtime library: either `crt0` or `crt0-semihost`.
* The semihosting library, if using `crt0-semihost`.
Expand All @@ -102,6 +103,7 @@ For example:
$ PATH=<install-dir>/LLVMEmbeddedToolchainForArm-<revision>/bin:$PATH
$ clang \
--target=armv6m-none-eabi \
-mfpu=none \
-fno-exceptions \
-fno-rtti \
-lcrt0-semihost \
Expand Down Expand Up @@ -129,6 +131,7 @@ directories of the libraries you want to use. For example:
$ clang \
--sysroot=<install-dir>/LLVMEmbeddedToolchainForArm-<revision>/lib/clang-runtimes/arm-none-eabi/armv6m_soft_nofp \
--target=armv6m-none-eabi \
-mfpu=none \
-fno-exceptions \
-fno-rtti \
-lcrt0-semihost \
Expand All @@ -137,6 +140,9 @@ $ clang \
-o example example.c
```

The FPU selection can be skipped, but it is not recommended to as the defaults
are different to GCC ones.

See [Migrating from Arm GNU Toolchain](https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/blob/main/docs/migrating.md)
for advice on using LLVM Embedded Toolchain for Arm with existing projects
relying on the Arm GNU Toolchain.
Expand Down
2 changes: 1 addition & 1 deletion packagetest/hello.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %clang --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -lcrt0-semihost -lsemihost -T %S/Inputs/microbit.ld %s -o %t.out
// RUN: %clang --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -lcrt0-semihost -lsemihost -T %S/Inputs/microbit.ld %s -o %t.out
// RUN: qemu-system-arm -M microbit -semihosting -nographic -device loader,file=%t.out 2>&1 | FileCheck %s

#include <stdio.h>
Expand Down
2 changes: 1 addition & 1 deletion packagetest/hello.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %clangxx --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti -T %S/Inputs/microbit.ld %s -o %t.out
// RUN: %clangxx --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti -T %S/Inputs/microbit.ld %s -o %t.out
// RUN: qemu-system-arm -M microbit -semihosting -nographic -device loader,file=%t.out 2>&1 | FileCheck %s

// Include as many C++17 headers as possible.
Expand Down
2 changes: 1 addition & 1 deletion samples/Makefile.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ifndef BIN_PATH
BIN_PATH=../../../bin
endif

MICROBIT_TARGET=--target=armv6m-none-eabi -march=armv6m -mfloat-abi=soft
MICROBIT_TARGET=--target=armv6m-none-eabi -march=armv6m -mfpu=none -mfloat-abi=soft
AARCH64_TARGET=--target=aarch64-none-elf

CRT=-lcrt0
Expand Down
2 changes: 1 addition & 1 deletion samples/src/baremetal-semihosting/make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ if exist hello.hex del /q hello.hex
@exit /B 1

:build_fn
%BIN_PATH%\clang.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -lcrt0-semihost -lsemihost -g -T ..\..\ldscripts\microbit.ld -o hello.elf hello.c
%BIN_PATH%\clang.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -lcrt0-semihost -lsemihost -g -T ..\..\ldscripts\microbit.ld -o hello.elf hello.c
%BIN_PATH%\llvm-objcopy.exe -O ihex hello.elf hello.hex
@exit /B
2 changes: 1 addition & 1 deletion samples/src/baremetal-uart/make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ if exist hello.hex del /q hello.hex
@exit /B 1

:build_fn
%BIN_PATH%\clang.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -lcrt0 -g -T ..\..\ldscripts\microbit.ld -o hello.elf hello.c
%BIN_PATH%\clang.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -lcrt0 -g -T ..\..\ldscripts\microbit.ld -o hello.elf hello.c
%BIN_PATH%\llvm-objcopy.exe -O ihex hello.elf hello.hex
@exit /B
8 changes: 4 additions & 4 deletions samples/src/cpp-baremetal-semihosting-cfi/make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ if exist hello.hex del /q hello.hex
@exit /B 1

:build_fn
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -fno-exceptions -fno-rtti -flto -fsanitize=cfi -fvisibility=hidden -fno-sanitize-ignorelist -g -c hello.cpp
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti -flto -T ..\..\ldscripts\microbit.ld -g -o hello.elf hello.o
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -fno-exceptions -fno-rtti -flto -fsanitize=cfi -fvisibility=hidden -fno-sanitize-ignorelist -g -c hello.cpp
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti -flto -T ..\..\ldscripts\microbit.ld -g -o hello.elf hello.o
%BIN_PATH%\llvm-objcopy.exe -O ihex hello.elf hello.hex
@exit /B

:build_no_cfi_fn
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -fno-exceptions -fno-rtti -flto -g -c hello.cpp
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti -flto -T ..\..\ldscripts\microbit.ld -g -o hello.elf hello.o
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -fno-exceptions -fno-rtti -flto -g -c hello.cpp
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti -flto -T ..\..\ldscripts\microbit.ld -g -o hello.elf hello.o
%BIN_PATH%\llvm-objcopy.exe -O ihex hello.elf hello.hex
@exit /B
4 changes: 2 additions & 2 deletions samples/src/cpp-baremetal-semihosting-prof/make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ if exist proflib.o del /q proflib.o
@exit /B 1

:build_fn
%BIN_PATH%\clang.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -g -c proflib.c
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti -g -T ..\..\ldscripts\microbit.ld -fprofile-instr-generate -fcoverage-mapping -o hello.elf hello.cpp proflib.o
%BIN_PATH%\clang.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -g -c proflib.c
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti -g -T ..\..\ldscripts\microbit.ld -fprofile-instr-generate -fcoverage-mapping -o hello.elf hello.cpp proflib.o
%BIN_PATH%\llvm-objcopy.exe -O ihex hello.elf hello.hex
@exit /B
4 changes: 2 additions & 2 deletions samples/src/cpp-baremetal-semihosting-ubsan/make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ if exist hello.hex del /q hello.hex
@exit /B 1

:build_fn
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti --std=c++17 -fsanitize=undefined -fsanitize-minimal-runtime -g -T ../../ldscripts/microbit.ld -o hello.elf *.cpp
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti --std=c++17 -fsanitize=undefined -fsanitize-minimal-runtime -g -T ../../ldscripts/microbit.ld -o hello.elf *.cpp
%BIN_PATH%\llvm-objcopy.exe -O ihex hello.elf hello.hex
@exit /B

:build_trap_fn
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti --std=c++17 -fsanitize=undefined -fsanitize-trap=all -g -T ../../ldscripts/microbit.ld -o hello.elf *.cpp
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti --std=c++17 -fsanitize=undefined -fsanitize-trap=all -g -T ../../ldscripts/microbit.ld -o hello.elf *.cpp
%BIN_PATH%\llvm-objcopy.exe -O ihex hello.elf hello.hex
@exit /B
2 changes: 1 addition & 1 deletion samples/src/cpp-baremetal-semihosting/make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ if exist hello.hex del /q hello.hex
@exit /B 1

:build_fn
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti -g -T ..\..\ldscripts\microbit.ld -o hello.elf hello.cpp
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti -g -T ..\..\ldscripts\microbit.ld -o hello.elf hello.cpp
%BIN_PATH%\llvm-objcopy.exe -O ihex hello.elf hello.hex
@exit /B
4 changes: 2 additions & 2 deletions test-support/picolibc-test-wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
# https://github.com/picolibc/picolibc/pull/500
"picolibc_aarch64-build/test/math_errhandling",
"picolibc_aarch64-build/test/test-fma",
"picolibc_armv7em_hard_fpv4_sp_d16-build/test/math_errhandling",
"picolibc_armv7m_soft_fpv4_sp_d16-build/test/math_errhandling",
"picolibc_armv8.1m.main_hard_fp-build/test/math_errhandling",
"picolibc_armv7em_hard_fpv4_sp_d16-build/test/math_errhandling",
"picolibc_armv8.1m.main_hard_fp_nomve-build/test/math_errhandling",
"picolibc_armv8.1m.main_hard_nofp_mve-build/test/fenv",
"picolibc_armv8.1m.main_hard_nofp_mve-build/test/math_errhandling",

Expand Down
2 changes: 1 addition & 1 deletion test/multilib/armv4t.test
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# RUN: %clang -print-multi-directory --target=arm-none-eabi | FileCheck %s
# RUN: %clang -print-multi-directory --target=arm-none-eabi -mfpu=none | FileCheck %s
# CHECK: arm-none-eabi/armv4t
# CHECK-EMPTY:
2 changes: 1 addition & 1 deletion test/multilib/armv5e.test
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# RUN: %clang -print-multi-directory --target=armv5e-none-eabi | FileCheck %s
# RUN: %clang -print-multi-directory --target=armv5e-none-eabi -mfpu=none | FileCheck %s
# CHECK: arm-none-eabi/armv5te
# CHECK-EMPTY:
2 changes: 1 addition & 1 deletion test/multilib/armv6m.test
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# RUN: %clang -print-multi-directory --target=armv6m-none-eabi | FileCheck %s
# RUN: %clang -print-multi-directory --target=armv6m-none-eabi -mfpu=none | FileCheck %s
# CHECK: arm-none-eabi/armv6m_soft_nofp
# CHECK-EMPTY:
9 changes: 6 additions & 3 deletions test/multilib/armv8.1m.main.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
# CHECK: arm-none-eabi/armv8.1m.main_soft_nofp
# CHECK-EMPTY:

# RUN: %clang -print-multi-directory --target=armv8.1m.main-none-eabihf -march=armv8.1m.main+fp | FileCheck --check-prefix=HARD %s
# HARD: arm-none-eabi/armv8.1m.main_hard_fp
RUN: %clang -print-multi-directory --target=armv8.1m.main-none-eabihf -march=armv8.1m.main -mfpu=fp-armv8-fullfp16-sp-d16 | FileCheck --check-prefix=HARD_FP %s
# HARD_FP: arm-none-eabi/armv8.1m.main_hard_fp_nomve
# HARD-EMPTY:

# RUN: %clang -print-multi-directory --target=armv8.1m.main-none-eabihf -march=armv8.1m.main+nofp+mve | FileCheck --check-prefix=MVE %s
# RUN: %clang -print-multi-directory --target=armv8.1m.main-none-eabihf -march=armv8.1m.main -mfpu=fp-armv8-fullfp16-d16 | FileCheck --check-prefix=HARD_FPDP %s
# HARD_FPDP: arm-none-eabi/armv8.1m.main_hard_fpdp_nomve

# RUN: %clang -print-multi-directory --target=armv8.1m.main-none-eabihf -march=armv8.1m.main+mve -mfpu=none | FileCheck --check-prefix=MVE %s
# MVE: arm-none-eabi/armv8.1m.main_hard_nofp_mve
# MVE-EMPTY:

Expand Down
2 changes: 1 addition & 1 deletion test/multilib/armv8m.main.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# CHECK: arm-none-eabi/armv8m.main_soft_nofp
# CHECK-EMPTY:

# RUN: %clang -print-multi-directory --target=armv8m.main-none-eabihf | FileCheck --check-prefix=HARD %s
# RUN: %clang -print-multi-directory --target=armv8m.main-none-eabihf -mfpu=fpv5-sp-d16 | FileCheck --check-prefix=HARD %s
# HARD: arm-none-eabi/armv8m.main_hard_fp
# HARD-EMPTY:

0 comments on commit 71b11de

Please sign in to comment.