| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
CLANG_FLAGS=$@ |
| 7 |
|
| 8 |
if test -z $P_TO_LLVM; then |
| 9 |
echo "P_TO_LLVM isn't set" |
| 10 |
exit 1 |
| 11 |
fi |
| 12 |
|
| 13 |
if test -z $NJOBS; then |
| 14 |
echo "NJOBS isn't set" |
| 15 |
exit 1 |
| 16 |
fi |
| 17 |
|
| 18 |
if test -z $VERSION; then |
| 19 |
echo "VERSION isn't set" |
| 20 |
exit 1 |
| 21 |
fi |
| 22 |
|
| 23 |
NCPUS=$NJOBS |
| 24 |
|
| 25 |
check_convert_bitcode () { |
| 26 |
local file_name=$(realpath ${1}) |
| 27 |
local file_type=$(file ${file_name}) |
| 28 |
shift |
| 29 |
CLANG_FLAGS="$@" |
| 30 |
|
| 31 |
if [[ "${file_type}" == *"LLVM IR bitcode"* ]]; then |
| 32 |
|
| 33 |
|
| 34 |
${P_TO_LLVM}/debian/tmp/usr/bin/llvm-bcanalyzer-${VERSION} -dump ${file_name} | grep -xP '.*\-flto((?!-fno-lto).)*' 2>&1 > /dev/null |
| 35 |
if [ $? -eq 0 ]; then |
| 36 |
echo "Compiling LLVM bitcode file ${file_name}." |
| 37 |
${P_TO_LLVM}/debian/tmp/usr/bin/clang-${VERSION} -fno-lto -opaque-pointers -Wno-unused-command-line-argument \ |
| 38 |
-x ir ${file_name} -c -o ${file_name} |
| 39 |
fi |
| 40 |
elif [[ "${file_type}" == *"current ar archive"* ]]; then |
| 41 |
echo "Unpacking ar archive ${file_name} to check for LLVM bitcode components." |
| 42 |
|
| 43 |
local archive_stage=$(mktemp -d) |
| 44 |
local archive=${file_name} |
| 45 |
pushd ${archive_stage} |
| 46 |
ar x ${archive} |
| 47 |
for archived_file in $(find -not -type d); do |
| 48 |
check_convert_bitcode ${archived_file} ${CLANG_FLAGS} |
| 49 |
echo "Repacking ${archived_file} into ${archive}." |
| 50 |
${P_TO_LLVM}/debian/tmp/usr/bin/llvm-ar-${VERSION} r ${archive} ${archived_file} |
| 51 |
done |
| 52 |
popd |
| 53 |
fi |
| 54 |
} |
| 55 |
|
| 56 |
echo "Checking for LLVM bitcode artifacts" |
| 57 |
export -f check_convert_bitcode |
| 58 |
find "$P_TO_LLVM/debian/" -type f -name "*.[ao]" -print0 | \ |
| 59 |
xargs -0 -r -n1 -P$NCPUS bash -c "check_convert_bitcode \$@ $CLANG_FLAGS" ARG0 |