From ac3c099a82ddf6c98eab39db95c31e7d7db5e7df Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Mon, 23 Sep 2024 22:58:46 -0400 Subject: [PATCH] sys-libs/libstdc++-v3: disable custom user flags entirely This is ancient brittle code -- an ancient, unmaintained version of GCC. It exists solely to provide access to an ancient, unmaintained version of libstdc++.so for ancient, unmaintained binaries that cannot be rebuilt. It doesn't need to be fast, or have cool CFLAGS. People shouldn't even be using it at all. The people who do use it care about compatibility more than anything else, so successfully compiling it should be taken as the gift that it is. With that in mind, we basically strip all flags. We preserve some existing logic to handle -march= values known to exist in this old gcc, and we continue to support -O levels, but we go no further. It's entirely impractical to support arbitrary flags, since every gcc release adds more flags that old versions don't support and then this fails because GCC 3's internal xgcc build cannot handle them. We also take this opportunity to add a workaround for modern C. New versions of GCC barf on some of the code here because it is not legal C99, but again, the point of this package is to provide legacy compatibility for ancient binaries, so... we assume if it ever worked before, it still works. :) Thus, suppress the errors. In order to suppress the errors, we make a wrapper script around the external compiler (not the xgcc one) so that we can apply flags that only affect modern compilers, and aren't parsed by xgcc which would choke on them due to those flags being too new. Closes: https://bugs.gentoo.org/879775 Closes: https://bugs.gentoo.org/919184 Closes: https://bugs.gentoo.org/832016 Closes: https://bugs.gentoo.org/923112 Signed-off-by: Eli Schwartz --- .../libstdc++-v3/libstdc++-v3-3.3.6-r4.ebuild | 73 +++++++++---------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/sys-libs/libstdc++-v3/libstdc++-v3-3.3.6-r4.ebuild b/sys-libs/libstdc++-v3/libstdc++-v3-3.3.6-r4.ebuild index 7c20c65248791..9ebe0e98eb7ec 100644 --- a/sys-libs/libstdc++-v3/libstdc++-v3-3.3.6-r4.ebuild +++ b/sys-libs/libstdc++-v3/libstdc++-v3-3.3.6-r4.ebuild @@ -70,11 +70,13 @@ is_arch_allowed() { } do_filter_flags() { - declare setting + declare setting newflags # In general gcc does not like optimization, and add -O2 where # it is safe. This is especially true for gcc 3.3 + 3.4 - replace-flags -O? -O2 + if is-flagq -O?; then + newflags+=" -O2" + fi # gcc 3.3 doesn't support -mtune on numerous archs, so xgcc will fail setting="`get-flag mtune`" @@ -90,47 +92,28 @@ do_filter_flags() { transform_known_flags setting="`get-flag march`" if [[ ! -z "${setting}" ]] ; then - is_arch_allowed "${setting}" || filter-flags -march="${setting}" + is_arch_allowed "${setting}" && newflags+=" -march=${setting}" fi setting="`get-flag mcpu`" if [[ ! -z "${setting}" ]] ; then - is_arch_allowed "${setting}" || filter-flags -mcpu="${setting}" + is_arch_allowed "${setting}" && newflags+=" -mcpu=${setting}" fi - # xgcc wont understand gcc 3.4 flags... - filter-flags -fno-unit-at-a-time - filter-flags -funit-at-a-time - filter-flags -fweb - filter-flags -fno-web - filter-flags -mno-tls-direct-seg-refs + # There is lots of brittle old code that violates the aliasing rules. GCC + # 3.3 supports disabling this optimization. + newflags+=" -fno-strict-aliasing" - # xgcc isnt patched with propolice - filter-flags -fstack-protector-all - filter-flags -fno-stack-protector-all - filter-flags -fstack-protector - filter-flags -fno-stack-protector - - # xgcc isnt patched with the gcc symbol visibility patch - filter-flags -fvisibility-inlines-hidden - filter-flags -fvisibility=hidden - - # Bug #269433 & #290202 - filter-flags -fno-strict-overflow - filter-flags -fstrict-overflow - - # Bug #442784 - filter-flags '-W*' - - filter-flags -frecord-gcc-switches - filter-flags '-fdiagnostics-color*' - - # Bug #610064 - filter-flags '-fstack-check*' - - # ...sure, why not? - strip-unsupported-flags - - strip-flags + # xgcc wont understand gcc 3.4 flags... in fact it won't understand most + # things or have most patches, regardless of what the real GCC understands. + # A random collection of bugs: + # #269433 #290202 #442784 #610064 #879775 #919184 #832016 + # + # There's some extensive discussion at bug #923112, ultimately the only + # practical approach is to simply reject *all* flags unless we handpicked + # them to allow them. Check in "${S}"/gcc/doc/gcc.1 before proceeding. + export CFLAGS="${newflags}" + export CXXFLAGS="${newflags}" + unset LDFLAGS } S=${WORKDIR}/gcc-${PV} @@ -153,6 +136,22 @@ src_prepare() { fi tc-export AR CC RANLIB NM + + # newer versions of GCC add default werrors that we need to disable for + # this very old and brittle code. But adding it to CFLAGS doesn't work, + # since GCC creates xgcc and uses that to compile libstdc++, and the + # ancient xgcc doesn't understand the flags we need. + mkdir "${T}/conservative-compiler" || die + export PATH="${$}/conservative-compiler:${PATH}" + + local realcc=$(type -P "${CC}") || die + export CC="${T}/conservative-compiler/${CC##*/}" + cat > "${CC}" <<- __EOF__ || die + #!/bin/sh + "${realcc}" -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=int-conversion -Wno-error=incompatible-pointer-types "\$@" + __EOF__ + + chmod +x "${CC}" || die } src_configure() {