https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110069
Bug ID: 110069 Summary: [Perf] -finstrument-functions causes program size to double Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: chipweinberger at jamcorder dot com Target Milestone: --- Created attachment 55228 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55228&action=edit Assembly comparison with and without finstrument functions Hello, First time issue filer here. First some context: I am using -finstrument-functions to implement a "stack mirror" feature on the ESP32 microcontroller from Espressif. This mirror is logged after detecting stack corruption, and it is incrediblly useful for debugging. Unfortunately, -finstrument-functions causes the program size to double, using 100KB extra of internal SRAM (over 20% of the entire MCUs memory), meaning most people cannot even enable this feature because spare ram is usually very scarce. The main problem is the function signature of __cyg_profile_func_enter. ~35 bytes of instructions are needed to set up the 2 function arguments, and these 35 bytes need to be inserted into *every* function. This is a major cost for both performance and memory. void __cyg_profile_func_enter(void *func, void *callsite) These arguments are not needed by us. We can traverse the stack ourself. I am hoping we can consider a new flag, -function-entry-exit-hooks, with a much simpler function signature: void __func_hook_entry(void) void __func_hook_exit(void) Without the arguments, each function only needs a simple 'call' instruction. This would be incredibly useful for us, and I imagine a lot of other people as well. Thanks, Chip