2

I need to link my firmware (running on STM32L4x6, built with arm-none-eabi_gcc) with two third party libraries (I don't have the source code of these libs).

One lib is compiled using hard float abi, and the other is not using float at all and linked probably with soft float abi.

I know both abis are not compatible and I fully understand the difference between them, but what if a library does not use float operation at all ? What is preventing to link it with some other code using whatever abi ?

From what I've googled it is not possible to force the linker in such a situation, however is it possible to "convert" a library (.a from gcc) from one float abi to another ?

Guillaume Petitjean
  • 2,408
  • 1
  • 21
  • 47
  • been a long time since I have dealt with this (gcc 3.x.x days) but there was also the issue of thumb vs arm, hard vs soft, combinations, and first you had to get all of them built then you had to link in the right one. I think it is possible to do both, build all and link the right one. I dont remember the mechanism off hand, and a lot more cores have come out and many of those now have an FPU where in the ARM7 days few did. So this has to have been solved, how you get there though. – old_timer Jul 18 '18 at 15:08
  • the soft functions are functions that the compiler generates, where hard float they generate instructions, so i fyou link in a library of functions against hard float software you just have extra baggage, the other way around and you will get linker errors. – old_timer Jul 18 '18 at 15:09
  • @old_timer - you probably mean multilib option - the compiler can choose the correct standard library depending on the compile options. But I afraid this mechanism is useless here. – 0___________ Jul 18 '18 at 15:31
  • Yes that is the term multilib...Not sure why you cant get the linker to find the right library it doesnt know where any library is you have to tell it, including gcclib (if you call the linker through gcc you get what gcc gives, but you call it directly you have to specify the one you want as the linker does not have a default path). If you can get it to build the library you can point the linker at the right one. – old_timer Jul 18 '18 at 17:18
  • Unless this question is about mixing objects, you have to go one way or the other with the whole project and it is understandable to ask, but why for this object that doesnt use said instruction set or feature. This toolchain marks each object and the linker wants matching objects because at that layer it doesnt know what you did or didnt put inside, and yes arguably it could not care and just complain when an extern is not resolved. Not how they chose to do it. – old_timer Jul 18 '18 at 17:22
  • My question is not really about mixing different abis (since it looks impossible) but more to convert a library (which you don't have source code of) from one abi to another one. Theoretically it is probably possible but I don't know it it is possible in real life – Guillaume Petitjean Jul 19 '18 at 17:42

2 Answers2

2

You can force the linker to accept objects with mismatched ABIs with

--noinhibit-exec

or (if it's called through the gcc wrapper)

-Wl,--noinhibit-exec

You'll get a few error messages, but it still produces a reasonable looking binary.

Alternatively, you can remove the attributes containing the ABI information from an object file with

arm-none-eabi-objcopy --remove-section=.ARM.attributes input.o output.o

and the linker will happily link it with anything afterwards.

If it's not a single object file (.o) but a library (.a), then you'll probably have to extract the objects from the library with arm-none-eabi-ar and reassemble it afterwards.

  • Interesting. I guess it may be dangerous because other errors might go unnoticed but at least it fixes my issue, until one of the lib developpers recompile it with the right float abi. – Guillaume Petitjean Jul 20 '18 at 15:35
  • While this is a risky solution, it can be a handy workaround in many cases when the vfp registers are not used. – hesham_EE Feb 18 '19 at 16:28
0

The only way I can think off it is another C wrapper where you define functions which will be linked against the soft and hard floats. It is the workaround of course but you need to show the compiler how to pass the parameters to the functions.

0___________
  • 60,014
  • 4
  • 34
  • 74