From 25ea080503858e773f09bb2a0a5d96807e469779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Fri, 23 Sep 2022 13:11:52 +0200 Subject: [PATCH] Fix brp-llvm-compile-lto to not rely on a backtracking regex Instead, grep the llvm-strings output for "-flto" and "-fno-lto" and recognize the input as LTO input if -flto has a byte index greater than -fno-lto. --- brp-llvm-compile-lto-elf | 22 ++++++++++++++-------- redhat-rpm-config.spec | 5 ++++- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/brp-llvm-compile-lto-elf b/brp-llvm-compile-lto-elf index 93dad4c..7eb53a1 100755 --- a/brp-llvm-compile-lto-elf +++ b/brp-llvm-compile-lto-elf @@ -16,14 +16,20 @@ check_convert_bitcode () { CLANG_FLAGS="$@" if [[ "${file_type}" == *"LLVM IR bitcode"* ]]; then - # check for an indication that the bitcode was - # compiled with -flto - llvm-bcanalyzer -dump ${file_name} | grep -xP '.*\-flto((?!-fno-lto).)*' 2>&1 > /dev/null - if [ $? -eq 0 ]; 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} - fi + # 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 diff --git a/redhat-rpm-config.spec b/redhat-rpm-config.spec index 6d02c94..cac4ee7 100644 --- a/redhat-rpm-config.spec +++ b/redhat-rpm-config.spec @@ -4,7 +4,7 @@ # 2) When making changes, increment the version (in baserelease) by 1. # rpmdev-bumpspec and other tools update the macro below, which is used # in Version: to get the desired effect. -%global baserelease 231 +%global baserelease 232 Summary: Red Hat specific rpm configuration files Name: redhat-rpm-config @@ -221,6 +221,9 @@ install -p -m 644 -t %{buildroot}%{_rpmluadir}/fedora/srpm forge.lua %doc buildflags.md %changelog +* Fri Sep 23 2022 Timm Bäder - 232-1 +- Fix brp-compile-lto-elf to not rely on a backtracking regex + * Thu Sep 08 2022 Maxwell G - 231-1 - forge macros: Support Sourcehut. Fixes rhbz#2035935.