10

How to build a GCC 4.7 toolchain for cross-compiling? explains how to build a cross-compiling GCC and advises choosing softfp, but I understand that hardfp would be much faster.

Will software compiled for hardfp work on a softfp kernel or is the ABI different?

Alex Chamberlain
  • 15,530
  • 14
  • 67
  • 113

1 Answers1

7

No, software compiled for hardfp will not work on a softfp system, as the calling conventions are different - the soft float conventions involve passing floats through integer registers (though technically, the kernel isn't the real issue - the problem is the linker and all of the standard libraries). This is why the Raspbian project was such a big undertaking, as everything needs to be hardfp from the ground up. However, now that we have an official Raspbian image with full hardfp support, there doesn't seem to be any reason to develop for softfp systems any more. I would suggest changing your toolchain to generate hardfp, using gcc options like:

gcc -O2 -march=armv6 -mfpu=vfp -mfloat-abi=hard

as this should generate code suitable for use with the new Raspbian image. The march flag specifies the processor family, and the mfpu and mfloat flags specify that hard float instructions and calling conventions can and should be used.

As an alternative to the -march flag, you could instead use "-mcpu=arm1176jzf-s", which specifies the actual chip used in the Pi.

Darren Wilkinson
  • 2,912
  • 4
  • 26
  • 27
  • Or use the toolchain that the Foundation provides on GitHub. – Jivings Jul 18 '12 at 10:00
  • @Jivings If you download their gcc, do you still have to specify march etc? – Alex Chamberlain Jul 18 '12 at 10:37
  • @AlexChamberlain I wouldn't think so. – Jivings Jul 18 '12 at 10:38
  • So, is -march=armv6 etc built into every gcc? – Alex Chamberlain Jul 18 '12 at 10:49
  • So, does gcc -march=armv6 exec another binary? How does it work? – Alex Chamberlain Jul 18 '12 at 11:23
  • gcc -march=armv6 -mcpu=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard --version errors out. – Alex Chamberlain Jul 18 '12 at 11:39
  • @AlexChamberlain Yes. Fixed answer. – Darren Wilkinson Jul 18 '12 at 13:00
  • The answer is wrong in its first sentence. Kernel has nothing to do with hardfp/softfp calling convention. It's just a userspace thing related to linker. In fact, there is only one foundations kernel which was used for a long time for both raspbian and official foundation image (which was softfp at that time). – Krzysztof Adamski Aug 20 '12 at 06:40
  • @KrzysztofAdamski you are technically correct. I have made a minor edit to the answer in response. Please feel free to edit further to improve, but please do not give the impression that it is easy to mix and match between hard float and soft float systems, because that is absolutely not the case. – Darren Wilkinson Aug 20 '12 at 10:13
  • @darrenjw: Now it's correct and I can change my vote to +1. Mixing them would require quite complicated multiarch setup which I don't think is supported by any existing distro yet. So sure it's not easy. It's just very often to think that kernel has anything to do with floating point in userspace and I think it's important to note it's not the case. – Krzysztof Adamski Aug 20 '12 at 10:49