Skip to content

Commit 2f1eedd

Browse files
committed
Disable C++ static denstructors in ARMC6 compiler
We disable C++ static destructors as best as possible in the various toolchains, trying to eliminate unwanted destructor code. We don't want to waste RAM or ROM on the C++-standard-specified behaviour of running all statically-constructed objects' destructors in reverse order on exit; we're never going to perform an orderly exit. Techniques used include: * `SingletonPtr` - makes an object be "lazily constructed" on first use, and also eliminates its destructor. Lazy construction adds ROM+RAM overhead. * `__eabi_atexit` is stubbed out, preventing RAM usage by run-time registration of static destructors. * GCC has `exit` wrapped to kill shutdown code * IAR has static destructors disabled in the compiler flags Killing static destructors in the compiler is the optimum; if we only stub out `__eabi_atexit`, the compiler is still inserting calls to it, and referencing the destructors in those call. Clang 8 added the compiler option `-fno-c++-static-destructors` (and the object attributes `[[clang::no_destroy]]` and `[[clang::always_destroy]]` for fine control). We can hence enable that option in ARMC6 tool profiles, matching IAR. This option appears to exist in ARM Compiler 6.11, but generates an apparently spurious linker error about `EthernetInterface`. It works in ARM Compiler 6.13, so this PR needs to wait until the compiler is updated.
1 parent 1dac871 commit 2f1eedd

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

tools/profiles/debug.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"-DMBED_TRAP_ERRORS_ENABLED=1"],
2626
"asm": [],
2727
"c": ["-D__ASSERT_MSG", "-std=gnu11"],
28-
"cxx": ["-fno-rtti", "-std=gnu++14"],
28+
"cxx": ["-fno-rtti", "-fno-c++-static-destructors", "-std=gnu++14"],
2929
"ld": ["--verbose", "--remove", "--show_full_path", "--legacyalign",
3030
"--any_contingency", "--keep=os_cb_sections"]
3131
},

tools/profiles/develop.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"-fshort-enums", "-fshort-wchar", "-DMBED_TRAP_ERRORS_ENABLED=1"],
2424
"asm": [],
2525
"c": ["-D__ASSERT_MSG", "-std=gnu11"],
26-
"cxx": ["-fno-rtti", "-std=gnu++14"],
26+
"cxx": ["-fno-rtti", "-fno-c++-static-destructors", "-std=gnu++14"],
2727
"ld": ["--show_full_path", "--legacyalign", "--any_contingency",
2828
"--keep=os_cb_sections"]
2929
},

tools/profiles/release.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"-fshort-enums", "-fshort-wchar", "-DNDEBUG"],
2424
"asm": [],
2525
"c": ["-D__ASSERT_MSG", "-std=gnu11"],
26-
"cxx": ["-fno-rtti", "-std=gnu++14"],
26+
"cxx": ["-fno-rtti", "-fno-c++-static-destructors", "-std=gnu++14"],
2727
"ld": ["--show_full_path", "--legacyalign", "--any_contingency",
2828
"--keep=os_cb_sections"]
2929
},

0 commit comments

Comments
 (0)