Integrating GPROF in Embedded(newlib) RISC-V toolchain

Hello Everyone,
I have implemented and tested “gprof” on hifive1 board. The “gmon.out” file was written to the host using semi-hosting and I have analysed it with cross gprof tool. I’m able to get call graph and timing information.

Currently any project/code that requires profiling has to manually include the gprof source files. I’m look for alternative methods to include this functionality instead of adding the source files every time.

Is it possible to integrate ‘gprof’ functionality into newlib cross-compiler ? i.e whenever user compiles code with -pg options, gprof code should be linked to final binary. (User has to implement other low-level functionality on his own but only generic gprof functionality will be added). If it possible, can anyone provide some pointers on how to add this functionality to newlib (riscv-gnu).

Thanks in advance.