sqrtf is linking the wrong libm.a library

Asked by David Osborne

Hi,

Using the windows compiler gcc-arm-none-eabi-4_7-2013q3-20130916-win32

I'm compiling with these options:
-mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -mthumb

and linking with these options:
-mcpu=cortex-m4 -mthumb

I made those selections based on what is in the readme.txt which lists the architecture options.

From the map file I can see it has linked:

/arm-none-eabi/lib/armv7e-m\libm.a(lib_a-wf_sqrt.o)

When I run the code the function call to sqrtf() gets the wrong result:
x = sqrtf(y)
The function returns y unchanged and assigns it to x.

I expect the linker should have used the /fpu/libm.a library (not the no-floating point one). However, I can not get it to use the fpu directory. Note, the diss-assembly shows it using hardware fp instructions.

When I change the float-abi option to -mfloat-abi=softfp the sqrtf works and gives the right result. However, the map file shows the linker is still using the base ./libm.a and not the /softfp/libm.a

Hope you can help

David.

Question information

Language:
English Edit question
Status:
Solved
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Solved by:
Terry Guo
Solved:
Last query:
Last reply:
Revision history for this message
Best Terry Guo (terry.guo) said :
#1

Hi David,

The link option should be same with the compile options, especially those "-mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mthumb". And please use arm-none-eabi-gcc as your linker.

Revision history for this message
David Osborne (david-oz) said :
#2

Hi Terry,

That fixed the problem. It now links with the fpu/libm.a library. Seems obvious to me now.

Cheers,
David.

Revision history for this message
David Osborne (david-oz) said :
#3

Thanks Terry Guo, that solved my question.