Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build a debuginfo RPM without source code?

I'm working with a proprietary code base where the owner would like users to get useful stack traces but not be able to view the source code. Generating Debian dbg packages with debug symbols but no source code is straightforward but the Redhat debuginfo RPMs are automatically created with source code.

Is there a way of configuring rpmbuild to build a debuginfo RPM without source code?

If not, what's the best way to remove the source code from a debuginfo package? Does anyone have a script to do it?

like image 893
Guy Lancaster Avatar asked Jan 16 '15 19:01

Guy Lancaster


2 Answers

A -debuginfo package is just a sub-package, and can be created manually without source code. The automatic generation adds the necessary syntax to a spec file, but you can also do this manually, adding a debug info package in the spec file.

Disable automagic generation of *-debuginfo.rpm, run find-debuginfo.sh at the end of %install, and then remove the source files.

Another (and easier/cleaner) means to remove source files overrides this macro

%__debug_install_post   \
   %{_rpmconfigdir}/find-debuginfo.sh %{?_missing_build_ids_terminate_build:--strict-build-id} %{?_find_debuginfo_opts} "%{_builddir}/%{?buildsubdir}"\
%{nil}

in the spec file, replacing %{_rpmconfigdir}/find-debuginfo.sh with a modified/customized find-debuginfo.sh script.

Include the modified script in the spec file like

SourceN: my-find-debuginfo.sh

and then use the macro

%{SOURCEn}

(where N == n, some small appropriate integer) instead of the default to generate debugging symbols without source code.

like image 77
Jeff Johnson Avatar answered Sep 18 '22 00:09

Jeff Johnson


Just finished a round of testing and in the end we inserted the following into the .spec file somewhere above the %description tag:

# Override the macro that invokes find-debuginfo.sh to remove
# the source files before the debuginfo pkg is assembled.
# It would be nice to remove the entire /usr/src tree but
# rpmbuild is running a check-files utility that fails the
# build if /usr/src/debug/%{name} isn't there.  Tried to
# just delete the contents but it's tricky getting an
# asterisk to expand properly so we remove the entire
# directory and then restore an empty one.  Sigh!
%define __debug_install_post   \
   %{_rpmconfigdir}/find-debuginfo.sh %{?_missing_build_ids_terminate_build:--strict-build-id} %{?_find_debuginfo_opts} "%{_builddir}/%{?buildsubdir}";\
   rm -rf "${RPM_BUILD_ROOT}/usr/src/debug/%{name}"; \
   mkdir "${RPM_BUILD_ROOT}/usr/src/debug/%{name}"; \
%{nil}

This works for RHEl 6 and 7 but results in a bash error in RHEl 5 so we avoid building a debuginfo package for the latter by not installing the redhat-rpm-config package.

We decided to avoid creating a modified find-debuginfo.sh script as suggested because there are already differences between different platforms and we preferred a single patch that would work for all targets including future new ones. This isn't perfect but is as close as we came up with.

like image 26
Guy Lancaster Avatar answered Sep 22 '22 00:09

Guy Lancaster