Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build Failure - Configure script incorrectly parses gcc's output when it has quotes #20606

Closed
VA1DER opened this issue Dec 11, 2022 · 9 comments · Fixed by #20750
Closed

Build Failure - Configure script incorrectly parses gcc's output when it has quotes #20606

VA1DER opened this issue Dec 11, 2022 · 9 comments · Fixed by #20750

Comments

@VA1DER
Copy link
Contributor

VA1DER commented Dec 11, 2022

Description
The perl source's Configure script fails when the output of gcc -v contains entries that are enclosed in quotation marks.

When Configure is run, prior to building perl, one of the checks it performs is determining pre-defined compiler flags. One way it does this is to run gcc -v and parse its output. However it is possible when gcc is built to have passed it configuration options in such a way as its gcc will produce output that has single quotes. For example:

# gcc -v
Using built-in specs.
COLLECT_GCC=/usr/bin/arm-openwrt-linux-muslgnueabi-gcc_orig
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-openwrt-linux-muslgnueabi/11.2.0/lto-wrapper
Target: arm-openwrt-linux-muslgnueabi
Configured with: /builder/shared-workdir/build/sdk/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/gcc-11.2.0/configure --target=arm-openwrt-linux --host=arm-openwrt-linux --build=x86_64-pc-linux-gnu --program-prefix= --program-suffix= --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib --sysconfdir=/etc --datadir=/usr/share --localstatedir=/var --mandir=/usr/man --infodir=/usr/info --disable-nls 'CXXFLAGS_FOR_TARGET=-g -O2 -D_GLIBCXX_INCLUDE_NEXT_C_HEADERS' --build=x86_64-pc-linux-gnu --host=arm-openwrt-linux-muslgnueabi --target=arm-openwrt-linux-muslgnueabi --enable-languages=c,c++ --with-bugurl=https://dev.openwrt.org/ --with-pkgversion='OpenWrt GCC 11.2.0' --enable-shared --disable-__cxa_atexit --with-default-libstdcxx-abi=gcc4-compatible --enable-target-optspace --with-gnu-ld --disable-nls --disable-libsanitizer --disable-libvtv --disable-libcilkrts --disable-libmudflap --disable-libmpx --disable-multilib --disable-libgomp --disable-libquadmath --disable-libssp --disable-decimal-float --disable-libstdcxx-pch --with-host-libstdcxx=-lstdc++ --prefix=/usr --libexecdir=/usr/lib --with-local-prefix=/usr --with-stage1-ldflags=-lstdc++ --with-float=hard
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (OpenWrt GCC 11.2.0) 

Note the single quotes starting at CXXFLAGS_FOR_TARGET and ending at -D_GLIBCXX_INCLUDE_NEXT_C_HEADERS

This causes Configure to pass on a single quote into config.sh, which creates mis-matched quotes with predictable results. For example the above output from gcc -v makes the following line in the resulting config.sh
ccsymbols='_GLIBCXX_INCLUDE_NEXT_C_HEADERS'=1'

The resulting mismatched quotes cause problems with everything that tries to invoke config.sh

Affected systems include OpenWrt and any other device using ENTWARE as its package system.

Steps to Reproduce
On an affected system:

  1. wget https://www.cpan.org/src/5.0/perl-5.37.6.tar.gz
  2. tar -xvzf perl-5.37.6.tar.gz
  3. cd perl-5.37.6
  4. ./Configure

Expected behavior
Should configure properly

Perl configuration
N/A

Patch
The following patch (made against Configure itself) will strip quotes from the output of "gcc -v" before further processing:

--- Configure.orig	2022-11-14 14:52:18.000000000 -0400
+++ Configure	2022-12-11 16:47:27.642795981 -0400
@@ -23770,11 +23770,11 @@
 extern int foo;
 EOF
 for i in \`$cc -v -c tmp.c 2>&1 $postprocess_cc_v\`
 do
 	case "\$i" in
-	-D*) echo "\$i" | $sed 's/^-D//';;
+	-D*) echo "\$i" | $sed 's/^-D//;s/['\''\"]//g';;
 	-A*) $test "$gccversion" && echo "\$i" | $sed 's/^-A//' | $sed 's/\(.*\)(\(.*\))/\1=\2/';;
 	esac
 done
 $rm_try
 EOS
@jkeenan
Copy link
Contributor

jkeenan commented Dec 12, 2022

@Tux, can you take a look at this ticket? Thanks.

@Tux
Copy link
Contributor

Tux commented Dec 12, 2022

Ooooooh, slippery slope …
Removing the quotes will "break" quoted combinations, so a single -D'foo bar' will result in two arguments -Dfoo and bar. I have no idea if this change will have action at a distance.

@VA1DER
Copy link
Contributor Author

VA1DER commented Dec 13, 2022

Removing the quotes will "break" quoted combinations

There is already no support for quoted combinations in the Configure script. If gcc -v produced...

a single -D'foo bar'

...then the ccsym helper script that Configure makes would create the result -D'foo and no bar at all.

I'm not sure that quotes are useful in -D gcc definitions. Can you have a space separated #define identifier? In any case, as quotes have no valid effect now and never did (Configure just treats the output of gcc -v as a space-separated list and then parses it that way), perhaps it's best to just filter them out.

@Tux
Copy link
Contributor

Tux commented Jan 20, 2023

I just built perl-5.37.8 on DSM-7.1 and I also needed this PR

I'd say to merge and see what the other smokers find of it.
Backporting can be done later

@khwilliamson
Copy link
Contributor

@VA1DER please turn this into an official Pull Request, and I will apply it to see what happens

demerphq pushed a commit that referenced this issue Jan 29, 2023
This patch was submitted in GH issue #20606. When gcc output contains
quoted elements we fail to handle it properly. This tweaks the sed
command to do so.
demerphq pushed a commit that referenced this issue Jan 29, 2023
This patch was submitted in GH issue #20606. When gcc output contains
quoted elements we fail to handle it properly. This tweaks the sed
command to do so.

Fixes #20606.
@demerphq
Copy link
Collaborator

@VA1DER please review #20750 and check if your email address is correct.

@khwilliamson I have pushed it myself.

demerphq pushed a commit that referenced this issue Jan 30, 2023
This patch was submitted in GH issue #20606. When gcc output contains
quoted elements we fail to handle it properly. This tweaks the sed
command to do so.

Fixes #20606.
@VA1DER
Copy link
Contributor Author

VA1DER commented Jan 30, 2023

My only concern is this, from the header for the Configure script this patches:

# Note: this Configure script was generated automatically by the tool
# called "metaconfig". Rather than working with this copy of Configure,
# you should use metaconfig. Perl uses a modified version of this
# tool, and this, together with the metaconfig units, are available
# in the git repository:
#    $ git clone https://github.com/perl5-metaconfig/metaconfig metaconfig
# The original dist package (including metaconfig) is available on github:
#    $ git clone https://github.com/rmanfredi/dist.git dist-git
#
# Though this script was generated by metaconfig from metaunits, it is
# OK to send patches against Configure itself (but not to commit them
# to blead). It's up to
# the Configure maintainers to backport the patch to the metaunits if it
# is accepted. Exceptions to this rule, and more information, is in
# Porting/pumpkin.pod.

@khwilliamson
Copy link
Contributor

khwilliamson commented Jan 30, 2023 via email

@Tux
Copy link
Contributor

Tux commented Feb 6, 2023

Now handled with :)

pjacklam pushed a commit to pjacklam/perl5 that referenced this issue May 20, 2023
This patch was submitted in GH issue Perl#20606. When gcc output contains
quoted elements we fail to handle it properly. This tweaks the sed
command to do so.

Fixes Perl#20606.
pjacklam pushed a commit to pjacklam/perl5 that referenced this issue May 20, 2023
This patch was submitted in GH issue Perl#20606. When gcc output contains
quoted elements we fail to handle it properly. This tweaks the sed
command to do so.

Fixes Perl#20606.
khwilliamson pushed a commit to khwilliamson/perl5 that referenced this issue Jul 10, 2023
This patch was submitted in GH issue Perl#20606. When gcc output contains
quoted elements we fail to handle it properly. This tweaks the sed
command to do so.

Fixes Perl#20606.
khwilliamson pushed a commit to khwilliamson/perl5 that referenced this issue Jul 28, 2023
This patch was submitted in GH issue Perl#20606. When gcc output contains
quoted elements we fail to handle it properly. This tweaks the sed
command to do so.

Fixes Perl#20606.

Backport of 85d2c8e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants