-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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 c++ static destructors on exit #26772
Disable c++ static destructors on exit #26772
Conversation
2b292f2
to
92cfcde
Compare
… the destructors on app termination
92cfcde
to
c16b348
Compare
@bzbarsky-apple Can you please help review? |
PR #26772: Size comparison from c24294a to c16b348 Increases (8 builds for bl602, bl702, esp32, nrfconnect, telink)
Decreases (10 builds for bl702, efr32, psoc6, telink)
Full report (57 builds for bl602, bl702, cc32xx, cyw30739, efr32, esp32, k32w, linux, mbed, nrfconnect, psoc6, qpg, telink)
|
Is this safe? Are we expecting constructors to not free resources? |
This patch adds the flag -fno-c++-static-destructors, which disables registration of exit-time destructors of static or thread storage duration variables. I.e the destructors for statically initialized c++ classes are called on exit(). This change is only added to the |
This appears quite safe, approving |
On iOS, tv casting mobile apps have been experiencing unexpected crashes after they were closed by users or the OS itself. The reason was mainly due to the ObjectLifeCycle state of properties within the static instances of SystemLayer, the UDPEndPointManager and TCPEndpointManager not being in the expected state (Uninitialized or Shutdown) upon c++ upon system exit(). This is because in the destructor of the static instances, there's a validation of state which is mismatching causing a crash through the chipDie call. For example, since the following code was not executed when applicationWillTerminate is invoked by the system, the c++ static destructors are invoked upon exit() and hence the internal logic for the ObjectLifeCycle class is hitting an assertion error.
Given that iOS already handle memory clean up upon an app exit, the fix disables the C++ static destructors that is called when application is terminated. This prevents the app from crashing when it's already terminated (after exit() is invoked).