update of the repack llvm ir => .a file

This commit is contained in:
Sylvestre Ledru 2024-03-05 23:20:25 +01:00
parent f6c22777bc
commit a403fa2c96

View File

@ -25,18 +25,25 @@ NCPUS=$NJOBS
check_convert_bitcode () { check_convert_bitcode () {
local file_name=$(realpath ${1}) local file_name=$(realpath ${1})
local file_type=$(file ${file_name}) local file_type=$(file ${file_name})
shift shift
CLANG_FLAGS="$@" CLANG_FLAGS="$@"
if [[ "${file_type}" == *"LLVM IR bitcode"* ]]; then if [[ "${file_type}" == *"LLVM IR bitcode"* ]]; then
# check for an indication that the bitcode was # Check the output of llvm-strings for the command line, which is in the LLVM bitcode because
# compiled with -flto # we pass -frecord-gcc-switches.
${P_TO_LLVM}/debian/tmp/usr/bin/llvm-bcanalyzer-${VERSION} -dump ${file_name} | grep -xP '.*\-flto((?!-fno-lto).)*' 2>&1 > /dev/null # Check for a line that has "-flto" after (or without) "-fno-lto".
if [ $? -eq 0 ]; then llvm-strings ${file_name} | while read line ; do
echo "Compiling LLVM bitcode file ${file_name}." flto=$(echo $line | grep -o -b -e -flto | tail -n 1 | cut -d : -f 1)
${P_TO_LLVM}/debian/tmp/usr/bin/clang-${VERSION} -fno-lto -opaque-pointers -Wno-unused-command-line-argument \ fnolto=$(echo $line | grep -o -b -e -fno-lto | tail -n 1 | cut -d : -f 1)
-x ir ${file_name} -c -o ${file_name}
fi if test -n "$flto" && { test -z "$fnolto" || test "$flto" -gt "$fnolto"; } ; then
echo "Compiling LLVM bitcode file ${file_name}."
clang ${CLANG_FLAGS} -fno-lto -Wno-unused-command-line-argument \
-x ir ${file_name} -c -o ${file_name}
break
fi
done
elif [[ "${file_type}" == *"current ar archive"* ]]; then elif [[ "${file_type}" == *"current ar archive"* ]]; then
echo "Unpacking ar archive ${file_name} to check for LLVM bitcode components." echo "Unpacking ar archive ${file_name} to check for LLVM bitcode components."
# create archive stage for objects # create archive stage for objects
@ -47,7 +54,7 @@ check_convert_bitcode () {
for archived_file in $(find -not -type d); do for archived_file in $(find -not -type d); do
check_convert_bitcode ${archived_file} ${CLANG_FLAGS} check_convert_bitcode ${archived_file} ${CLANG_FLAGS}
echo "Repacking ${archived_file} into ${archive}." echo "Repacking ${archived_file} into ${archive}."
${P_TO_LLVM}/debian/tmp/usr/bin/llvm-ar-${VERSION} r ${archive} ${archived_file} ar r ${archive} ${archived_file}
done done
popd popd
fi fi
@ -55,5 +62,7 @@ check_convert_bitcode () {
echo "Checking for LLVM bitcode artifacts" echo "Checking for LLVM bitcode artifacts"
export -f check_convert_bitcode export -f check_convert_bitcode
find "$P_TO_LLVM/debian/" -type f -name "*.[ao]" -print0 | \ # Deduplicate by device:inode to avoid processing hardlinks in parallel.
xargs -0 -r -n1 -P$NCPUS bash -c "check_convert_bitcode \$@ $CLANG_FLAGS" ARG0 find "$P_TO_LLVM/debian/" -type f -name "*.[ao]" -printf "%D:%i %p\n" | \
awk '!seen[$1]++' | cut -d" " -f2- | \
xargs -d"\n" -r -n1 -P$NCPUS sh -c "check_convert_bitcode \$@ $CLANG_FLAGS" ARG0