Slightly optimise GCC static destruction #11727
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 slightlyreduce 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
Reviewers
@pan-, @bulislaw, @0xc0170