Skip to content

Commit 71b11de

Browse files
authored
Add explicit "-mfpu=" for AArch32 commands (#322)
Added single precision version for v8.1m.main.
1 parent ae0ee93 commit 71b11de

File tree

17 files changed

+61
-37
lines changed

17 files changed

+61
-37
lines changed

CMakeLists.txt

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,6 @@ endfunction()
922922
set(multilib_yaml_content "")
923923

924924
# Define which library variants to build and which flags to use.
925-
# The order is <arch> <name suffix> <compile flags> <multilib selection flags> <qemu params>
926925
add_library_variant(
927926
aarch64
928927
COMPILE_FLAGS "-march=armv8-a"
@@ -937,9 +936,12 @@ add_library_variant(
937936
RAM_SIZE 2M
938937
STACK_SIZE 8K
939938
)
939+
# For AArch32, clang uses different defaults for FPU selection than GCC, both
940+
# when "+fp" or "+fp.dp" are used and when no FPU specifier is provided in
941+
# "-march=". Using "-mfpu=" explicitly.
940942
add_library_variant(
941943
armv4t
942-
COMPILE_FLAGS "-march=armv4t"
944+
COMPILE_FLAGS "-march=armv4t -mfpu=none"
943945
MULTILIB_FLAGS "--target=armv4t-none-unknown-eabi -mfpu=none"
944946
QEMU_MACHINE "none"
945947
QEMU_CPU "ti925t"
@@ -954,7 +956,7 @@ add_library_variant(
954956
)
955957
add_library_variant(
956958
armv5te
957-
COMPILE_FLAGS "-march=armv5te"
959+
COMPILE_FLAGS "-march=armv5te -mfpu=none"
958960
MULTILIB_FLAGS "--target=armv5e-none-unknown-eabi -mfpu=none"
959961
QEMU_MACHINE "none"
960962
QEMU_CPU "arm926"
@@ -970,7 +972,7 @@ add_library_variant(
970972
add_library_variant(
971973
armv6m
972974
SUFFIX soft_nofp
973-
COMPILE_FLAGS "-mfloat-abi=soft -march=armv6m"
975+
COMPILE_FLAGS "-mfloat-abi=soft -march=armv6m -mfpu=none"
974976
MULTILIB_FLAGS "--target=thumbv6m-none-unknown-eabi -mfpu=none"
975977
QEMU_MACHINE "mps2-an385"
976978
BOOT_FLASH_ADDRESS 0x00000000
@@ -981,8 +983,6 @@ add_library_variant(
981983
RAM_SIZE 2M
982984
STACK_SIZE 4K
983985
)
984-
# clang does not correctly handle +nofp and +fp for armv7a and armv7r in march.
985-
# Using mfpu as a workaround.
986986
add_library_variant(
987987
armv7a
988988
SUFFIX soft_nofp
@@ -1071,7 +1071,7 @@ add_library_variant(
10711071
add_library_variant(
10721072
armv7m
10731073
SUFFIX soft_nofp
1074-
COMPILE_FLAGS "-mfloat-abi=soft -march=armv7m+nofp"
1074+
COMPILE_FLAGS "-mfloat-abi=soft -march=armv7m -mfpu=none"
10751075
MULTILIB_FLAGS "--target=thumbv7m-none-unknown-eabi -mfpu=none"
10761076
QEMU_MACHINE "mps2-an385"
10771077
QEMU_CPU "cortex-m3"
@@ -1137,7 +1137,7 @@ add_library_variant(
11371137
add_library_variant(
11381138
armv8m.main
11391139
SUFFIX soft_nofp
1140-
COMPILE_FLAGS "-mfloat-abi=soft -march=armv8m.main+nofp"
1140+
COMPILE_FLAGS "-mfloat-abi=soft -march=armv8m.main -mfpu=none"
11411141
MULTILIB_FLAGS "--target=thumbv8m.main-none-unknown-eabi -mfpu=none"
11421142
QEMU_MACHINE "mps2-an505"
11431143
QEMU_CPU "cortex-m33"
@@ -1152,8 +1152,8 @@ add_library_variant(
11521152
add_library_variant(
11531153
armv8m.main
11541154
SUFFIX hard_fp
1155-
COMPILE_FLAGS "-mfloat-abi=hard -march=armv8m.main+fp"
1156-
MULTILIB_FLAGS "--target=thumbv8m.main-none-unknown-eabihf -mfpu=fpv5-d16"
1155+
COMPILE_FLAGS "-mfloat-abi=hard -march=armv8m.main -mfpu=fpv5-sp-d16"
1156+
MULTILIB_FLAGS "--target=thumbv8m.main-none-unknown-eabihf -mfpu=fpv5-sp-d16"
11571157
QEMU_MACHINE "mps2-an505"
11581158
QEMU_CPU "cortex-m33"
11591159
BOOT_FLASH_ADDRESS 0x10000000
@@ -1167,7 +1167,7 @@ add_library_variant(
11671167
add_library_variant(
11681168
armv8.1m.main
11691169
SUFFIX soft_nofp_nomve
1170-
COMPILE_FLAGS "-mfloat-abi=soft -march=armv8.1m.main+nofp+nomve"
1170+
COMPILE_FLAGS "-mfloat-abi=soft -march=armv8.1m.main+nomve -mfpu=none"
11711171
MULTILIB_FLAGS "--target=thumbv8.1m.main-none-unknown-eabi -mfpu=none"
11721172
QEMU_MACHINE "mps3-an547"
11731173
QEMU_CPU "cortex-m55"
@@ -1181,8 +1181,8 @@ add_library_variant(
11811181
)
11821182
add_library_variant(
11831183
armv8.1m.main
1184-
SUFFIX hard_fp
1185-
COMPILE_FLAGS "-mfloat-abi=hard -march=armv8.1m.main+fp"
1184+
SUFFIX hard_fp_nomve
1185+
COMPILE_FLAGS "-mfloat-abi=hard -march=armv8.1m.main+nomve -mfpu=fp-armv8-fullfp16-sp-d16"
11861186
MULTILIB_FLAGS "--target=thumbv8.1m.main-none-unknown-eabihf -march=thumbv8.1m.main+fp16 -mfpu=fp-armv8-fullfp16-sp-d16"
11871187
QEMU_MACHINE "mps3-an547"
11881188
QEMU_CPU "cortex-m55"
@@ -1194,10 +1194,25 @@ add_library_variant(
11941194
RAM_SIZE 2M
11951195
STACK_SIZE 4K
11961196
)
1197+
add_library_variant(
1198+
armv8.1m.main
1199+
SUFFIX hard_fpdp_nomve
1200+
COMPILE_FLAGS "-mfloat-abi=hard -march=armv8.1m.main+nomve -mfpu=fp-armv8-fullfp16-d16"
1201+
MULTILIB_FLAGS "--target=thumbv8.1m.main-none-unknown-eabihf -march=thumbv8.1m.main+fp16 -mfpu=fp-armv8-fullfp16-d16"
1202+
QEMU_MACHINE "mps3-an547"
1203+
QEMU_CPU "cortex-m55"
1204+
BOOT_FLASH_ADDRESS 0x00000000
1205+
BOOT_FLASH_SIZE 512K
1206+
FLASH_ADDRESS 0x01000000
1207+
FLASH_SIZE 2M
1208+
RAM_ADDRESS 0x60000000
1209+
RAM_SIZE 2M
1210+
STACK_SIZE 4K
1211+
)
11971212
add_library_variant(
11981213
armv8.1m.main
11991214
SUFFIX hard_nofp_mve
1200-
COMPILE_FLAGS "-mfloat-abi=hard -march=armv8.1m.main+nofp+mve"
1215+
COMPILE_FLAGS "-mfloat-abi=hard -march=armv8.1m.main+mve -mfpu=none"
12011216
MULTILIB_FLAGS "--target=thumbv8.1m.main-none-unknown-eabihf -march=thumbv8.1m.main+dsp+mve -mfpu=none"
12021217
QEMU_MACHINE "mps3-an547"
12031218
QEMU_CPU "cortex-m55"

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ find . -type f -perm +0111 | xargs xattr -d com.apple.quarantine
8888
8989
To use the toolchain, on the command line you need to provide the following options:
9090
* The target triple.
91+
* The FPU to use.
9192
* Disabling C++ exceptions and RTTI that are not supported by the standard library provided yet.
9293
* The C runtime library: either `crt0` or `crt0-semihost`.
9394
* The semihosting library, if using `crt0-semihost`.
@@ -102,6 +103,7 @@ For example:
102103
$ PATH=<install-dir>/LLVMEmbeddedToolchainForArm-<revision>/bin:$PATH
103104
$ clang \
104105
--target=armv6m-none-eabi \
106+
-mfpu=none \
105107
-fno-exceptions \
106108
-fno-rtti \
107109
-lcrt0-semihost \
@@ -129,6 +131,7 @@ directories of the libraries you want to use. For example:
129131
$ clang \
130132
--sysroot=<install-dir>/LLVMEmbeddedToolchainForArm-<revision>/lib/clang-runtimes/arm-none-eabi/armv6m_soft_nofp \
131133
--target=armv6m-none-eabi \
134+
-mfpu=none \
132135
-fno-exceptions \
133136
-fno-rtti \
134137
-lcrt0-semihost \
@@ -137,6 +140,9 @@ $ clang \
137140
-o example example.c
138141
```
139142

143+
The FPU selection can be skipped, but it is not recommended to as the defaults
144+
are different to GCC ones.
145+
140146
See [Migrating from Arm GNU Toolchain](https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/blob/main/docs/migrating.md)
141147
for advice on using LLVM Embedded Toolchain for Arm with existing projects
142148
relying on the Arm GNU Toolchain.

packagetest/hello.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -lcrt0-semihost -lsemihost -T %S/Inputs/microbit.ld %s -o %t.out
1+
// 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
22
// RUN: qemu-system-arm -M microbit -semihosting -nographic -device loader,file=%t.out 2>&1 | FileCheck %s
33

44
#include <stdio.h>

packagetest/hello.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// 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
1+
// 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
22
// RUN: qemu-system-arm -M microbit -semihosting -nographic -device loader,file=%t.out 2>&1 | FileCheck %s
33

44
// Include as many C++17 headers as possible.

samples/Makefile.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ifndef BIN_PATH
1919
BIN_PATH=../../../bin
2020
endif
2121

22-
MICROBIT_TARGET=--target=armv6m-none-eabi -march=armv6m -mfloat-abi=soft
22+
MICROBIT_TARGET=--target=armv6m-none-eabi -march=armv6m -mfpu=none -mfloat-abi=soft
2323
AARCH64_TARGET=--target=aarch64-none-elf
2424

2525
CRT=-lcrt0

samples/src/baremetal-semihosting/make.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ if exist hello.hex del /q hello.hex
4949
@exit /B 1
5050

5151
:build_fn
52-
%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
52+
%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
5353
%BIN_PATH%\llvm-objcopy.exe -O ihex hello.elf hello.hex
5454
@exit /B

samples/src/baremetal-uart/make.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ if exist hello.hex del /q hello.hex
4949
@exit /B 1
5050

5151
:build_fn
52-
%BIN_PATH%\clang.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -lcrt0 -g -T ..\..\ldscripts\microbit.ld -o hello.elf hello.c
52+
%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
5353
%BIN_PATH%\llvm-objcopy.exe -O ihex hello.elf hello.hex
5454
@exit /B

samples/src/cpp-baremetal-semihosting-cfi/make.bat

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ if exist hello.hex del /q hello.hex
5656
@exit /B 1
5757

5858
:build_fn
59-
%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
60-
%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
59+
%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
60+
%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
6161
%BIN_PATH%\llvm-objcopy.exe -O ihex hello.elf hello.hex
6262
@exit /B
6363

6464
:build_no_cfi_fn
65-
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -fno-exceptions -fno-rtti -flto -g -c hello.cpp
66-
%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
65+
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -fno-exceptions -fno-rtti -flto -g -c hello.cpp
66+
%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
6767
%BIN_PATH%\llvm-objcopy.exe -O ihex hello.elf hello.hex
6868
@exit /B

samples/src/cpp-baremetal-semihosting-prof/make.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ if exist proflib.o del /q proflib.o
5858
@exit /B 1
5959

6060
:build_fn
61-
%BIN_PATH%\clang.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -g -c proflib.c
62-
%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
61+
%BIN_PATH%\clang.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -g -c proflib.c
62+
%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
6363
%BIN_PATH%\llvm-objcopy.exe -O ihex hello.elf hello.hex
6464
@exit /B

samples/src/cpp-baremetal-semihosting-ubsan/make.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ if exist hello.hex del /q hello.hex
5555
@exit /B 1
5656

5757
:build_fn
58-
%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
58+
%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
5959
%BIN_PATH%\llvm-objcopy.exe -O ihex hello.elf hello.hex
6060
@exit /B
6161

6262
:build_trap_fn
63-
%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
63+
%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
6464
%BIN_PATH%\llvm-objcopy.exe -O ihex hello.elf hello.hex
6565
@exit /B

0 commit comments

Comments
 (0)