diff --git a/brp-llvm-compile-lto-elf b/brp-llvm-compile-lto-elf new file mode 100644 index 0000000000000000000000000000000000000000..9ef4d40272ba2bdc00aac51978453aa2d98bb0a5 --- /dev/null +++ b/brp-llvm-compile-lto-elf @@ -0,0 +1,57 @@ +#!/usr/bin/bash -eu +# From fedora: +# https://src.fedoraproject.org/rpms/redhat-rpm-config +# version 287 + + +if [ -z "$RPM_BUILD_ROOT" ] || [ "$RPM_BUILD_ROOT" = "/" ]; then + exit 0 +fi + +CLANG_FLAGS=$@ +NCPUS=${RPM_BUILD_NCPUS:-1} + +check_convert_bitcode () { + local file_name=$(realpath ${1}) + local file_type=$(file ${file_name}) + + shift + CLANG_FLAGS="$@" + + if [[ "${file_type}" == *"LLVM IR bitcode"* ]]; then + # Check the output of llvm-strings for the command line, which is in the LLVM bitcode because + # we pass -frecord-gcc-switches. + # Check for a line that has "-flto" after (or without) "-fno-lto". + llvm-strings ${file_name} | while read line ; do + flto=$(echo $line | grep -o -b -e -flto | tail -n 1 | cut -d : -f 1) + fnolto=$(echo $line | grep -o -b -e -fno-lto | tail -n 1 | cut -d : -f 1) + + 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 + 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} ${CLANG_FLAGS} + echo "Repacking ${archived_file} into ${archive}." + ar r ${archive} ${archived_file} + done + popd + fi +} + +echo "Checking for LLVM bitcode artifacts" +export -f check_convert_bitcode +# Deduplicate by device:inode to avoid processing hardlinks in parallel. +find "$RPM_BUILD_ROOT" -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 diff --git a/macros b/macros index 6ff7d6ac556fa98535162646bff273c5dfb8efc9..d3c404e71a4cb2404e88e23b5ad7d913332df8ad 100644 --- a/macros +++ b/macros @@ -260,6 +260,7 @@ for k,_ in pairs(stripped_flags) do print(k .. " ") end %__brp_remove_la_files /usr/lib/rpm/brp-remove-la-files %__brp_remove_info_dir /usr/lib/rpm/brp-remove-info-dir %__brp_clean_perl_files /usr/lib/rpm/brp-clean-perl-files +%__brp_llvm_compile_lto_elf /usr/lib/rpm/brp-llvm-compile-lto-elf %{build_cflags} %{build_ldflags} %__os_install_post \ %{?__brp_ldconfig} \ @@ -279,6 +280,7 @@ for k,_ in pairs(stripped_flags) do print(k .. " ") end %{nil} %__spec_install_post\ + %[ "%{toolchain}" == "clang" ? "%{?__brp_llvm_compile_lto_elf}" : "%{nil}" ] \ %{?__debug_package:%{__debug_install_post}}\ %{?@VENDOR@_delete_rpath:%{?__brp_chrpath}} \ %{__arch_install_post}\ diff --git a/openEuler-rpm-config.spec b/openEuler-rpm-config.spec index b721b528305b98c1a0d68eb1fe0c20eeb143ec12..beb211ced4cee207b1a04e14edee851313b10874 100644 --- a/openEuler-rpm-config.spec +++ b/openEuler-rpm-config.spec @@ -3,7 +3,7 @@ Name: %{vendor}-rpm-config Version: 31 -Release: 7 +Release: 8 License: GPL+ Summary: specific rpm configuration files URL: https://gitee.com/src-openeuler/openEuler-rpm-config @@ -56,6 +56,7 @@ Source704: brp-remove-info-dir Source705: brp-check-elf-files Source706: brp-strip-lto Source707: brp-clean-perl-files +Source708: brp-llvm-compile-lto-elf # Convenience lua functions Source800: common.lua @@ -113,6 +114,10 @@ Requires: %{_bindir}/xargs Requires: %{_bindir}/chrpath Requires: %{_bindir}/eu-elfclassify +# for brp-llvm-compile-lto-elf +Requires: (llvm if clang) +Requires: (gawk if clang) + Requires: coreutils # -fstack-clash-protection and -fcf-protection require GCC 8. @@ -179,6 +184,10 @@ sed -i "s/@VENDOR@/%{vendor}/g" `grep "@VENDOR@" -rl %{buildroot}%{_rpmconfigdir %{rpmvdir}/find-requires.ksyms %changelog +* Sat Nov 16 2024 Funda Wang - 31-8 +- compile LLVM IR bitcode in object files or static libraries + into ELF object code for clang < 18 + * Sat Oct 26 2024 Funda Wang - 31-7 - remove useless perl .packlist, empty .bs files and wrongly created perllocal.pod from buildroot