2021-02-10 16:59:25 +00:00
|
|
|
#!/usr/bin/bash -eu
|
|
|
|
|
|
|
|
|
|
|
|
if [ -z "$RPM_BUILD_ROOT" ] || [ "$RPM_BUILD_ROOT" = "/" ]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2022-03-02 16:14:11 +00:00
|
|
|
CLANG_FLAGS=$@
|
2022-02-25 15:36:03 +00:00
|
|
|
NCPUS=${RPM_BUILD_NCPUS:-1}
|
2021-02-10 16:59:25 +00:00
|
|
|
|
|
|
|
check_convert_bitcode () {
|
2022-02-25 15:36:03 +00:00
|
|
|
local file_name=$(realpath ${1})
|
|
|
|
local file_type=$(file ${file_name})
|
2021-02-10 16:59:25 +00:00
|
|
|
|
2022-05-23 23:46:48 +00:00
|
|
|
shift
|
|
|
|
CLANG_FLAGS="$@"
|
|
|
|
|
2022-03-02 16:14:11 +00:00
|
|
|
if [[ "${file_type}" == *"LLVM IR bitcode"* ]]; then
|
2021-02-10 16:59:25 +00:00
|
|
|
# check for an indication that the bitcode was
|
|
|
|
# compiled with -flto
|
2021-11-16 21:28:14 +00:00
|
|
|
llvm-bcanalyzer -dump ${file_name} | grep -xP '.*\-flto((?!-fno-lto).)*' 2>&1 > /dev/null
|
2021-02-10 16:59:25 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "Compiling LLVM bitcode file ${file_name}."
|
2022-03-02 16:14:11 +00:00
|
|
|
clang ${CLANG_FLAGS} -fno-lto -Wno-unused-command-line-argument \
|
|
|
|
-x ir ${file_name} -c -o ${file_name}
|
2021-02-10 16:59:25 +00:00
|
|
|
fi
|
2022-03-02 16:14:11 +00:00
|
|
|
elif [[ "${file_type}" == *"current ar archive"* ]]; then
|
2021-02-10 16:59:25 +00:00
|
|
|
echo "Unpacking ar archive ${file_name} to check for LLVM bitcode components."
|
|
|
|
# create archive stage for objects
|
2022-02-25 15:36:03 +00:00
|
|
|
local archive_stage=$(mktemp -d)
|
2021-02-10 16:59:25 +00:00
|
|
|
local archive=${file_name}
|
|
|
|
pushd ${archive_stage}
|
|
|
|
ar x ${archive}
|
2022-02-25 15:36:03 +00:00
|
|
|
for archived_file in $(find -not -type d); do
|
2022-05-23 23:46:48 +00:00
|
|
|
check_convert_bitcode ${archived_file} ${CLANG_FLAGS}
|
2021-02-10 16:59:25 +00:00
|
|
|
echo "Repacking ${archived_file} into ${archive}."
|
|
|
|
ar r ${archive} ${archived_file}
|
|
|
|
done
|
|
|
|
popd
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "Checking for LLVM bitcode artifacts"
|
2022-02-25 15:36:03 +00:00
|
|
|
export -f check_convert_bitcode
|
|
|
|
find "$RPM_BUILD_ROOT" -type f -name "*.[ao]" -print0 | \
|
2022-08-05 09:40:53 +00:00
|
|
|
xargs -0 -r -n1 -P$NCPUS sh -c "check_convert_bitcode \$@ $CLANG_FLAGS" ARG0
|