In modern linux almost all objects are stripped and splitted in two parts (two files). First is executable itself and second is debug symbols, stripped out from original ELF. Such files are created with
objcopy --only-keep-debug original.elf binary.dbg
mv original.elf binary
objcopy --strip-debug binary
How can I merge binary
and binary.dbg
into ELF file with debugging info? I want to recreate unstripped, original binary. It can be not byte-to-byte equal to the original, but it must to have a debug symbols inside.
PS Yes, I know about gnu.debuglink
section, but it doesn't work for some debuggers (etnus) and disassemblers (objdump can't restore symbols info)
To remove debugging symbols from a binary (which must be an a. out or ELF binary), run strip --strip-debug filename. Wildcards can be used to treat multiple files (use something like strip --strip-debug $LFS/tools/bin/*).
objcopy uses the GNU BFD Library to read and write the object files. It can write the destination object file in a format different from that of the source object file. The exact behavior of objcopy is controlled by command-line options.
The strip command reduces the size of XCOFF object files. The strip command optionally removes the line number information, relocation information, the debug section, the typchk section, the comment section, file headers, and all or part of the symbol table from the XCOFF object files.
For ELF, the elfutils
package contains a tool called eu-unstrip
that does the job. In the context of your example:
eu-unstrip binary binary.dbg
binary.dbg
now has both the binary and debug symbols. I'd include a reference to documentation if I could find any...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With