23

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)

osgx
  • 80,853
  • 42
  • 303
  • 470

1 Answers1

12

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

lyngvi
  • 1,222
  • 12
  • 19
  • There is the doc: http://www.linuxfromscratch.org/blfs/view/svn/general/elfutils.html "*`eu-unstrip` combine stripped files with separate symbols and debug information.*" and this is homepage https://fedorahosted.org/elfutils/ and this is source https://git.fedorahosted.org/cgit/elfutils.git/tree/src/unstrip.c "Combine stripped files with separate symbols and debug information. Copyright (C) 2007-2012, 2014, 2015 Red Hat, Inc...Roland McGrath". If I have "program.bin" as normal stripped ELF, and "program.dbg" with only debug info, how should I start `eu-unstrip` and which file will be changed? – osgx Jul 29 '16 at 06:03
  • 4
    Based on my usage, it merges the binary into the debug symbols. If you have program.dbg and program.bin, then `eu-unstrip program.bin program.dbg` merges the bin into the dbg file. Getting the params reversed yields errors. – lyngvi Jul 29 '16 at 11:36
  • I dont have access to elfutils but only binutils. Is it possible to do it using objcopy --add-section or similar ? – sunil Jun 29 '17 at 08:55