In a bare metal C/C++ project, I use gcc-arm-embedded (currently the most recent 4.9-2015-q2).
For some reasons, I have to avoid using some functions, like some of stdio et cetera (don't want to use retargeting or semihosting).
Further, I use FreeRtos with heap_4.c and had e.g. malloc()
redirected directly to pvPortMalloc()
like this:
void* malloc(size_t s) {
return pvPortMalloc(s);
}
Therefore, I don't want to have any parts of the toolchain's heap management code within my binary.
Now, there are some situations, as were a developer of my team means to use e.g. printf()
which indirectly references _malloc_r()
(and some more) and it's actually quite hard to find out where it's referenced from and so where to fix.
(The use printf()
is just an example here. In my project, I have custom implementation of printf() which prints directly to uart without using stdio. But there are other cases, e.g. type info demangeling, …)
Currently, I have the situation that my project (which consists of about 200 c and c++ source files) compiles well without referencing _malloc_r()
in any way - as long as I build with gcc 4.8.
But when building with gcc 4.9, I see unwanted references to _malloc_r
and some more.
Might there be command line tool to analyze my elf file for finding out where specific functions are referenced from?
Edit 2015-07-20:
- Finally, I'd solved my underlying problem, that I need to build my whole project with gcc 4.9 without having references to
_malloc_r
inside of my code. - Some of the references I'd found by applying this answer.
Further I find out, that there is a
__gnu_cxx::__snprintf_lite()
which references the full blown ofiostream
which I don't want in my code. This__gnu_cxx::__snprintf_lite()
is used by some exceptions of thegcc
stl
implementation (e.g. referenced by__throw_out_of_range_fmt()
). (Yep, my code usesstd::map
). My way to get rid ofiostream
was to simply provide my own__gnu_cxx::__snprintf_lite()
like this (having my own small footprintvsnprintf
):namespace __gnu_cxx { int __snprintf_lite(char* buf, size_t bufsize, const char* fmt, va_list ap) { return vsnprintf(buf, bufsize, fmt, ap); } }
This can be checked by viewing the gcc-4.9 library sources (e.g.
src/gcc/libstdc++-v3/src/c++11/snprintf_lite.cc
).
This is an example for finding out the references to
_exit
in a statically compiled program:Compile it:
Find out the address of
_exit
:Disassemble with
objdump -d -j .text
,grep
for the address of_exit
,cut
the address out of the line and pipe it toaddr2line
:The result is:
Functions
oom
,main
,__run_exit_handlers
, ... do reference the function_exit
.