11.3.1-4.3

Compile the cross binaries as PIE/-z now

Resolves: #2155452
This commit is contained in:
Marek Polacek 2022-12-21 14:51:59 -05:00
parent c8c6d760a7
commit 9e2005ad2a

View File

@ -128,7 +128,7 @@
Summary: Various compilers (C, C++, Objective-C, ...) Summary: Various compilers (C, C++, Objective-C, ...)
Name: gcc Name: gcc
Version: %{gcc_version} Version: %{gcc_version}
Release: %{gcc_release}.2%{?dist} Release: %{gcc_release}.3%{?dist}
# libgcc, libgfortran, libgomp, libstdc++ and crtstuff have # libgcc, libgfortran, libgomp, libstdc++ and crtstuff have
# GCC Runtime Exception. # GCC Runtime Exception.
License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD
@ -1206,6 +1206,7 @@ CONFIGURE_OPTS_CROSS="\
--enable-languages=c,c++ --disable-bootstrap --disable-libsanitizer \ --enable-languages=c,c++ --disable-bootstrap --disable-libsanitizer \
--host=%{gcc_target_platform} --build=%{gcc_target_platform} \ --host=%{gcc_target_platform} --build=%{gcc_target_platform} \
--disable-multilib --disable-libstdcxx-pch --disable-libcc1 \ --disable-multilib --disable-libstdcxx-pch --disable-libcc1 \
--enable-host-pie --enable-host-bind-now \
" "
CC="$CC" CXX="$CXX" CFLAGS="$OPT_FLAGS" \ CC="$CC" CXX="$CXX" CFLAGS="$OPT_FLAGS" \
@ -1250,6 +1251,8 @@ cd ..
# Build cross compilers here. # Build cross compilers here.
%if %{build_cross} %if %{build_cross}
echo ==================== BUILD CROSS ========================= echo ==================== BUILD CROSS =========================
# Get out of obj-%{gcc_target_platform}.
pushd ..
for crossarch in %{cross_targets}; do for crossarch in %{cross_targets}; do
mkdir obj-$crossarch mkdir obj-$crossarch
cd obj-$crossarch cd obj-$crossarch
@ -1271,23 +1274,26 @@ for crossarch in %{cross_targets}; do
esac esac
# Temporarily replace DEV-PHASE. # Temporarily replace DEV-PHASE.
cp -p ../../gcc/DEV-PHASE{.cross,} cp -p ../gcc/DEV-PHASE{.cross,}
CC="$CC" CXX="$CXX" CFLAGS="$OPT_FLAGS" \ CC="$CC" CXX="$CXX" CFLAGS="$OPT_FLAGS" \
CXXFLAGS="`echo " $OPT_FLAGS " | sed 's/ -Wall / /g;s/ -fexceptions / /g' \ CXXFLAGS="`echo " $OPT_FLAGS " | sed 's/ -Wall / /g;s/ -fexceptions / /g' \
| sed 's/ -Wformat-security / -Wformat -Wformat-security /'`" \ | sed 's/ -Wformat-security / -Wformat -Wformat-security /'`" \
XCFLAGS="$OPT_FLAGS" TCFLAGS="$OPT_FLAGS" \ XCFLAGS="$OPT_FLAGS" TCFLAGS="$OPT_FLAGS" \
../../configure $CONFIGURE_OPTS_BASE $CONFIGURE_OPTS_CROSS \ ../configure $CONFIGURE_OPTS_BASE $CONFIGURE_OPTS_CROSS \
--with-sysroot=/usr/$crossarch/sys-root/el9/ \ --with-sysroot=/usr/$crossarch/sys-root/el9/ \
--with-gxx-include-dir="/usr/$crossarch/sys-root/el9/%{_prefix}/include/c++/%{gcc_major}" \ --with-gxx-include-dir="/usr/$crossarch/sys-root/el9/%{_prefix}/include/c++/%{gcc_major}" \
--target=$crossarch \ --target=$crossarch \
$CONFIGURE_OPTS_FOR_ARCH $CONFIGURE_OPTS_FOR_ARCH
make %{?_smp_mflags} make %{?_smp_mflags} LDFLAGS_FOR_TARGET=-Wl,-z,relro,-z,now
# Restore DEV-PHASE. # Restore DEV-PHASE.
cp -p ../../gcc/DEV-PHASE{.native,} cp -p ../gcc/DEV-PHASE{.native,}
# Out of obj-$crossarch.
cd .. cd ..
done done
# Go back to obj-%{gcc_target_platform}.
popd
echo ==================== BUILD CROSS END ========================= echo ==================== BUILD CROSS END =========================
%endif %endif
@ -1493,25 +1499,27 @@ chmod 644 %{buildroot}%{_infodir}/gnat*
%if %{build_cross} %if %{build_cross}
echo ==================== INSTALL CROSS ========================= echo ==================== INSTALL CROSS =========================
# Our of obj-%{gcc_target_platform}.
pushd ..
for crossarch in %{cross_targets}; do for crossarch in %{cross_targets}; do
cd obj-$crossarch cd obj-$crossarch
CROSS_LIBPATH=%{buildroot}%{_prefix}/lib/gcc/$crossarch/%{gcc_major}/ CROSS_LIBPATH=%{buildroot}%{_prefix}/lib/gcc/$crossarch/%{gcc_major}/
# Temporarily replace DEV-PHASE. # Temporarily replace DEV-PHASE.
cp -p ../../gcc/DEV-PHASE{.cross,} cp -p ../gcc/DEV-PHASE{.cross,}
# --with-gxx-include-dir= doesn't prefix its argument with $(DESTDIR) # --with-gxx-include-dir= doesn't prefix its argument with $(DESTDIR)
# and you can't install things into /usr unless you're root. # and you can't install things into /usr unless you're root.
mkdir scratch mkdir scratch
scratchdir=`pwd`/scratch scratchdir=`pwd`/scratch
cd $crossarch/libstdc++-v3 pushd $crossarch/libstdc++-v3
for i in `find . -name Makefile`; do for i in `find . -name Makefile`; do
cp -a $i $i.save cp -a $i $i.save
sed -i -e 's?^gxx_include_dir = .*$?gxx_include_dir = '$scratchdir'?' $i sed -i -e 's?^gxx_include_dir = .*$?gxx_include_dir = '$scratchdir'?' $i
touch -r $i.save $i touch -r $i.save $i
done done
cd ../.. popd
# Use -j1, because build-many-glibcs says: # Use -j1, because build-many-glibcs says:
# Parallel "make install" for GCC has race conditions that can # Parallel "make install" for GCC has race conditions that can
@ -1528,14 +1536,14 @@ for crossarch in %{cross_targets}; do
infodir=%{buildroot}%{_infodir} install infodir=%{buildroot}%{_infodir} install
# Restore DEV-PHASE. # Restore DEV-PHASE.
cp -p ../../gcc/DEV-PHASE{.native,} cp -p ../gcc/DEV-PHASE{.native,}
# Restore Makefiles with the old gxx_include_dir. # Restore Makefiles with the old gxx_include_dir.
cd $crossarch/libstdc++-v3 pushd $crossarch/libstdc++-v3
for i in `find . -name Makefile`; do for i in `find . -name Makefile`; do
mv -f $i.save $i mv -f $i.save $i
done done
cd ../.. popd
# We're not shipping C++ headers; nuke 'em. # We're not shipping C++ headers; nuke 'em.
rm -rf $scratchdir rm -rf $scratchdir
@ -1604,6 +1612,8 @@ INPUT( =%{_prefix}/lib/gcc/$crossarch/%{gcc_major}/libitm.a )" > $CROSS_LIBPATH/
#ln -s ../../libexec/gcc/$crossarch/%{gcc_major}/liblto_plugin.so \ #ln -s ../../libexec/gcc/$crossarch/%{gcc_major}/liblto_plugin.so \
# %{buildroot}%{_libdir}/$crossarch/bfd-plugins/ # %{buildroot}%{_libdir}/$crossarch/bfd-plugins/
done done
# Back to obj-%{gcc_target_platform}.
popd
echo ==================== INSTALL CROSS END ========================= echo ==================== INSTALL CROSS END =========================
%endif %endif
@ -3562,6 +3572,9 @@ end
%endif %endif
%changelog %changelog
* Wed Dec 21 2022 Marek Polacek <polacek@redhat.com> 11.3.1-4.3
- compile the cross binaries as PIE/-z now (#2155452)
* Mon Dec 19 2022 Marek Polacek <polacek@redhat.com> 11.3.1-4.2 * Mon Dec 19 2022 Marek Polacek <polacek@redhat.com> 11.3.1-4.2
- ship libitm.spec in cross-gcc (#2154462) - ship libitm.spec in cross-gcc (#2154462)