ac2ca1dbba
The brp-llvm-compile-lto-elf script uses PCRE in grep to match for the -flto flag in bitcode object dumps, using negative lookahead to exclude the case where -fno-lto is specified after. When lines in the bitcode dump exceed the length that PCRE can match against, grep will error out causing brp-llvm-compile-lto-elf to fail. This script implements an equivalent regex match in python to avoid the limit in PCRE grep. Resolves: rhbz#2017193
53 lines
1.6 KiB
Bash
Executable File
53 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/bash -eu
|
|
|
|
# first argument is the path to llvm-lto-elf-check
|
|
MATCH_LTO_SCRIPT=$1
|
|
shift
|
|
|
|
# remaining args are cflags
|
|
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} | ${MATCH_LTO_SCRIPT} 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
|
|
|