diff --git a/gcc.spec b/gcc.spec index 7cec762..69e7e69 100644 --- a/gcc.spec +++ b/gcc.spec @@ -115,10 +115,29 @@ %ifarch x86_64 %global multilib_32_arch i686 %endif + +# Use "--without annobin-plugin" to disable the building of the annobin plugin for GCC. +%bcond_without annobin_plugin + +# Use "--without tests" to disable the testsuite. +# Not technically needed for building the annobin plugin, but this has been added +# because not running the testsuites makes building the gcc rpms a *lot* faster. +%bcond_without tests + +# The next line has been stolen from redhat-rpm-config.spec. +# We install the version info into a file in this directory, rather than +# gcc's plugin directory, because there is no reliable way for redhat-rpm-config +# to determine the name of gcc's plugin directory. Plus there may be more than +# one plugin directory if different versions of gcc are installed. +%global rrcdir /usr/lib/rpm/redhat + +# A file that records information about the built gcc-annobin plugin. +%global gver %{rrcdir}/gcc-annobin-plugin-version-info + Summary: Various compilers (C, C++, Objective-C, ...) Name: gcc Version: %{gcc_version} -Release: %{gcc_release}%{?dist} +Release: %{gcc_release}.1%{?dist} # libgcc, libgfortran, libgomp, libstdc++ and crtstuff have # GCC Runtime Exception. License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD @@ -205,6 +224,15 @@ BuildRequires: libunwind >= 0.98 BuildRequires: doxygen >= 1.7.1 BuildRequires: graphviz, dblatex, texlive-collection-latex, docbook5-style-xsl %endif + +%if %{with annobin_plugin} +# Starting with release 9.93 annobin puts a copy of the sources in /usr/src/annobin +# Starting with release 10.01 annobin fixed a bug in its configure scripts which prevented them from working with a built but not installed compiler +BuildRequires: annobin >= 10.01 +# See The %%install phase for why we need xz. +BuildRequires: xz +%endif + Requires: cpp = %{version}-%{release} # Need .eh_frame ld optimizations # Need proper visibility support @@ -1205,6 +1233,82 @@ done) rm -f rpm.doc/changelogs/gcc/ChangeLog.[1-9] find rpm.doc -name \*ChangeLog\* | xargs bzip2 -9 +%if %{with annobin_plugin} +# Get the annobin sources. Note these are not added to the rpm as SOURCE4 +# because if they were the build phase would try to include them as part of +# gcc itself, and this causes problems. Instead we locate the sources in +# the buildroot. They should have been put there when annobin was installed. + +pushd %{_builddir} + +%global annobin_source_dir %{_usrsrc}/annobin + +if [ -d %{annobin_source_dir} ] +then + # Unpack the sources. + echo "Unpacking annobin sources" + rm -fr annobin-* + tar xvf %{annobin_source_dir}/latest-annobin.tar.xz +else + echo "Unable to locate annobin sources (expected to find: %{annobin_source_dir}/latest-annobin.tar.xz)" + echo "These should be provided by installing the annobin-plugin-gcc package" + exit 1 +fi + +# Setting this as a local symbol because using %%global does not appear to work. +annobin_dir=$(find . -maxdepth 1 -type d -name "annobin*") + +# Now build the annobin plugin using the just built compiler. +echo "annobin directory = ${annobin_dir}" +cd ${annobin_dir} + +# Work out where this version of gcc stores its plugins. +%global ANNOBIN_GCC_PLUGIN_DIR %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_major}/plugin + +CONFIG_ARGS="--quiet" +CONFIG_ARGS="$CONFIG_ARGS --with-gcc-plugin-dir=%{ANNOBIN_GCC_PLUGIN_DIR}" +CONFIG_ARGS="$CONFIG_ARGS --without-annocheck" +CONFIG_ARGS="$CONFIG_ARGS --without-tests" + +comp_dir="%{_builddir}/gcc-%{version}-%{DATE}/obj-%{gcc_target_platform}/gcc/" +ccompiler="%{_builddir}/gcc-%{version}-%{DATE}/obj-%{gcc_target_platform}/gcc/xgcc -B $comp_dir" +cxxcompiler="%{_builddir}/gcc-%{version}-%{DATE}/obj-%{gcc_target_platform}/gcc/xg++ -B $comp_dir" + +comp_flags="%build_cflags" +comp_flags="$comp_flags -I %{_builddir}/gcc-%{version}-%{DATE}/gcc" +comp_flags="$comp_flags -I %{_builddir}/gcc-%{version}-%{DATE}/obj-%{gcc_target_platform}/gcc/" +comp_flags="$comp_flags -I %{_builddir}/gcc-%{version}-%{DATE}/obj-%{gcc_target_platform}/%{gcc_target_platform}/libstdc++-v3/include" +comp_flags="$comp_flags -I %{_builddir}/gcc-%{version}-%{DATE}/obj-%{gcc_target_platform}/%{gcc_target_platform}/libstdc++-v3/include/%{gcc_target_platform}" +comp_flags="$comp_flags -I %{_builddir}/gcc-%{version}-%{DATE}/libstdc++-v3/libsupc++" +comp_flags="$comp_flags -I %{_builddir}/gcc-%{version}-%{DATE}/include" +comp_flags="$comp_flags -I %{_builddir}/gcc-%{version}-%{DATE}/libcpp/include" + +ld_flags="%build_ldflags" +ld_flags="$ld_flags -L%{_builddir}/gcc-%{version}-%{DATE}/obj-%{gcc_target_platform}/libstdc++-v3/.libs" +ld_flags="$ld_flags -L%{_builddir}/gcc-%{version}-%{DATE}/obj-%{gcc_target_platform}/%{gcc_target_platform}/libstdc++-v3/.libs" +ld_flags="$ld_flags -L%{_builddir}/gcc-%{version}-%{DATE}/obj-%{gcc_target_platform}/%{gcc_target_platform}/libstdc++-v3/src/.libs" +ld_flags="$ld_flags -L%{_builddir}/gcc-%{version}-%{DATE}/obj-%{gcc_target_platform}/libstdc++-v3/libsupc++/.libs" +ld_flags="$ld_flags -L%{_builddir}/gcc-%{version}-%{DATE}/obj-%{gcc_target_platform}/%{gcc_target_platform}/libstdc++-v3/libsupc++/.libs" +ld_flags="$ld_flags -L%{_builddir}/gcc-%{version}-%{DATE}/obj-%{gcc_target_platform}/%{gcc_target_platform}/libgcc/.libs" +ld_flags="$ld_flags -Wl,-rpath,/usr/%{_lib}" + +# libtool works with CFLAGS but ignores LDFLAGS, so we have to combine them. +comp_flags="$comp_flags $ld_flags" + +echo "Configuring the annobin plugin" +CC="${ccompiler}" CFLAGS="${comp_flags}" \ + CXX="${cxxcompiler}" CXXFLAGS="${comp_flags}" \ + LDFLAGS="${ld_flags}" \ + ./configure ${CONFIG_ARGS} || cat config.log + +echo "Building the annobin plugin" +make + +echo "Annobin plugin build complete" +popd +# endif for %{with annobin_plugin} +%endif + %install rm -rf %{buildroot} mkdir -p %{buildroot} @@ -2001,6 +2105,52 @@ echo gcc-%{version}-%{release}.%{_arch} > $FULLPATH/rpmver ln -s ../../libexec/gcc/%{gcc_target_platform}/%{gcc_major}/liblto_plugin.so \ %{buildroot}%{_libdir}/bfd-plugins/ +%if %{with annobin_plugin} + +# Rename the plugin to gcc-annobin. +mkdir -p %{buildroot}%{ANNOBIN_GCC_PLUGIN_DIR} +pushd %{buildroot}%{ANNOBIN_GCC_PLUGIN_DIR} + +annobin_dir=$(find %{_builddir} -maxdepth 1 -type d -name "annobin*") +echo "annobin directory = ${annobin_dir}" + +cp ${annobin_dir}/gcc-plugin/.libs/annobin.so.0.0.0 gcc-annobin.so.0.0.0 +# Compress the plugin so that it cannot be stripped or examined by check-rpath. +# The problem with check-rpath is that the plugin contains a path to the built +# but not installed version of the libstdc++ library, and this is insecure. +# In practice this is not a problem as the plugin does not load the library, but +# there is no way to tell check-rpath this fact. +xz -9 gcc-annobin.so.0.0.0 + +rm -f gcc-annobin.so.0 gcc-annobin.so +ln -s gcc-annobin.so.0.0.0 gcc-annobin.so.0 +ln -s gcc-annobin.so.0.0.0 gcc-annobin.so + +# Record information about the plugin. +mkdir -p %{buildroot}%{rrcdir} +# Note - the comparison logic in redhat-rpm-config's %%triggger macros require +# that the plugin builder information appear as "major.minor.revision-release", +# eg "11.2.1-1" on the first line of the version file. +echo "%{gcc_version}-%{gcc_release}" > %{buildroot}%{gver} +# Provide a more complete version information string on the second line. +# This is not used by the comparison logic, but makes the file more useful to humans. +echo "%{ANNOBIN_GCC_PLUGIN_DIR}/gcc-annobin.so.0.0.0 was built by gcc version %{gcc_version}-%{gcc_release} from the ${annobin_dir} sources" >> %{buildroot}%{gver} +popd +# endif for %{with annobin_plugin} +%endif + +%if %{with annobin_plugin} +%post +pushd %{ANNOBIN_GCC_PLUGIN_DIR} > /dev/null +# Uncompress the annobin plugin now that the %%install phase is over. +xz -d gcc-annobin.so.0.0.0.xz +rm -f gcc-annobin.so.0 gcc-annobin.so +ln -s gcc-annobin.so.0.0.0 gcc-annobin.so.0 +ln -s gcc-annobin.so.0.0.0 gcc-annobin.so +popd > /dev/null +%endif + +%if %{with tests} %check cd obj-%{gcc_target_platform} @@ -2053,6 +2203,9 @@ tar cf - testlogs-%{_target_platform}-%{version}-%{release} | xz -9e \ | uuencode testlogs-%{_target_platform}.tar.xz || : rm -rf testlogs-%{_target_platform}-%{version}-%{release} +# endif for the if {with tests} above. +%endif + %post go %{_sbindir}/update-alternatives --install \ %{_prefix}/bin/go go %{_prefix}/bin/go.gcc 92 \ @@ -2118,6 +2271,11 @@ end %ldconfig_scriptlets -n libgo +%if %{with annobin_plugin} +%{ANNOBIN_GCC_PLUGIN_DIR} +%{gver} +%endif + %files -f %{name}.lang %{_prefix}/bin/cc %{_prefix}/bin/c89 @@ -3145,6 +3303,9 @@ end %endif %changelog +* Thu Dec 16 2021 Marek Polacek 11.2.1-7.1 +- build annobin plugin (patch by Nick Clifton) (#2030667) + * Tue Dec 7 2021 Marek Polacek 11.2.1-7 - update from releases/gcc-11-branch (#1996858) - PRs ada/100486, c++/70796, c++/92746, c++/93286, c++/94490, c++/102642,