Non-portable echo usage in sysdeps/unix/make-syscalls.sh

Message ID 20150214090556.GA9442@stranger.qboosh.pl
State Committed
Headers

Commit Message

Jakub Bogusz Feb. 14, 2015, 9:05 a.m. UTC
  Hello,

Some paths of make-syscalls.sh script use echo in a way specific to
bash or echo from GNU coreutils, expecting not to interpret escape
sequences by default.
It's contrary to what POSIX specs say and the way that echo from
some other shells (like ksh or dash) works (escape sequences are
always interpreted or are interpreted by default).

The attached patch is a try to fix the problem by avoiding non
portable cases.
  

Comments

Joseph Myers Feb. 14, 2015, 5:34 p.m. UTC | #1
On Sat, 14 Feb 2015, Jakub Bogusz wrote:

> Hello,
> 
> Some paths of make-syscalls.sh script use echo in a way specific to
> bash or echo from GNU coreutils, expecting not to interpret escape
> sequences by default.
> It's contrary to what POSIX specs say and the way that echo from
> some other shells (like ksh or dash) works (escape sequences are
> always interpreted or are interpreted by default).

Problems building with dash are bug 16704, so include [BZ #16704] in the 
ChangeLog entry.  Is this a complete fix (if so, the bug number would also 
go in NEWS when committing and then the bug would be closed), or does it 
just fix one of several issues building with dash?
  
Jakub Bogusz July 16, 2015, 4:10 p.m. UTC | #2
On Sat, Feb 14, 2015 at 05:34:09PM +0000, Joseph Myers wrote:
> On Sat, 14 Feb 2015, Jakub Bogusz wrote:
> 
> > Hello,
> > 
> > Some paths of make-syscalls.sh script use echo in a way specific to
> > bash or echo from GNU coreutils, expecting not to interpret escape
> > sequences by default.
> > It's contrary to what POSIX specs say and the way that echo from
> > some other shells (like ksh or dash) works (escape sequences are
> > always interpreted or are interpreted by default).
> 
> Problems building with dash are bug 16704, so include [BZ #16704] in the 
> ChangeLog entry.  Is this a complete fix (if so, the bug number would also 
> go in NEWS when committing and then the bug would be closed), or does it 
> just fix one of several issues building with dash?

I didn't test build with dash; this patch is sufficient to build glibc
2.21 on x86/x86_64/x32 archs using mksh or pdksh as /bin/sh.
  

Patch

--- glibc-2.20/sysdeps/unix/make-syscalls.sh.orig	2014-09-07 10:09:09.000000000 +0200
+++ glibc-2.20/sysdeps/unix/make-syscalls.sh	2014-12-21 17:54:48.973388216 +0100
@@ -276,28 +276,33 @@ 
     vdso_symbol="${vdso_syscall%@*}"
     vdso_symver="${vdso_syscall#*@}"
     vdso_symver=`echo "$vdso_symver" | sed 's/\./_/g'`
-    echo "\
+    cat <<EOF
+
 \$(foreach p,\$(sysd-rules-targets),\$(objpfx)\$(patsubst %,\$p,$file).os): \\
-		\$(..)sysdeps/unix/make-syscalls.sh\
+		\$(..)sysdeps/unix/make-syscalls.sh
 	\$(make-target-directory)
 	(echo '#include <dl-vdso.h>'; \\
-	 echo 'extern void *${strong}_ifunc (void) __asm (\"${strong}\");'; \\
+	 echo 'extern void *${strong}_ifunc (void) __asm ("${strong}");'; \\
 	 echo 'void *'; \\
 	 echo '${strong}_ifunc (void)'; \\
 	 echo '{'; \\
 	 echo '  PREPARE_VERSION_KNOWN (symver, ${vdso_symver});'; \\
-	 echo '  return _dl_vdso_vsym (\"${vdso_symbol}\", &symver);'; \\
+	 echo '  return _dl_vdso_vsym ("${vdso_symbol}", &symver);'; \\
 	 echo '}'; \\
-	 echo 'asm (\".type ${strong}, %gnu_indirect_function\");'; \\"
+	 echo 'asm (".type ${strong}, %gnu_indirect_function");'; \\
+EOF
     # This is doing "libc_hidden_def (${strong})", but the compiler
     # doesn't know that we've defined ${strong} in the same file, so
     # we can't do it the normal way.
-    echo "\
-	 echo 'asm (\".globl __GI_${strong}\\n\"'; \\
-	 echo '     \"__GI_${strong} = ${strong}\");'; \\"
+    cat <<EOF
+	 echo 'asm (".globl __GI_${strong}");'; \\
+	 echo 'asm ("__GI_${strong} = ${strong}");'; \\
+EOF
     emit_weak_aliases
-    echo '	) | $(compile-stdin.c) '"\
-\$(foreach p,\$(patsubst %$file,%,\$(basename \$(@F))),\$(\$(p)CPPFLAGS))"
+    cat <<EOF
+	) | \$(compile-stdin.c) \
+\$(foreach p,\$(patsubst %$file,%,\$(basename \$(@F))),\$(\$(p)CPPFLAGS))
+EOF
   fi
 
   if test $shared_only = t; then