stripbinutilsobjdumpobjcopy

How to reverse the objcopy's strip with only-keep-debug?


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)


Solution

  • 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...