How to build a debuginfo RPM without source code?
Asked Answered
P

4

8

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?

Pore answered 16/1, 2015 at 19:4 Comment(2)
Does this happen even if you set the nosource tag in the spec file?Lavation
Yes, it does happen even with the nosource tag. It seems that nosource only applies to the source RPMs, not debuginfo. I studied the /usr/lib/rpm/find-debuginfo.sh script and it seems to determine what sources to include directly from the generated .so file. But thanks for the suggestion - I hadn't thought of trying it.Pore
D
5

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.

Doze answered 17/1, 2015 at 17:3 Comment(0)
S
5

Adding this line in the .spec file worked for me:

%define _debugsource_template %{nil}

I come across the "magic" line in this thread.

The regular rpm along with the debuginfo one is generated but no src package is generated.

This actually solved a build break in my case. I was unable to build because rpmbuild was failing with the following error:

Empty %files file /my/path/BUILD/program-1.0.0/debugsourcefiles.list
Steersman answered 6/3, 2023 at 15:59 Comment(2)
This answer deserves to be the top voted here, spent hours only to find such a simple solution, thanksSatiety
... The task was to re-package already existing libraries without the corresponding lib source code, but still making available the debuginfo of the libs in extra debuginfo rpms. Had an error ""Empty %files file ..../debugsourcefiles.list" otherwise.Bacchant
P
3

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.

Pore answered 27/1, 2015 at 18:37 Comment(0)
H
2

CentOS 7 needed a slight modification of Guy's solution. Here's what I'm using successfully:

# Remove source code from debuginfo package.
%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"; \
  mkdir -p "${RPM_BUILD_ROOT}/usr/src/debug/%{name}-%{version}"; \
%{nil}

The following can be used to verify the source code is no longer contained within the RPM:

rpm -qpl xxx-debuginfo-1.0.0-1.el7.x86_64.rpm
Headwards answered 25/4, 2015 at 4:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.