Skip to content

Disable global objects destruction #2745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 22, 2016

Conversation

pan-
Copy link
Member

@pan- pan- commented Sep 19, 2016

Description

This pull request disable the destruction of global objects when exit is called.
A different method is applied for each compiler:

  • IAR: use the compilation flag --no_static_destruction.
  • ARMCC: override __aeabi_atexit, __cxa_atexit and __cxa_finalize. The methodology is explained here.
  • GCC: For GCC it is a bit more complicated, depending on how it is compiled, it is possible or not to override the itanium abi calls. To ensure that the correct behavior is used, exit has been overridden to directly call _exit instead of calling in reverse order every function registered by atexit. In the meantime, atexit has been overridden to be a stub which does nothing.

Related PRs

This PR is a follow up of #2715 #2741

Gain:

The test have been conducted upon mbed-os-example-blinky compiled with NDEBUG enabled.

  • Without the patch:
GCC ARMCC IAR
RAM 11832 10152 7970
ROM 37008 26868 21266
GCC ARMCC IAR
RAM 9236 bytes 8020 bytes 7350 bytes
ROM 11480 bytes 12686 bytes 12398 bytes
  • Difference:
GCC ARMCC IAR
RAM -2596 bytes (-21.94%) -2132 bytes (-21%) -620 bytes (7.8%)
ROM -25528 bytes (-68.97%) -14686 bytes (-52.8%) -8868 bytes (-41.7%)

This behavior is realized by enabling the flag --no_static_destruction
when the compilerin the invoked.
This prevent destructors for global C++ objects to be invoked at exit.
By default atexit handlers registration involved dynamic allocation.
With this call, destructors are not registered for execution atexit.
This change simplify the exit and initialization process.
It also reduce the number of hidden memory allocation made by atexit.
@pan- pan- changed the title Disable global objects destruction and Disable global objects destruction Sep 19, 2016
@pan-
Copy link
Member Author

pan- commented Sep 19, 2016

@c1728p9 @geky @sg- @0xc0170 Could you review this PR ?

I wonder if completely shutting down atexit is reasonable for GCC or should I re-implement it with the basic requirements implied by the C standard (32 entries) ?

If so, what is the use case ? We're never supposed to exit our applications.

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 20, 2016

I wonder if completely shutting down atexit is reasonable for GCC or should I re-implement it with the basic requirements implied by the C standard (32 entries) ?

Can you elaborate? how does this differ from the rest toolchains?

@pan-
Copy link
Member Author

pan- commented Sep 20, 2016

This PR shutdown completely atexit on GCC while on other toolchains it shutdowns __aeabi_atexit .

On ARMCC, the result is identical to shutting down atexit while on IAR it depends if the application is compiled with aeabi compatibility enabled. Also, on IAR, the atexit behavior is already non compliant with the C library, it only stores 10 entries instead of the 32 from the C standard.

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 20, 2016

This PR shutdown completely atexit on GCC while on other toolchains it shutdowns __aeabi_atexit .

Good to know, I would have assumed all of them would do __eabi_atexit.

Also, on IAR, the atexit behavior is already non compliant with the C library, it only stores 10 entries instead of the 32 from the C standard.

Memory savings? 😄 We can ask IAR.

Looks good to me the way it is.

@sg-
Copy link
Contributor

sg- commented Sep 20, 2016

/morph test

@sg-
Copy link
Contributor

sg- commented Sep 20, 2016

@mbed-bot: TEST

HOST_OSES=ALL
BUILD_TOOLCHAINS=ALL
TARGETS=ALL

@mbed-bot
Copy link

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 906

All builds and test passed!

@mbed-bot
Copy link

[Build 952]
SUCCESS: Building succeeded and tests were run! Be sure to check the test results

@sg- sg- merged commit 0c0455b into ARMmbed:master Sep 22, 2016
pan- added a commit to pan-/mbed that referenced this pull request Oct 21, 2016
@pan- pan- deleted the disable_global_objects_destruction branch July 3, 2018 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants