linuxmakefilerpmccppp

How to preserve debug symbols when generating shared library


Is there a possibility to preserve debug symbols when generating a shared object from an object file?

For example, I'm generating my object file with debug symbols using cc using the implicit target and only adding -g to CFLAGS. Then, I generate the shared object (.so) file by defining a custom target where I'm using the -shared option for cc.

My observations so far are:

My assumption is:

If the exact files are needed for examination, take for example how radius.so is generated: http://git.ozlabs.org/?p=ppp.git;a=blob;f=pppd/plugins/radius/Makefile.linux;h=24ed3e580c4db6aeca129dd22dbe6de5f2d1ff5f;hb=HEAD

I need to mention again that I've added -g option to CFLAGS.

Thank you!


Solution

  • The quick-and-dirty answer is to add exit 0 at the end of the %install script which disables various helpers that are appended to the end of the %install build scriptlet when run.

    The more specific answer is to examine the helper scriptlets (which strip shared libraries of debugging symbols) using rpm --showrc on your system and modify what helpers are being run.

    The two most important macros that need to be configured to diable debug symbol stripping are:

    # Define per-arch and per-os defaults. Normally overridden by per-target macros.
    %__arch_install_post    %{nil}
    %__os_install_post      %{___build_post}
    

    Which are usually re-defined in the redhat-rpm-config package.