Search code examples
gccdebug-symbolsobjdumpdwarfobjcopy

Display source code with disassembly when path has changed


We have some static libraries for a know arch (e.g. powerpc) in which we need to display source code with disassembly to perform some asm review activities.

However, the binaries were cross-compiled in different locations and even in some cases different OSes (Linux and Windows), e.g. C:/path-to-mylib/common/src and others others /home/user-name/path-to-mylib/common/src, and so, objdump -S mylib.a isn't able to find the source. An option that we have is to replicate the path

I could replicate the compilation path and place the source there. However, I find that method a bit dirty and I guess that won't work from cross platform (between Linux and Windows).

Is there away to tell objdump -S where is the source path located or modify the path with objcopy?

Some important assumptions:

  • The source code used to produce that exact library is available
  • The toolchain for the cross-compilation is GNU compiler and is cross platform (works both in linux and Windows)
  • The version of the GNU binutils (GCC, objdump, objcopy, etc) is 4.3.3.
  • I am working in linux.
  • The object binaries were compiled with debug symbols and information. E.g. -O0 -g
  • (I don't think this really matters but) I can work with the object binaries extracted from the archive mylib.a
  • Re-generating the binaries is not the solution I am searching for.

Let me know if you need more information, thanks.


Solution

  • As ssbssa user said, there is an undocumented --include= option (also as -I) in objdump. With this option, you have to place all source code files into a folder and then call objdump the path to the source code:

    objdump -I path-to-mylib/common/src -S mylib.a
    

    Nevertheless, in this other page they suggest an alternative solution to the problem. By using options --prefix=”.” --prefix-strip=3 we can replace the prefix of the path when calling objdump. E.g.

    objdump -S --prefix=”./myfolder” --prefix-strip=3 mylib.a
    

    This will allow objdump to search the src as ./myfolder/driver/common/src, instead of the original /home/user/source/driver/common/src. However, I didn't manage to make it work with different OSes (E.g compiled in Windows, asm+src dump in Linux),