Random memory leak in binutils?
Nick Clifton
nickc@redhat.com
Fri Feb 26 14:37:17 GMT 2021
Hi Nile,
> But something strange happened that I have just finished proving is related to the GCC profiler: without the argument (`-pg') I get 22 allocs and 22 frees, but with the argument I tend to get 23 allocs and 22 frees with a fallout of a little more than 16KB as shown in the report below:
This is really more of a question for the gcc folks, rather than the
binutils, since -pg is a compiler option, not a linker option.
Nevertheless I will attempt to provide an answer for you.
The thing is, the -pg option adds extra code to your compiled program
and involves linking in different versions of the C runtime startup code
(crt1.o vs gcrt1.o). You can see this for yourself if you compile with
the -v option added to the command line and compare the output when add
or remove the -pg option.
So it is almost certain that the memory leak is coming from this alternate
startup file. Given what the -pg option does I would guess that the
startup code allocates memory to contain the profiling information that
is generated as the code runs.
Cheers
Nick
PS. As an aside I would suggest that worrying about memory leaks is only
important if your program is intended to run for a long time. And worrying
about memory leaks when trying to profile the program is just not worth it.
More information about the Binutils
mailing list