From f77dcdec182e65966d6a14f6db242cab6fce990e Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Mon, 23 May 2022 16:46:48 -0700 Subject: [PATCH] Fix passing of CFLAGS to brp-llvm-compile-lto-elf This was accidentally broken by d9c7e4eef8d39f1660a0ee3372eabe44239bd121. --- brp-llvm-compile-lto-elf | 7 ++-- redhat-rpm-config.spec | 5 ++- .../brp-llvm-compile-lto-elf-test-lib.c | 5 +++ .../brp-llvm-compile-lto-elf-test-lib.h | 1 + .../brp-llvm-compile-lto-elf-test-lib.spec | 34 +++++++++++++++++++ .../brp-llvm-compile-lto-elf-test.c | 6 ++++ .../brp-llvm-compile-lto-elf-test.spec | 24 +++++++++++++ tests/brp-llvm-compile-lto-elf/main.fmf | 8 +++++ tests/brp-llvm-compile-lto-elf/runtest.sh | 17 ++++++++++ 9 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 tests/brp-llvm-compile-lto-elf/brp-llvm-compile-lto-elf-test-lib/brp-llvm-compile-lto-elf-test-lib.c create mode 100644 tests/brp-llvm-compile-lto-elf/brp-llvm-compile-lto-elf-test-lib/brp-llvm-compile-lto-elf-test-lib.h create mode 100644 tests/brp-llvm-compile-lto-elf/brp-llvm-compile-lto-elf-test-lib/brp-llvm-compile-lto-elf-test-lib.spec create mode 100644 tests/brp-llvm-compile-lto-elf/brp-llvm-compile-lto-elf-test/brp-llvm-compile-lto-elf-test.c create mode 100644 tests/brp-llvm-compile-lto-elf/brp-llvm-compile-lto-elf-test/brp-llvm-compile-lto-elf-test.spec create mode 100644 tests/brp-llvm-compile-lto-elf/main.fmf create mode 100755 tests/brp-llvm-compile-lto-elf/runtest.sh diff --git a/brp-llvm-compile-lto-elf b/brp-llvm-compile-lto-elf index 03006c7..6eceee2 100755 --- a/brp-llvm-compile-lto-elf +++ b/brp-llvm-compile-lto-elf @@ -12,6 +12,9 @@ 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 for an indication that the bitcode was # compiled with -flto @@ -29,7 +32,7 @@ check_convert_bitcode () { pushd ${archive_stage} ar x ${archive} for archived_file in $(find -not -type d); do - check_convert_bitcode ${archived_file} + check_convert_bitcode ${archived_file} ${CLANG_FLAGS} echo "Repacking ${archived_file} into ${archive}." ar r ${archive} ${archived_file} done @@ -40,4 +43,4 @@ check_convert_bitcode () { echo "Checking for LLVM bitcode artifacts" export -f check_convert_bitcode find "$RPM_BUILD_ROOT" -type f -name "*.[ao]" -print0 | \ - xargs -0 -n1 -P$NCPUS sh -c "check_convert_bitcode \$@" ARG0 + xargs -0 -n1 -P$NCPUS sh -c "check_convert_bitcode \$@ $CLANG_FLAGS" ARG0 diff --git a/redhat-rpm-config.spec b/redhat-rpm-config.spec index b7a0c5a..d178469 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 223 +%global baserelease 224 Summary: Red Hat specific rpm configuration files Name: redhat-rpm-config @@ -219,6 +219,9 @@ install -p -m 644 -t %{buildroot}%{_rpmluadir}/fedora/srpm forge.lua %doc buildflags.md %changelog +* Tue Jun 14 2022 Tom Stellard - 224-1 +- Fix passing of CFLAGS to brp-llvm-compile-lto-elf + * Fri May 27 2022 Tom Stellard - 223-1 - Move -fno-openmp-implicit-rpath option from CFLAGS to LDFLAGS diff --git a/tests/brp-llvm-compile-lto-elf/brp-llvm-compile-lto-elf-test-lib/brp-llvm-compile-lto-elf-test-lib.c b/tests/brp-llvm-compile-lto-elf/brp-llvm-compile-lto-elf-test-lib/brp-llvm-compile-lto-elf-test-lib.c new file mode 100644 index 0000000..851790f --- /dev/null +++ b/tests/brp-llvm-compile-lto-elf/brp-llvm-compile-lto-elf-test-lib/brp-llvm-compile-lto-elf-test-lib.c @@ -0,0 +1,5 @@ +#include + +void hello(void) { + printf("Hello, world!\n"); +} diff --git a/tests/brp-llvm-compile-lto-elf/brp-llvm-compile-lto-elf-test-lib/brp-llvm-compile-lto-elf-test-lib.h b/tests/brp-llvm-compile-lto-elf/brp-llvm-compile-lto-elf-test-lib/brp-llvm-compile-lto-elf-test-lib.h new file mode 100644 index 0000000..ef77476 --- /dev/null +++ b/tests/brp-llvm-compile-lto-elf/brp-llvm-compile-lto-elf-test-lib/brp-llvm-compile-lto-elf-test-lib.h @@ -0,0 +1 @@ +void hello(void); diff --git a/tests/brp-llvm-compile-lto-elf/brp-llvm-compile-lto-elf-test-lib/brp-llvm-compile-lto-elf-test-lib.spec b/tests/brp-llvm-compile-lto-elf/brp-llvm-compile-lto-elf-test-lib/brp-llvm-compile-lto-elf-test-lib.spec new file mode 100644 index 0000000..d8bfb32 --- /dev/null +++ b/tests/brp-llvm-compile-lto-elf/brp-llvm-compile-lto-elf-test-lib/brp-llvm-compile-lto-elf-test-lib.spec @@ -0,0 +1,34 @@ +Name: brp-llvm-compile-lto-elf-test-lib +Version: 1 +Release: 1 +Summary: Library package for testing brp-llvm-compile-lto-elf +License: MIT + +BuildRequires: clang binutils +Source0: %{name}.c +Source1: %{name}.h + +# FIXME: I'm not sure why this doesn't work +%undefine _package_note_file + +%global toolchain clang + +%description +%{summary} + +%build + +clang ${CFLAGS} -c %{SOURCE0} -o lib.o +ar cr %{name}.a lib.o +ranlib %{name}.a + +%install +mkdir -p %{buildroot}%{_libdir} +mkdir -p %{buildroot}%{_includedir} + +%{__install} -p -m 644 -t %{buildroot}%{_libdir} %{name}.a +%{__install} -p -m 644 -t %{buildroot}%{_includedir} %{SOURCE1} + +%files +%{_libdir}/%{name}.a +%{_includedir}/%{name}.h diff --git a/tests/brp-llvm-compile-lto-elf/brp-llvm-compile-lto-elf-test/brp-llvm-compile-lto-elf-test.c b/tests/brp-llvm-compile-lto-elf/brp-llvm-compile-lto-elf-test/brp-llvm-compile-lto-elf-test.c new file mode 100644 index 0000000..eab7d69 --- /dev/null +++ b/tests/brp-llvm-compile-lto-elf/brp-llvm-compile-lto-elf-test/brp-llvm-compile-lto-elf-test.c @@ -0,0 +1,6 @@ +#include + +int main(int argc, char **argv) { + hello(); + return 0; +} diff --git a/tests/brp-llvm-compile-lto-elf/brp-llvm-compile-lto-elf-test/brp-llvm-compile-lto-elf-test.spec b/tests/brp-llvm-compile-lto-elf/brp-llvm-compile-lto-elf-test/brp-llvm-compile-lto-elf-test.spec new file mode 100644 index 0000000..a43e545 --- /dev/null +++ b/tests/brp-llvm-compile-lto-elf/brp-llvm-compile-lto-elf-test/brp-llvm-compile-lto-elf-test.spec @@ -0,0 +1,24 @@ +Name: brp-llvm-compile-lto-elf-test +Version: 1 +Release: 1 +Summary: Library package for testing brp-llvm-compile-lto-elf +License: MIT + +BuildRequires: gcc +BuildRequires: brp-llvm-compile-lto-elf-test-lib + +Source0: %{name}.c + +# FIXME: I'm not sure why this doesn't work +%undefine _package_note_file + + +%description +%{summary} + +%build +gcc ${CFLAGS} -c %{SOURCE0} -o %{name}.o +gcc ${LDFLAGS} %{name}.o %{_libdir}/%{name}-lib.a -o %{name} + +%check +./%{name} | grep "Hello, world!" diff --git a/tests/brp-llvm-compile-lto-elf/main.fmf b/tests/brp-llvm-compile-lto-elf/main.fmf new file mode 100644 index 0000000..ada5230 --- /dev/null +++ b/tests/brp-llvm-compile-lto-elf/main.fmf @@ -0,0 +1,8 @@ +Summary: Test that the brp-llvm-compile-lto-elf script is working correctly + +require: + - dnf-plugins-core + - redhat-rpm-config + - rpm-build + +test: ./runtest.sh diff --git a/tests/brp-llvm-compile-lto-elf/runtest.sh b/tests/brp-llvm-compile-lto-elf/runtest.sh new file mode 100755 index 0000000..1690d65 --- /dev/null +++ b/tests/brp-llvm-compile-lto-elf/runtest.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +set -ex + +lib_dir=brp-llvm-compile-lto-elf-test-lib +lib_spec=$lib_dir/brp-llvm-compile-lto-elf-test-lib.spec + +dnf -y build-dep $lib_spec +rpmbuild --define "_sourcedir ." --define "_builddir ./$lib_dir" --define "_rpmdir ." -bb $lib_spec + +dnf -y install ./`rpm --eval '%{_arch}'`/*.rpm + +test_dir=brp-llvm-compile-lto-elf-test +test_spec=$test_dir/brp-llvm-compile-lto-elf-test.spec + +dnf -y build-dep $test_spec +rpmbuild --define "_sourcedir ." --define "_builddir ./$test_dir" -bi $test_spec