Why does rpmbuild rewrite elf headers and how do I stop it?

75 Views Asked by At

I have a stripped down spec file that looks like:

Name: some-binary
Version: 6.1.0
Release: 1
License: proprietary
Summary: a binary

%description
Whatever

%install
install -d %{buildroot}/fromrpm
cp %{_sourcedir}/thebinary %{buildroot}//fromrpm/thebinary

%files 
/fromrpm/thebinary

Then I run:

$ cd ~/rpmbuild/

$ rpmbuild -bb SPECS/some-binary.spec 2>/dev/null 
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.gxRpSj
Processing files: some-binary-6.1.0-1.x86_64
Provides: some-binary = 6.1.0-1 some-binary(x86-64) = 6.1.0-1
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Checking for unpackaged file(s): /usr/lib/rpm/check-files /home/dspeyer/rpmbuild/BUILDROOT/some-binary-6.1.0-1.x86_64
Wrote: /home/dspeyer/rpmbuild/RPMS/x86_64/some-binary-6.1.0-1.x86_64.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.WR3Utx

$ rpm2cpio RPMS/x86_64/some-binary-6.1.0-1.x86_64.rpm | cpio -idmv
./fromrpm/thebinary
41456 blocks

$ readelf -a SOURCES/thebinary | grep rela\\.
  [ 5] .rela.plt         RELA             0000000000400338  00000338
   00     .note.gnu.property .note.gnu.build-id .note.ABI-tag .note.go.buildid .rela.plt 
Relocation section '.rela.plt' at offset 0x338 contains 29 entries:

$ readelf -a fromrpm/thebinary | grep rela\\.
  [ 6] .rela.got.plt     RELA             0000000000000000  0143d048
Relocation section '.rela.got.plt' at offset 0x143d048 contains 29 entries:

I'm not actually sure what the rela tags do, but I strongly suspect they're the reason the post-rpm binary when run on rhel 7.9 immediately crashes trying to crash with "Unexpected reloc type in static binary". Yes, the binary is statically linked. (And, yes, I did say "crashes trying to crash": sigsegv inside __libc_fatal)

Any ideas what rpmbuild is trying to do, or how to stop it?

1

There are 1 best solutions below

0
dspeyer On

By default, rpmbuild strips debugging symbols from the main binary, while putting them in a separate -devel package. Unfortunately, this also strips rela headers, resulting in crashes when the binary tries to run and can't reloc correctly.

If you're using rpmbuild directly, you can avoid this by adding the following to your spec:

%global _enable_debug_package 0
%global debug_package %{nil}
%global __os_install_post /usr/lib/rpm/brp-compress %{nil}