public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/110069] New: [Perf] -finstrument-functions causes program size to double
@ 2023-06-01  4:45 chipweinberger at jamcorder dot com
  2023-06-01  4:55 ` [Bug middle-end/110069] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: chipweinberger at jamcorder dot com @ 2023-06-01  4:45 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug middle-end/110069] [Perf] -finstrument-functions causes program size to double
  2023-06-01  4:45 [Bug c/110069] New: [Perf] -finstrument-functions causes program size to double chipweinberger at jamcorder dot com
@ 2023-06-01  4:55 ` pinskia at gcc dot gnu.org
  2023-06-01  4:57 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-01  4:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110069

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
In your backend you could implement all of this I think. 

Are you talking about -O0 code generation or -O2?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug middle-end/110069] [Perf] -finstrument-functions causes program size to double
  2023-06-01  4:45 [Bug c/110069] New: [Perf] -finstrument-functions causes program size to double chipweinberger at jamcorder dot com
  2023-06-01  4:55 ` [Bug middle-end/110069] " pinskia at gcc dot gnu.org
@ 2023-06-01  4:57 ` pinskia at gcc dot gnu.org
  2023-06-01  5:08 ` chipweinberger at jamcorder dot com
  2023-06-01 11:36 ` amonakov at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-01  4:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110069

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug middle-end/110069] [Perf] -finstrument-functions causes program size to double
  2023-06-01  4:45 [Bug c/110069] New: [Perf] -finstrument-functions causes program size to double chipweinberger at jamcorder dot com
  2023-06-01  4:55 ` [Bug middle-end/110069] " pinskia at gcc dot gnu.org
  2023-06-01  4:57 ` pinskia at gcc dot gnu.org
@ 2023-06-01  5:08 ` chipweinberger at jamcorder dot com
  2023-06-01 11:36 ` amonakov at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: chipweinberger at jamcorder dot com @ 2023-06-01  5:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110069

--- Comment #2 from Chip Weinberger <chipweinberger at jamcorder dot com> ---
The 35 bytes figure is from -O0. This is a debug feature.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug middle-end/110069] [Perf] -finstrument-functions causes program size to double
  2023-06-01  4:45 [Bug c/110069] New: [Perf] -finstrument-functions causes program size to double chipweinberger at jamcorder dot com
                   ` (2 preceding siblings ...)
  2023-06-01  5:08 ` chipweinberger at jamcorder dot com
@ 2023-06-01 11:36 ` amonakov at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: amonakov at gcc dot gnu.org @ 2023-06-01 11:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110069

Alexander Monakov <amonakov at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |amonakov at gcc dot gnu.org

--- Comment #3 from Alexander Monakov <amonakov at gcc dot gnu.org> ---
For such space-constrained environments I'd suggest using '-pg' instead. It
emits just one call to the _mcount function on entry without overhead. If you
need to hook the exit, you can replace the return address in your
implementation of _mcount (this function usually has a non-standard ABI, so
it's always necessary to implement it in assembly).

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-06-01 11:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-01  4:45 [Bug c/110069] New: [Perf] -finstrument-functions causes program size to double chipweinberger at jamcorder dot com
2023-06-01  4:55 ` [Bug middle-end/110069] " pinskia at gcc dot gnu.org
2023-06-01  4:57 ` pinskia at gcc dot gnu.org
2023-06-01  5:08 ` chipweinberger at jamcorder dot com
2023-06-01 11:36 ` amonakov at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).