brp: Add brp-strip-lto script

Strip LTO sections and symbols from objects and archives (static
libraries). %brp_strip_none macro is respected.

Reviewed-by: Dmitry V. Levin <ldv@altlinux.org>
This commit is contained in:
Виталий Чикунов 2021-07-28 05:09:31 +03:00
parent 8851274e51
commit 715065e999
6 changed files with 89 additions and 3 deletions

1
.gitignore vendored
View File

@ -60,6 +60,7 @@ Makefile.in
/scripts/brp-compress /scripts/brp-compress
/scripts/brp-fix-perms /scripts/brp-fix-perms
/scripts/brp-fixup /scripts/brp-fixup
/scripts/brp-strip-lto
/scripts/brp-verify-info /scripts/brp-verify-info
/scripts/brp-verify_elf /scripts/brp-verify_elf
/scripts/compress_files /scripts/compress_files

View File

@ -942,6 +942,7 @@ AC_OUTPUT([ Doxyfile Makefile rpmrc macros platform rpmpopt
scripts/brp-sign-kmodules scripts/brp-sign-kmodules
scripts/brp-fix-perms scripts/brp-fix-perms
scripts/brp-fixup scripts/brp-fixup
scripts/brp-strip-lto
scripts/brp-verify_elf scripts/brp-verify_elf
scripts/brp-verify-info scripts/brp-verify-info
scripts/compress_files scripts/compress_files
@ -954,6 +955,7 @@ AC_OUTPUT([ Doxyfile Makefile rpmrc macros platform rpmpopt
scripts/find-package scripts/find-package
scripts/find-debuginfo-files scripts/find-debuginfo-files
scripts/process-debuginfo scripts/process-debuginfo
scripts/process-lto
scripts/find-scriptlet-requires scripts/find-scriptlet-requires
scripts/fixup-binconfig scripts/fixup-binconfig
scripts/fixup-libraries scripts/fixup-libraries

View File

@ -361,6 +361,7 @@ mv -T %buildroot%_rpmlibdir/{,build}macros
%rpmattr %_rpmlibdir/find-requires %rpmattr %_rpmlibdir/find-requires
%rpmattr %_rpmlibdir/find-debuginfo-files %rpmattr %_rpmlibdir/find-debuginfo-files
%rpmattr %_rpmlibdir/process-debuginfo %rpmattr %_rpmlibdir/process-debuginfo
%rpmattr %_rpmlibdir/process-lto
%rpmattr %_rpmlibdir/find-scriptlet-requires %rpmattr %_rpmlibdir/find-scriptlet-requires
%rpmattr %_rpmlibdir/fixup-* %rpmattr %_rpmlibdir/fixup-*
%rpmattr %_rpmlibdir/files.* %rpmattr %_rpmlibdir/files.*

View File

@ -6,11 +6,11 @@ EXTRA_DIST = \
posttrans-filetriggers 0ldconfig.filetrigger \ posttrans-filetriggers 0ldconfig.filetrigger \
debuginfo.req debuginfo.req.files debuginfo.prov debuginfo.prov.files \ debuginfo.req debuginfo.req.files debuginfo.prov debuginfo.prov.files \
functions find-package .provides.sh \ functions find-package .provides.sh \
find-debuginfo-files process-debuginfo \ find-debuginfo-files process-debuginfo process-lto \
find-scriptlet-requires brp-sign-kmodules \ find-scriptlet-requires brp-sign-kmodules \
brp-adjust_libraries brp-alt \ brp-adjust_libraries brp-alt \
brp-check_contents brp-cleanup brp-compress brp-debuginfo \ brp-check_contents brp-cleanup brp-compress brp-debuginfo \
brp-fix-perms brp-fixup \ brp-fix-perms brp-fixup brp-strip-lto \
brp-verify_elf brp-verify-info \ brp-verify_elf brp-verify-info \
compress_files \ compress_files \
cpp.req cpp.req.files \ cpp.req cpp.req.files \
@ -44,7 +44,7 @@ libexecdir = ${prefix}/libexec
config_DATA = 0common-files.req.list # .provides.sh config_DATA = 0common-files.req.list # .provides.sh
config_SCRIPTS = \ config_SCRIPTS = \
debuginfo.req debuginfo.req.files debuginfo.prov debuginfo.prov.files \ debuginfo.req debuginfo.req.files debuginfo.prov debuginfo.prov.files \
find-debuginfo-files process-debuginfo \ find-debuginfo-files process-debuginfo process-lto \
find-scriptlet-requires \ find-scriptlet-requires \
brp-alt \ brp-alt \
compress_files \ compress_files \
@ -82,7 +82,9 @@ install-data-local:
$(INSTALL) -m755 brp-adjust_libraries $(DESTDIR)$(configdir)/brp.d/048-adjust_libraries.brp $(INSTALL) -m755 brp-adjust_libraries $(DESTDIR)$(configdir)/brp.d/048-adjust_libraries.brp
$(INSTALL) -m755 brp-debuginfo $(DESTDIR)$(configdir)/brp.d/056-debuginfo.brp $(INSTALL) -m755 brp-debuginfo $(DESTDIR)$(configdir)/brp.d/056-debuginfo.brp
$(INSTALL) -m755 brp-sign-kmodules $(DESTDIR)$(configdir)/brp.d/057-brp-sign-kmodules.brp $(INSTALL) -m755 brp-sign-kmodules $(DESTDIR)$(configdir)/brp.d/057-brp-sign-kmodules.brp
$(INSTALL) -m755 brp-strip-lto $(DESTDIR)$(configdir)/brp.d/061-brp-strip-lto.brp
$(INSTALL) -m755 process-debuginfo $(DESTDIR)$(configdir)/process-debuginfo $(INSTALL) -m755 process-debuginfo $(DESTDIR)$(configdir)/process-debuginfo
$(INSTALL) -m755 process-lto $(DESTDIR)$(configdir)/process-lto
$(INSTALL) -m755 brp-verify_elf $(DESTDIR)$(configdir)/brp.d/064-verify_elf.brp $(INSTALL) -m755 brp-verify_elf $(DESTDIR)$(configdir)/brp.d/064-verify_elf.brp
$(INSTALL) -m755 install $(DESTDIR)$(libexecdir)/rpm-build/install $(INSTALL) -m755 install $(DESTDIR)$(libexecdir)/rpm-build/install
$(INSTALL) -m755 strip $(DESTDIR)$(libexecdir)/rpm-build/strip $(INSTALL) -m755 strip $(DESTDIR)$(libexecdir)/rpm-build/strip

39
scripts/brp-strip-lto.in Executable file
View File

@ -0,0 +1,39 @@
#!/bin/sh -efu
#
# brp-strip-lto - Strip LTO sections and symbols from object files
#
# LTO bytecode needs to be stripped for distributions, because it's
# GCC version dependent:
# "The bytecode files are versioned and there is a strict version
# check, so bytecode files generated in one version of GCC do not
# work with an older or newer version of GCC." -- gcc(1).
#
# Based on brp-strip-lto (Fedora) and brp-debuginfo.
# Copyright (c) 2021 Vitaly Chikunov <vt@altlinux.org>.
# License: GPLv2+.
# Implementation notes:
# - xargs -Px -nx to start parallelizing sooner.
# - %brp_strip_none is respected.
. @RPMCONFIGDIR@/functions
ValidateBuildRoot
cd "$RPM_BUILD_ROOT"
mkdir -p .tmp
# They skip /usr/lib/debug from the search, but why. There aren't
# such objects nor meaning to skip stripping them.
# Only skip internal temporary workspace.
find -path './.*' -prune -o -name '*.[ao]' -type f -print | \
while read -r f; do
for pat in ${RPM_BRP_STRIP_NONE-}; do
if [ -z "${f##.$pat}" ]; then
f=
continue
fi
done
[ -n "$f" ] && printf "%s\0" "$f"
done | \
eu-elfclassify --not-program --not-library --not-linux-kernel-module --stdin0 --print0 | \
xargs -0 -r -P$(nproc) -n$(nproc) @RPMCONFIGDIR@/process-lto

41
scripts/process-lto.in Executable file
View File

@ -0,0 +1,41 @@
#!/bin/sh -efu
#
# Process single file for LTO business.
# (Will be run multiple instances in parallel.)
#
# Based on brp-strip-lto (Fedora).
# Copyright (c) 2021 Vitaly Chikunov <vt@altlinux.org>.
# License: GPLv2+.
#
# Implementation notes:
# - eu-strip cannot be used due to absence of `-N`.
. @RPMCONFIGDIR@/functions
ValidateBuildRoot
cd "$RPM_BUILD_ROOT"
mkdir -p .tmp
# If there is only slim lto, strip will produce "plugin needed to handle lto
# object" warning, because of stripping __gnu_lto_v1 symbol while remaining
# __gnu_lto_slim.
strip -p -R '.gnu.lto_*' -R '.gnu.debuglto_*' -N '__gnu_lto_v1' "$@"
# Verify that we still have exportable symbols.
suggest="Perhaps, you need to %define optflags_lto %optflags_lto -ffat-lto-objects"
for f
do
# Output in one line per symbol format.
nm -g -A -P "$f" > .tmp/lto-nm.$$ 2>/dev/null
if grep -F -q -w ': __gnu_lto_slim' .tmp/lto-nm.$$; then
if grep -F -q -v -w ': __gnu_lto_slim' .tmp/lto-nm.$$; then
Fatal "$f: contains __gnu_lto_slim. $suggest"
else
Fatal "$f: contains __gnu_lto_slim only. $suggest"
fi
elif [ ! -s .tmp/lto-nm.$$ ]; then
# This is only informational call of file.
Warning "$f: contains no exportable symbols: $(file4 -b "$f")"
fi
rm .tmp/lto-nm.$$
done