How to strip debug symbols from the built binaries to separate files?

12 views
Skip to first unread message

Konstantin Erman

unread,
May 1, 2020, 8:36:44 PM5/1/20
to bazel-discuss
We need to extract debug symbols from the C++ build produced binaries (shared libraries and executables) and store them to the separate files. On Linux it would be something like

# Copy the debug symbols from the .so file to a .debug file
objcopy --only-keep-debug libfoo.so libfoo.debug
# Remove the debug symbols from the .so
objcopy --strip-debug libfoo.so
# Add the gdb header to associate the .debug file with the .so
objcopy --add-gnu-debuglink=libfoo.debug libfoo.so

On Windows we get PDBs generated just fine, now we need the same for Mac and Linux.
This operation is so typical that I was hoping to find it as a standard part of C++ toolchain but to my surprise Bazel options --strip and --stripopt seems to only control removal of the symbols from binaries, but not the extraction of symbols to separate symbol files.

I probably can write a custom rule for that but I still hope there is built-in or at least commonly accepted solution already.

Thank you!
Konstantin
Reply all
Reply to author
Forward
0 new messages