add brp-llvm-compile-lto-elf

This commit is contained in:
David Benoit 2021-02-10 11:59:25 -05:00
parent 27a8c7a7c2
commit 391eca3508
3 changed files with 61 additions and 1 deletions

47
brp-llvm-compile-lto-elf Executable file
View File

@ -0,0 +1,47 @@
#!/usr/bin/bash -eu
CLANG_FLAGS=$@
if [ -z "$RPM_BUILD_ROOT" ] || [ "$RPM_BUILD_ROOT" = "/" ]; then
exit 0
fi
TMPDIR=`mktemp -d`
check_convert_bitcode () {
local file_name=`realpath ${1}`
local file_type=`file ${file_name}`
if [[ "${file_type}" == *"LLVM IR bitcode"* ]]; then
# check for an indication that the bitcode was
# compiled with -flto
llvm-bcanalyzer -dump ${file_name} | grep -xP '.*\-flto((?!-fno-lto).)*' 2>&1 > /dev/null
if [ $? -eq 0 ]; then
echo "Compiling LLVM bitcode file ${file_name}."
# create path to file in temp dir
# move file to temp dir with llvm .bc extension for clang
mkdir -p ${TMPDIR}/`dirname ${file_name}`
mv $file_name ${TMPDIR}/${file_name}.bc
clang -c ${CLANG_FLAGS} -fno-lto -Wno-unused-command-line-argument ${TMPDIR}/${file_name}.bc -o ${file_name}
fi
elif [[ "${file_type}" == *"current ar archive"* ]]; then
echo "Unpacking ar archive ${file_name} to check for LLVM bitcode components."
# create archive stage for objects
local archive_stage=`mktemp -d`
local archive=${file_name}
pushd ${archive_stage}
ar x ${archive}
for archived_file in `find -not -type d`; do
check_convert_bitcode ${archived_file}
echo "Repacking ${archived_file} into ${archive}."
ar r ${archive} ${archived_file}
done
popd
fi
}
echo "Checking for LLVM bitcode artifacts"
for i in `find $RPM_BUILD_ROOT -type f -name "*.[ao]"`; do
check_convert_bitcode ${i}
done

3
macros
View File

@ -253,7 +253,10 @@ print(result)
# __brp_mangle_shebangs_exclude_from_file - file from which to get files to ignore # __brp_mangle_shebangs_exclude_from_file - file from which to get files to ignore
%__brp_mangle_shebangs /usr/lib/rpm/redhat/brp-mangle-shebangs %{?__brp_mangle_shebangs_exclude:--shebangs "%{?__brp_mangle_shebangs_exclude}"} %{?__brp_mangle_shebangs_exclude_file:--shebangs-from "%{__brp_mangle_shebangs_exclude_file}"} %{?__brp_mangle_shebangs_exclude_from:--files "%{?__brp_mangle_shebangs_exclude_from}"} %{?__brp_mangle_shebangs_exclude_from_file:--files-from "%{__brp_mangle_shebangs_exclude_from_file}"} %__brp_mangle_shebangs /usr/lib/rpm/redhat/brp-mangle-shebangs %{?__brp_mangle_shebangs_exclude:--shebangs "%{?__brp_mangle_shebangs_exclude}"} %{?__brp_mangle_shebangs_exclude_file:--shebangs-from "%{__brp_mangle_shebangs_exclude_file}"} %{?__brp_mangle_shebangs_exclude_from:--files "%{?__brp_mangle_shebangs_exclude_from}"} %{?__brp_mangle_shebangs_exclude_from_file:--files-from "%{__brp_mangle_shebangs_exclude_from_file}"}
%__brp_llvm_compile_lto_elf /usr/lib/rpm/redhat/brp-llvm-compile-lto-elf %{build_cflags} %{build_ldflags}
%__os_install_post \ %__os_install_post \
%[ "%{toolchain}" == "clang" ? "%{?__brp_llvm_compile_lto_elf}" : "%{nil}" ] \
%{?__brp_ldconfig} \ %{?__brp_ldconfig} \
%{?__brp_compress} \ %{?__brp_compress} \
%{!?__debug_package:\ %{!?__debug_package:\

View File

@ -6,7 +6,7 @@
Summary: Red Hat specific rpm configuration files Summary: Red Hat specific rpm configuration files
Name: redhat-rpm-config Name: redhat-rpm-config
Version: 182 Version: 183
Release: 1%{?dist} Release: 1%{?dist}
# No version specified. # No version specified.
License: GPL+ License: GPL+
@ -57,6 +57,9 @@ Source202: brp-python-bytecompile
# https://github.com/fedora-python/marshalparser # https://github.com/fedora-python/marshalparser
Source203: brp-fix-pyc-reproducibility Source203: brp-fix-pyc-reproducibility
# for converting llvm LTO bitcode objects into ELF
Source204: brp-llvm-compile-lto-elf
# Dependency generator scripts (deprecated) # Dependency generator scripts (deprecated)
Source300: find-provides Source300: find-provides
Source301: find-provides.ksyms Source301: find-provides.ksyms
@ -124,6 +127,9 @@ Requires: %{_bindir}/grep
Requires: %{_bindir}/sed Requires: %{_bindir}/sed
Requires: %{_bindir}/xargs Requires: %{_bindir}/xargs
# for brp-llvm-compile-lto-elf
Requires: (llvm if clang)
# -fstack-clash-protection and -fcf-protection require GCC 8. # -fstack-clash-protection and -fcf-protection require GCC 8.
Conflicts: gcc < 8.0.1-0.22 Conflicts: gcc < 8.0.1-0.22
@ -213,6 +219,10 @@ install -p -m 644 -t %{buildroot}%{_rpmluadir}/fedora/srpm forge.lua
%{_rpmconfigdir}/macros.d/macros.kmp %{_rpmconfigdir}/macros.d/macros.kmp
%changelog %changelog
* Tue Apr 6 2021 David Benoit <dbenoit@redhat.com> - 183-1
- BRP: LLVM Compile LTO Bitcode to ELF
- Add Requires: (llvm if clang)
* Mon Mar 22 2021 Lumír Balhar <lbalhar@redhat.com> - 182-1 * Mon Mar 22 2021 Lumír Balhar <lbalhar@redhat.com> - 182-1
- Fix handling of files without newlines in brp-mangle-shebang - Fix handling of files without newlines in brp-mangle-shebang