Patchwork bash vs. dash: Avoid unportable shell feature in gcc/configure.ac

login
register
mail settings
Submitter Thomas Schwinge
Date July 13, 2011, 4:13 p.m.
Message ID <87mxgi5fch.fsf@kepler.schwinge.homeip.net>
Download mbox | patch
Permalink /patch/104555/
State Superseded, archived
Headers show

Comments

Thomas Schwinge - July 13, 2011, 4:13 p.m.
Hallo!

Diffing the make log of a build of GCC with SHELL not explicitly set
(thus /bin/sh, which is bash) and one with SHELL=/bin/dash, I found the
following unexpected difference:

    -checking assembler for eh_frame optimization... yes
    +checking assembler for eh_frame optimization... buggy

This is from gcc/configure; which invokes
acinclude.m4:gcc_GAS_CHECK_FEATURE for the ``eh_frame optimization''
check.

Latter case, gcc/config.log:

    configure:22282: checking assembler for eh_frame optimization
    configure:22327: /usr/bin/as --32  -o conftest.o conftest.s >&5
    conftest.s: Assembler messages:
    conftest.s: Warning: end of file in string; '"' inserted
    conftest.s:13: Warning: unterminated string; newline inserted

There, the following happens:

    $ sh # This is bash.
    sh-4.1$ echo '.ascii "z\0"'
    .ascii "z\0"

This is what GCC expects.  However, with dash:

    $ dash
    $ echo '.ascii "z\0"'
    .ascii "z

The backslash escape and everything after is cut off.

The test in gcc/configure.ac:

    gcc_GAS_CHECK_FEATURE(eh_frame optimization, gcc_cv_as_eh_frame,
      [elf,2,12,0],,
    [	.text
    [...]
    	.byte	0x1
    	.ascii "z\0"
    	.byte	0x1
    [...]

As quickly determined in #gcc with Ian's and Ismail's help, this is
unportable usage of the echo builtin (and also at least questionable for
/bin/echo), so I'm suggesting the following simple fix:

	gcc/
	* configure.ac (eh_frame optimization): Avoid unportable shell feature.


Alternatively, gcc_GAS_CHECK_FEATURE could be changed to emit the
temporary file by using a shell here-doc, which is what AC_TRY_COMPILE is
doing, for example.


Grüße,
 Thomas
Paolo Bonzini - July 13, 2011, 4:23 p.m.
On 07/13/2011 06:13 PM, Thomas Schwinge wrote:
> Alternatively, gcc_GAS_CHECK_FEATURE could be changed to emit the
> temporary file by using a shell here-doc, which is what AC_TRY_COMPILE is
> doing, for example.

Change instead echo ifelse(...) > conftest.s to

   AS_ECHO([m4_if(...)]) > conftest.s

in gcc_GAS_CHECK_FEATURE.

Paolo

Patch

diff --git a/gcc/configure.ac b/gcc/configure.ac
index c2163bf..73f0209 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -2538,7 +2538,7 @@  __FRAME_BEGIN__:
 .LSCIE1:
 	.4byte	0x0
 	.byte	0x1
-	.ascii "z\0"
+	.asciz "z"
 	.byte	0x1
 	.byte	0x78
 	.byte	0x1a