I'm working on a STM32H753 with a double precision FPU.
I first tried the following compile and link commands:
arm-none-eabi-gcc -mcpu=cortex-m7 -std=c99 -mfpu=fpv5-d16 -mfloat-abi=hard -mthumb -g3 -O1 -Wall -ffunction-sections -fdata-sections -fstack-usage xxx.c -o xxx.o
arm-none-eabi-gcc -T"xxx.ld" -mfpu=fpv5-d16 -mfloat-abi=hard -mthumb -nostdlib -Wl,-Map=xxx.map -o xxx.elf xxx.o -lm -lc
but got a link error
xxx/arm-none-eabi/bin/ld: error: xxx.elf uses VFP register arguments, /opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/libm.a(lib_a-w_sqrt.o) does not
xxx/arm-none-eabi/bin/ld: failed to merge target specific data of file /opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/libm.a(lib_a-w_sqrt.o)
...
w_sqrt.c:(.text.sqrt+0x3c): undefined reference to `__aeabi_dcmpun'
xxx/arm-none-eabi/bin/ld: w_sqrt.c:(.text.sqrt+0x60): undefined reference to `__aeabi_dcmplt'
xxx/arm-none-eabi/bin/ld: w_sqrt.c:(.text.sqrt+0x98): undefined reference to `__aeabi_ddiv'
xxx/arm-none-eabi/bin/ld: /opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/libm.a(lib_a-e_sqrt.o): in function `__ieee754_sqrt':
...
collect2: error: ld returned 1 exit status
make: *** [makefile:76: base_gen_uP1.elf] Error 1
I assumed the wrong math lib was used so I specified its path like this:
arm-none-eabi-gcc -T"xxx.ld" -L/opt/gcc-arm-none-eabi-10-2020-q4-major/arm-none-eabi/lib/thumb/v7e-m+dp/hard/ -mfpu=fpv5-d16 -mfloat-abi=hard -mthumb -nostdlib -Wl,-Map=xxx.map -o xxx.elf xxx.o -lm -lc
which works (no link error, assembly code is correct, FPU instructions are called).
Then I wanted to try my code without FPU instructions and cuoldn't find the correct compile/link options. I thought the following would be correct
arm-none-eabi-gcc -mcpu=cortex-m7 -std=c99 -mfloat-abi=soft -mthumb
arm-none-eabi-gcc -T"xxx.ld" -mfloat-abi=soft -mthumb -nostdlib -Wl,-Map=xxx.map -o xxx.elf xxx.o -lm -lc
but I got (I tried also with cortex-m7+nofp, same thing)
xxx/arm-none-eabi/bin/ld: /opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/thumb/nofp/libm.a(lib_a-w_sqrt.o): in function `sqrt':
w_sqrt.c:(.text.sqrt+0x22): undefined reference to `__aeabi_dcmpun'
/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld: w_sqrt.c:(.text.sqrt+0x32): undefined reference to `__aeabi_dcmplt'
...
why did I have to manually add the path of the FPU-enabled math library ? I guess gcc should be able to find the right lib according to compilation or link options
what is wrong in my FPU-disabled link command ?
Sorry for the self answer but I just found out for 2) that I forgot to add libgcc (option -lgcc).
Since I'm using -nostdlib I have to manually add libm in the link command (option -lc) but when using no FPU libm requires also libgcc