ARMmbed / mbed-os-example-mbed-crypto

Mbed Crypto example for Mbed OS 5
Apache License 2.0
5 stars 19 forks source link

Include "mbed.h" to enable GCC_ARM build with "-flto" #55

Closed fkjagodzinski closed 4 years ago

fkjagodzinski commented 4 years ago

Add the "mbed.h" header to use the MBED_USED attribute with main().

Since the "used" attribute and the definition of main() have to be in the same translation unit, I placed a declaration of main() in "platform/mbed_toolchain.h" which "mbed.h" includes.

Without the attribute, the main() symbol is not emitted with the GCC toolchain using "-Wl,--wrap,main" and "-flto" flags.

This patch is required by https://github.com/ARMmbed/mbed-os/pull/11856.

Patater commented 4 years ago
  1. Could you please explain more (in the commit message) why including mbed.h is needed?

  2. What other ways are there to let GCC know that main() is used and shouldn't be linked out?

  3. What exactly is it about including the mbed.h header file that causes -flto to not remove the main() function?

  4. "Fix a missing header" <-- I believe this is not correct. If we don't use anything from mbed.h, why would it be considered "missing" if we don't have it?

fkjagodzinski commented 4 years ago

Updated the commit message and PR description.

fkjagodzinski commented 4 years ago

Fortunately, there is a better solution to undefined reference to 'main' problem! Please see: https://github.com/ARMmbed/mbed-os/pull/11856#issuecomment-559097300