Search code examples
c++elfmap-files

What is section ".debug_info" in an elf file?


I have an elf file, while analysing the mapfile and elf using elfparser, I saw a section called .Debug_info, which is taking largest memory.

I am compiling for xtensa DSP, using xt-xc++, I haven't used -g option also given -o2 optimization level.

enter image description here

is it possible to remove this for release builds?


Solution

  • section called .debug_info, which is taking largest memory.

    Note that this section does not have SHF_ALLOC flag, and therefore does not take any RAM at runtime (it only takes space in the filesystem). Of course if you use ramdisk, then that section still does cost you RAM in the end.

    is it possible to remove this for release builds?

    Yes: none of the .debug* sections are necessary at runtime, and all of them can be safely stripped.

    -g0 and -s option didn't work.

    It's likely that you are getting .debug_* sections from libraries that you are linking in, and not from your own code. The -g was present when the libraries were compiled, so building with -g0 doesn't have any effect.

    It's surprising that -s didn't work, but maybe your compiler interprets this flag differently.

    In any case, you should use strip --strip-debug to get rid of .debug_* sections (note: this does not remove the symbol table).

    The best practice is actually to compile all your code with full debug info (-g), save the full debug binary for post-mortem analysis, use strip --strip-debug to make a release binary, and use that binary for actual distribution.

    If/when the release binary crashes and leaves a core dump, having (saved) full-debug exactly matching binary greatly improves post-mortem analysis you can do.