diff --git a/gcc.spec b/gcc.spec index ee96bce..f9cf84a 100644 --- a/gcc.spec +++ b/gcc.spec @@ -113,10 +113,22 @@ %ifarch x86_64 %global multilib_32_arch i686 %endif +%if 0%{?rhel} == 9 +%ifarch x86_64 +%global build_cross 1 +%else +%global build_cross 0 +%endif +%else +%dnl rhel != 9 +%global build_cross 0 +%endif +# TODO: Add ppc64le-redhat-linux s390x-redhat-linux later. +%global cross_targets aarch64-redhat-linux 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 @@ -796,6 +808,46 @@ This package adds a version of the annobin plugin for gcc. This version of the plugin is explicitly built by the same version of gcc that is installed so that there cannot be any synchronization problems. +%package -n cross-gcc-aarch64 +Summary: Cross targeted AArch64 gcc for developer use. Not intended for production. +Provides: cross-gcc-aarch64 = %{version}-%{release} +%if %{build_cross} +Requires: cross-binutils-aarch64 >= 2.35 +Requires: sysroot-aarch64-el9-glibc >= 2.34 +BuildRequires: sysroot-aarch64-el9-glibc >= 2.34 +BuildRequires: cross-binutils-aarch64 >= 2.35 +%endif +# Don't provide e.g. liblto_plugin.so()(64bit). +AutoReqProv: no + +%description -n cross-gcc-aarch64 +This package contains a version of gcc that can compile code for AArch64 +(cross compiler). This cross compiler is intended for developers to use +during application development. This cross compiler is not intended for +production use, and output binary artifacts should not be used in +production. Generated binary artifacts contain binary annotations that +mark them as cross compiled. + +%package -n cross-gcc-c++-aarch64 +Summary: Cross targeted AArch64 gcc-c++ for developer use. Not intended for production. +Provides: cross-gcc-c++-aarch64 = %{version}-%{release} +%if %{build_cross} +Requires: cross-gcc-aarch64 = %{version}-%{release} +BuildRequires: sysroot-aarch64-el9-glibc >= 2.34 +BuildRequires: cross-binutils-aarch64 >= 2.35 +%endif +# ??? Otherwise this subpackage couldn't be installed, depends on libm.so +# and libgcc_s.so +AutoReqProv: no + +%description -n cross-gcc-c++-aarch64 +This package contains a version of g++ that can compile code for AArch64 +(cross compiler). This cross compiler is intended for developers to use +during application development. This cross compiler is not intended for +production use, and output binary artifacts should not be used in +production. Generated binary artifacts contain binary annotations that +mark them as cross compiled. + %prep %setup -q -n gcc-%{version}-%{DATE} -a 1 -a 2 -a 3 %patch0 -p0 -b .hack~ @@ -846,7 +898,12 @@ so that there cannot be any synchronization problems. rm -f gcc/testsuite/go.test/test/fixedbugs/issue19182.go %endif -echo 'Red Hat %{version}-%{gcc_release}' > gcc/DEV-PHASE +echo 'Red Hat %{version}-%{gcc_release}' > gcc/DEV-PHASE.native + +for crossarch in %{cross_targets}; do + echo "Red Hat %{version}-%{gcc_release} cross from $crossarch" > gcc/DEV-PHASE.$crossarch +done +cp -p gcc/DEV-PHASE{.native,} cp -a libstdc++-v3/config/cpu/i{4,3}86/atomicity.h @@ -985,10 +1042,36 @@ enablelgo=,go %if %{build_d} enableld=,d %endif -CONFIGURE_OPTS="\ +# CONFIGURE_OPTS_BASE are the configure options common to the native and cross +# builds. E.g., --prefix. This cannot include arch-specific configure options. +# CONFIGURE_OPTS_NATIVE are the configure options used for the native build +# (that is, the regular non-cross build) and libgccjit. This includes arch-specific +# configure options (default -march and such). +# CONFIGURE_OPTS = CONFIGURE_OPTS_BASE + CONFIGURE_OPTS_NATIVE +# CONFIGURE_OPTS_CROSS are the configure options common to all the cross +# builds. E.g., only build C/C++. This shall not be used for the native build. +# Each cross compiler's configure options will be: +# CONFIGURE_OPTS_BASE + CONFIGURE_OPTS_CROSS + --target= + --with-sysroot= + +# It it very important that the arch-specific configure options used in +# CONFIGURE_OPTS_NATIVE are in lockstep with the +# used in the cross builds. +CONFIGURE_OPTS_BASE="\ --prefix=%{_prefix} --mandir=%{_mandir} --infodir=%{_infodir} \ --with-bugurl=http://bugzilla.redhat.com/bugzilla \ --enable-shared --enable-threads=posix --enable-checking=release \ + --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions \ + --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only \ + --enable-plugin --enable-initfini-array \ +%if %{build_isl} + --with-isl=`pwd`/isl-install \ +%else + --without-isl \ +%endif + " + +# NB: When updating CONFIGURE_OPTS_NATIVE, make sure to update the cross +# compiler options as well (look for CONFIGURE_OPTS_FOR_ARCH). +CONFIGURE_OPTS_NATIVE="\ %ifarch ppc64le --enable-targets=powerpcle-linux \ %endif @@ -1005,16 +1088,8 @@ CONFIGURE_OPTS="\ %else --enable-multilib \ %endif - --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions \ - --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only \ %ifnarch %{mips} --with-linker-hash-style=gnu \ -%endif - --enable-plugin --enable-initfini-array \ -%if %{build_isl} - --with-isl=`pwd`/isl-install \ -%else - --without-isl \ %endif %if %{build_offload_nvptx} --enable-offload-targets=nvptx-none \ @@ -1129,6 +1204,13 @@ CONFIGURE_OPTS="\ %endif %endif " +CONFIGURE_OPTS="$CONFIGURE_OPTS_BASE $CONFIGURE_OPTS_NATIVE" + +CONFIGURE_OPTS_CROSS="\ + --enable-languages=c,c++ --disable-bootstrap --disable-libsanitizer \ + --host=%{gcc_target_platform} --build=%{gcc_target_platform} \ + --disable-multilib --disable-libstdcxx-pch --disable-libcc1 \ + " CC="$CC" CXX="$CXX" CFLAGS="$OPT_FLAGS" \ CXXFLAGS="`echo " $OPT_FLAGS " | sed 's/ -Wall / /g;s/ -fexceptions / /g' \ @@ -1169,6 +1251,49 @@ make jit.sphinx.html make jit.sphinx.install-html jit_htmldir=`pwd`/../../rpm.doc/libgccjit-devel/html cd .. +# Build cross compilers here. +%if %{build_cross} +echo ==================== BUILD CROSS ========================= +for crossarch in %{cross_targets}; do + mkdir obj-$crossarch + cd obj-$crossarch + + case $crossarch in + aarch64*) + CONFIGURE_OPTS_FOR_ARCH="" + ;; + s390x*) + CONFIGURE_OPTS_FOR_ARCH="" + ;; + ppc64le*) + CONFIGURE_OPTS_FOR_ARCH="" + ;; + *) + echo >&2 "ERROR: unknown cross arch $crossarch" + exit 1 + ;; + esac + + # Temporarily replace DEV-PHASE. + cp -p ../../gcc/DEV-PHASE{.$crossarch,} + + CC="$CC" CXX="$CXX" CFLAGS="$OPT_FLAGS" \ + CXXFLAGS="`echo " $OPT_FLAGS " | sed 's/ -Wall / /g;s/ -fexceptions / /g' \ + | sed 's/ -Wformat-security / -Wformat -Wformat-security /'`" \ + XCFLAGS="$OPT_FLAGS" TCFLAGS="$OPT_FLAGS" \ + ../../configure $CONFIGURE_OPTS_BASE $CONFIGURE_OPTS_CROSS \ + --with-sysroot=/usr/$crossarch/sys-root/el9/ \ + --target=$crossarch \ + $CONFIGURE_OPTS_FOR_ARCH + make %{?_smp_mflags} + + # Restore DEV-PHASE. + cp -p ../../gcc/DEV-PHASE{.native,} + cd .. +done +echo ==================== BUILD CROSS END ========================= +%endif + %if %{build_isl} cp -a isl-install/lib/libisl.so.15 gcc/ %endif @@ -1369,6 +1494,76 @@ make prefix=%{buildroot}%{_prefix} mandir=%{buildroot}%{_mandir} \ chmod 644 %{buildroot}%{_infodir}/gnat* %endif +%if %{build_cross} +echo ==================== INSTALL CROSS ========================= +for crossarch in %{cross_targets}; do + cd obj-$crossarch + + CROSS_LIBPATH=%{buildroot}%{_prefix}/lib/gcc/$crossarch/%{gcc_major}/ + + # Temporarily replace DEV-PHASE. + cp -p ../../gcc/DEV-PHASE{.$crossarch,} + + # Use -j1, because build-many-glibcs says: + # Parallel "make install" for GCC has race conditions that can + # cause it to fail; see + # . Such + # problems are not known for binutils, but doing the + # installation in parallel within a particular toolchain build + # (as opposed to installation of one toolchain from + # build-many-glibcs.py running in parallel to the installation + # of other toolchains being built) is not known to be + # significantly beneficial, so it is simplest just to disable + # parallel install for cross tools here. + make -j1 prefix=%{buildroot}%{_prefix} mandir=%{buildroot}%{_mandir} \ + infodir=%{buildroot}%{_infodir} install + + # Restore DEV-PHASE. + cp -p ../../gcc/DEV-PHASE{.native,} + + # Move libgomp.spec to where it belongs for %files. + mv $crossarch/libgomp/libgomp.spec $CROSS_LIBPATH + + cd .. + + echo '/* GNU ld script + Use the shared library, but some functions are only in + the static library. */ +OUTPUT_FORMAT(elf64-littleaarch64) +GROUP ( =/lib64/libgcc_s.so.1 libgcc.a )' > $CROSS_LIBPATH/libgcc_s.so + + echo '/* GNU ld script + Use the shared library from sysroot. */ +OUTPUT_FORMAT(elf64-littleaarch64) +INPUT ( =%{_prefix}/lib64/libgomp.so.1 )' > $CROSS_LIBPATH/libgomp.so + + echo '/* GNU ld script + Use the shared library from sysroot. */ +OUTPUT_FORMAT(elf64-littleaarch64) +INPUT ( =/%{_prefix}/lib64/libstdc++.so.6 )' > $CROSS_LIBPATH/libstdc++.so + + echo "/* GNU ld script + Use the static library from sysroot. */ +INPUT( =%{_prefix}/lib/gcc/$crossarch/%{gcc_major}/libstdc++.a )" > $CROSS_LIBPATH/libstdc++.a + + echo "/* GNU ld script + Use the static library from sysroot. */ +INPUT( =%{_prefix}/lib/gcc/$crossarch/%{gcc_major}/libsupc++.a )" > $CROSS_LIBPATH/libsupc++.a + + # TODO add libitm.{so,a} and libatomic.{so,a} + + # Help plugins find out nvra. + echo gcc-%{version}-%{release}.%{_arch} > $CROSS_LIBPATH/rpmver + + # TODO + # Add symlink to lto plugin in the binutils plugin directory. + #%{__mkdir_p} %{buildroot}%{_libdir}/bfd-plugins/ + #ln -s ../../libexec/gcc/$crossarch/%{gcc_major}/liblto_plugin.so \ + # %{buildroot}%{_libdir}/$crossarch/bfd-plugins/ +done +echo ==================== INSTALL CROSS END ========================= +%endif + FULLPATH=%{buildroot}%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_major} FULLEPATH=%{buildroot}%{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_major} @@ -3272,7 +3467,52 @@ end %{ANNOBIN_GCC_PLUGIN_DIR}/gcc-annobin.so.0 %{ANNOBIN_GCC_PLUGIN_DIR}/gcc-annobin.so.0.0.0 +%if %{build_cross} +%files -n cross-gcc-aarch64 +%{_prefix}/bin/aarch64-redhat-linux-cpp +%{_prefix}/bin/aarch64-redhat-linux-gcc +%{_prefix}/bin/aarch64-redhat-linux-gcc-%{gcc_major} +%{_prefix}/bin/aarch64-redhat-linux-gcc-ar +%{_prefix}/bin/aarch64-redhat-linux-gcc-nm +%{_prefix}/bin/aarch64-redhat-linux-gcc-ranlib +%{_prefix}/bin/aarch64-redhat-linux-gcov* +%{_prefix}/bin/aarch64-redhat-linux-lto-dump +%{_prefix}/libexec/gcc/aarch64-redhat-linux/%{gcc_major}/cc1 +%{_prefix}/libexec/gcc/aarch64-redhat-linux/%{gcc_major}/collect2 +%{_prefix}/libexec/gcc/aarch64-redhat-linux/%{gcc_major}/lto1 +%{_prefix}/libexec/gcc/aarch64-redhat-linux/%{gcc_major}/lto-wrapper +%{_prefix}/libexec/gcc/aarch64-redhat-linux/%{gcc_major}/liblto_plugin.so +%dir %{_prefix}/lib/gcc +%dir %{_prefix}/lib/gcc/aarch64-redhat-linux +%dir %{_prefix}/lib/gcc/aarch64-redhat-linux/%{gcc_major} +%dir %{_prefix}/lib/gcc/aarch64-redhat-linux/%{gcc_major}/include +%{_prefix}/lib/gcc/aarch64-redhat-linux/%{gcc_major}/crt*.o +%{_prefix}/lib/gcc/aarch64-redhat-linux/%{gcc_major}/libgcc.a +%{_prefix}/lib/gcc/aarch64-redhat-linux/%{gcc_major}/libgcc_eh.a +%{_prefix}/lib/gcc/aarch64-redhat-linux/%{gcc_major}/libgcov.a +%{_prefix}/lib/gcc/aarch64-redhat-linux/%{gcc_major}/include/*.h +%{_prefix}/lib/gcc/aarch64-redhat-linux/%{gcc_major}/rpmver +# These are here for ld(1) purposes only. +%{_prefix}/lib/gcc/aarch64-redhat-linux/%{gcc_major}/libgcc_s.so +%{_prefix}/lib/gcc/aarch64-redhat-linux/%{gcc_major}/libgomp.so +%{_prefix}/lib/gcc/aarch64-redhat-linux/%{gcc_major}/libgomp.spec + +%files -n cross-gcc-c++-aarch64 +%{_prefix}/bin/aarch64-redhat-linux-c++ +%{_prefix}/bin/aarch64-redhat-linux-g++ +%{_prefix}/libexec/gcc/aarch64-redhat-linux/%{gcc_major}/cc1plus +%{_prefix}/libexec/gcc/aarch64-redhat-linux/%{gcc_major}/g++-mapper-server +# For ld(1) purposes only. +%{_prefix}/lib/gcc/aarch64-redhat-linux/%{gcc_major}/libstdc++.so +%{_prefix}/lib/gcc/aarch64-redhat-linux/%{gcc_major}/libstdc++.a +%{_prefix}/lib/gcc/aarch64-redhat-linux/%{gcc_major}/libsupc++.a +%dnl build_cross +%endif + %changelog +* Tue Dec 13 2022 Marek Polacek 11.3.1-4.1 +- add cross compiler functionality for non-production uses (#2149650) + * Tue Nov 22 2022 Marek Polacek 11.3.1-4 - update from releases/gcc-11-branch (#2117632) - PRs analyzer/105252, analyzer/105365, analyzer/105366, c++/65211,