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

Disable global objects destruction #2745

Merged
merged 4 commits into from Sep 22, 2016

Conversation

Projects
None yet
4 participants
@pan-
Member

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%)

pan- added some commits Sep 19, 2016

Disable destruction of global C++ objects when IAR is used.
This behavior is realized by enabling the flag --no_static_destruction
when the compilerin the invoked.
Disable registration of atexit handlers on ARMCC.
This prevent destructors for global C++ objects to be invoked at exit.
By default atexit handlers registration involved dynamic allocation.
Disable registration of __libc_fini_array in the init process.
With this call, destructors are not registered for execution atexit.
Override exit and atexit functions from newlib.
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 from Disable global objects destruction and to Disable global objects destruction Sep 19, 2016

@pan-

This comment has been minimized.

Show comment
Hide comment
@pan-

pan- Sep 19, 2016

Member

@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.

Member

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

This comment has been minimized.

Show comment
Hide comment
@0xc0170

0xc0170 Sep 20, 2016

Member

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?

Member

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-

This comment has been minimized.

Show comment
Hide comment
@pan-

pan- Sep 20, 2016

Member

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.

Member

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

This comment has been minimized.

Show comment
Hide comment
@0xc0170

0xc0170 Sep 20, 2016

Member

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.

Member

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-

This comment has been minimized.

Show comment
Hide comment
@sg-

sg- Sep 20, 2016

Member

/morph test

Member

sg- commented Sep 20, 2016

/morph test

@sg-

This comment has been minimized.

Show comment
Hide comment
@sg-

sg- Sep 20, 2016

Member

@mbed-bot: TEST

HOST_OSES=ALL
BUILD_TOOLCHAINS=ALL
TARGETS=ALL

Member

sg- commented Sep 20, 2016

@mbed-bot: TEST

HOST_OSES=ALL
BUILD_TOOLCHAINS=ALL
TARGETS=ALL

@mbed-bot

This comment has been minimized.

Show comment
Hide comment
@mbed-bot

mbed-bot Sep 20, 2016

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 commented Sep 20, 2016

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

This comment has been minimized.

Show comment
Hide comment
@mbed-bot

mbed-bot Sep 20, 2016

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

mbed-bot commented Sep 20, 2016

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

@0xc0170 0xc0170 added ready for merge and removed needs: CI labels Sep 21, 2016

@sg- sg- merged commit 0c0455b into ARMmbed:master Sep 22, 2016

4 of 5 checks passed

continuous-integration/jenkins/pr-merge This commit is being built
Details
ci/morph-test Job has started
Details
continuous-integration/mbedci Merged build finished. No test results found.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
mbed-os CI Checks Build finished.
Details

@bridadan bridadan referenced this pull request Sep 22, 2016

Merged

New exporter build tests #2754

pan- added a commit to pan-/mbed that referenced this pull request Oct 21, 2016

@pan- pan- deleted the pan-:disable_global_objects_destruction branch Jul 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment