3.6. ARM Profiling Implementation
Prev | Chapter 3. Sourcery G++ Lite for ARM EABI | Next

## 3.6. ARM Profiling Implementation

Profiling is enabled by means of the `-pg` compiler option. In this mode, the compiler inserts a call to `__gnu_mcount_nc` into every function prologue. However, no implementation of `__gnu_mcount_nc` is provided (to do so would be impossible without knowledge of the execution environment).

You must provide your own implementation of `__gnu_mcount_nc` . Here are the requirements:

- On exit, pop the top value from the stack, and place it in the `lr` register. The `sp` register should be adjusted accordingly. For example, this is how to write it as a stub function:

              .globl __gnu_mcount_nc
              .type __gnu_mcount_nc, %function
      __gnu_mcount_nc:
              mov    ip, lr
              pop    { lr }
              bx     ip

- Preserve all other register state except for `r12` and the CPSR condition code bits. In particular all coprocessor state and registers `r0`-`r3` must be preserved.
- Record and count all occurrences of the function calls in the program. The caller can be determined from the `lr` value stored on the top of the stack (on entry to `__gnu_mcount_nc`), and the callee can be determined from the current value of the `lr` register (i.e. the caller of this function).
- Arrange for the data to be saved to a file named `gmon.out` when the program exits (via `atexit`). Refer to the `gprof` profiler manual for more information.

Prev | Up | Next
3.5. ABI Compatibility | Home | 3.7. Object File Portability