Skip to content

Conversation

@kjbracey
Copy link
Contributor

Description

Static destruction code may still end up in a GCC image despite our efforts. Use of SingletonPtr will eliminate most, but references can still occur.

For IAR and ARM toolchains they can be totally eliminated in the compiler (see #11726 for ARM). As the Clang attributes have been submitted for C++ standardisation (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1247r0.html), it seems likely that one day GCC will also support this, so it seems not worthwhile to create a NotDestroyed<T> template wrapper as a workaround, as I was originally intending.

In the meantime, GCC is inserting calls to __eabi_atexit. That is stubbed out, so whatever it attempts to register will not be called. We can't stop it putting the calls in, but we can transparently slightly
reduce code size by telling it to use atexit instead. It needs to pass fewer parameters for us to ignore, so the callsites become a little smaller.

Pull request type

[ ] Fix
[X] Refactor
[ ] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

Reviewers

@pan-, @bulislaw, @0xc0170

Static destruction code may still end up in a GCC image despite our
efforts. Use of `SingletonPtr` will eliminate most, but references
can still occur.

For IAR and ARM toolchains they can be totally eliminated in the
compiler (see ARMmbed#11726 for ARM). As the Clang attributes have been
submitted for C++ standardisation
(http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1247r0.html),
it seems likely that one day GCC will also support this, so it seems not
worthwhile to create a `NotDestroyed<T>` template wrapper as a
workaround, as I was originally intending.

In the meantime, GCC is inserting calls to `__eabi_atexit`. That is
stubbed out, so whatever it attempts to register will not be called. We
can't stop it putting the calls in, but we can transparently slightly
reduce code size by telling it to use `atexit` instead. It needs to pass
fewer parameters for us to ignore, so the callsites become a little
smaller.
@ciarmcom
Copy link
Member

@kjbracey-arm, thank you for your changes.
@bulislaw @0xc0170 @pan- @ARMmbed/mbed-os-tools @ARMmbed/mbed-os-maintainers please review.

@ciarmcom ciarmcom requested a review from a team October 22, 2019 13:00
@0xc0170
Copy link
Contributor

0xc0170 commented Oct 22, 2019

If we test this flag with some examples, how much size difference does it make?

@kjbracey
Copy link
Contributor Author

Just tried it with a large (cloud client) image rather than my small synthetic examples, and found it made that bigger :)

There's obviously a secondary effect here - maybe something to do with failure to exclude the ".fini" array. Will dig into it.

Even if this does work properly, saving is going to be pretty minor, compared to #11726.

@kjbracey
Copy link
Contributor Author

Okay, can't pin down a particular reason for the increases here. If it's not a straightforward (small) win, I'll skip it - not worth spending time on.

@kjbracey kjbracey closed this Oct 23, 2019
@kjbracey kjbracey deleted the gcc_use_atexit branch October 23, 2019 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants