dash 0.5.13.1: problems with dash as /bin/sh on ARM64
We are using dash 0.5.13.1 as /bin/sh and running into several build problems on ARM64, for example curl:
...
+ make
Making all in lib
make[1]: Entering directory '/home/pkgmk/work/curl/src/curl-8.16.0/lib' make all-am
make[2]: Entering directory '/home/pkgmk/work/curl/src/curl-8.16.0/lib'
CC libcurl_la-altsvc.lo CC libcurl_la-amigaos.lo CC libcurl_la-asyn-ares.lo CC libcurl_la-asyn-base.lo CC libcurl_la-asyn-thrdd.lo
../libtool: 371: Syntax error: "}" unexpected
make[2]: *** [Makefile:2400: libcurl_la-altsvc.lo] Error 2 make[2]: *** Waiting for unfinished jobs....
CC libcurl_la-bufq.lo
../libtool: 371: Syntax error: "}" unexpected
make[2]: *** [Makefile:2407: libcurl_la-amigaos.lo] Error 2 ../libtool: 371: Syntax error: "}" unexpected
make[2]: *** [Makefile:2414: libcurl_la-asyn-ares.lo] Error 2 ../libtool: 371: Syntax error: "}" unexpected
CC libcurl_la-bufref.lo
make[2]: *** [Makefile:2421: libcurl_la-asyn-base.lo] Error 2 ../libtool: 371: Syntax error: "}" unexpected
make[2]: *** [Makefile:2428: libcurl_la-asyn-thrdd.lo] Error 2 ../libtool: 371: Syntax error: "}" unexpected
make[2]: *** [Makefile:2435: libcurl_la-bufq.lo] Error 2 ../libtool: 371: Syntax error: "}" unexpected
make[2]: *** [Makefile:2442: libcurl_la-bufref.lo] Error 2 make[2]: Leaving directory '/home/pkgmk/work/curl/src/curl-8.16.0/lib' make[1]: *** [Makefile:1658: all] Error 2
make[1]: Leaving directory '/home/pkgmk/work/curl/src/curl-8.16.0/lib'
make: *** [Makefile:620: all-recursive] Error 1
=======> ERROR: Building '/home/pkgmk/pkg/curl#8.16.0-1.pkg.tar.xz' failed.
similar errors for libuv, libpcre2 and probably others. On x86_64 everything woks fine. Here's a diff between the libtool file created with x86_64 and ARM64:
tmp/libtool_arm64 renamed from tmp/libtool +10 -10
@@ -56,7 +56,7 @@ build_old_libs=yes # What type of objects to build. -pic_mode=yes +pic_mode=default # Whether or not to optimize for fast installation. fast_install=yes
@@ -68,19 +68,19 @@ SHELL="/bin/sh" # An echo program that protects backslashes. -ECHO="printf %s\\n" +ECHO="printf %s\n" # The PATH separator for the build system. PATH_SEPARATOR=":" # The host system. host_alias= -host=x86_64-pc-linux-gnu +host=aarch64-unknown-linux-gnu host_os=linux-gnu # The build system. build_alias= -build=x86_64-pc-linux-gnu +build=aarch64-unknown-linux-gnu build_os=linux-gnu # A sed program that does not truncate output.
@@ -117,10 +117,10 @@ lt_unset=unset # turn spaces into newlines. -SP2NL="tr \\040 \\012" +SP2NL="tr \040 \012" # turn newlines into spaces. -NL2SP="tr \\015\\012 \\040\\040" +NL2SP="tr \015\012 \040\040" # convert $build file names to $host format. to_host_file_cmd=func_convert_file_noop
@@ -135,7 +135,7 @@ deplibs_check_method="pass_all" # Command to use when deplibs_check_method = "file_magic". -file_magic_cmd="\$MAGIC_CMD" +file_magic_cmd="$MAGIC_CMD" # How to find potential files when deplibs_check_method = "file_magic". file_magic_glob=""
@@ -144,7 +144,7 @@ want_nocaseglob="no" # Command to associate shared and link libraries. -sharedlib_from_linklib_cmd="printf %s\\n" +sharedlib_from_linklib_cmd="printf %s\n" # The archiver. AR="/usr/bin/ar"
@@ -163,7 +163,7 @@ # Commands used to install an old-style archive. RANLIB="ranlib" -old_postinstall_cmds="chmod 644 \$oldlib~\$RANLIB \$tool_oldlib" +old_postinstall_cmds="chmod 644 $oldlib~$RANLIB $tool_oldlib" old_postuninstall_cmds="" # Whether to use a lock for old archive extraction.
@@ -173,22 +173,22 @@ LTCC="gcc" # LTCC compiler flags. -LTCFLAGS="-O2 -march=x86-64 -pipe -Werror-implicit-function-declaration -Wno-system-headers" +LTCFLAGS="-O2 -pipe -Werror-implicit-function-declaration -Wno-system-headers" # Take the output of nm and produce a listing of raw symbols and C
names.
-global_symbol_pipe="/bin/sed -n -e 's/^.*[ ]\\([ABCDGIRSTW][ABCDGIRSTW]*\\)[ ][ ]*\\([_A-Za-z][_A-Za-z0-9]*\\)\$/\\1 \\2 \\2/p' | /bin/sed '/ __gnu_lto/d'"
+global_symbol_pipe="/bin/sed -n -e 's/^.*[ ]\([ABCDGIRSTW][ABCDGIRSTW]*\)[ ][ ]*\([_A-Za-z][_A-Za-z0-9]*\)$/\1 \2 \2/p' | /bin/sed '/ __gnu_lto/d'"
# Transform the output of nm in a proper C declaration.
-global_symbol_to_cdecl="/bin/sed -n -e 's/^T .* \\(.*\\)\$/extern int \\1();/p' -e 's/^[ABCDGIRSTW][ABCDGIRSTW]* .* \\(.*\\)\$/extern char \\1;/p'" +global_symbol_to_cdecl="/bin/sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^[ABCDGIRSTW][ABCDGIRSTW]* .* \(.*\)$/extern char \1;/p'"
# Transform the output of nm into a list of symbols to manually
relocate.
global_symbol_to_import=""
# Transform the output of nm in a C name address pair.
-global_symbol_to_c_name_address="/bin/sed -n -e 's/^: \\(.*\\) .*\$/ {\"\\1\", (void *) 0},/p' -e 's/^[ABCDGIRSTW][ABCDGIRSTW]* .* \\(.*\\)\$/ {\"\\1\", (void *) \\&\\1},/p'" +global_symbol_to_c_name_address="/bin/sed -n -e 's/^: \(.*\) .*$/ {"\1", (void *) 0},/p' -e 's/^[ABCDGIRSTW][ABCDGIRSTW]* .* \(.*\)$/ {"\1", (void *) \&\1},/p'"
# Transform the output of nm in a C name address pair when lib prefix
is needed.
-global_symbol_to_c_name_address_lib_prefix="/bin/sed -n -e 's/^: \\(.*\\) .*\$/ {\"\\1\", (void *) 0},/p' -e 's/^[ABCDGIRSTW][ABCDGIRSTW]* .* \\(lib.*\\)\$/ {\"\\1\", (void *) \\&\\1},/p' -e 's/^[ABCDGIRSTW][ABCDGIRSTW]* .* \\(.*\\)\$/ {\"lib\\1\", (void *) \\&\\1},/p'" +global_symbol_to_c_name_address_lib_prefix="/bin/sed -n -e 's/^: \(.*\) .*$/ {"\1", (void *) 0},/p' -e 's/^[ABCDGIRSTW][ABCDGIRSTW]* .* \(lib.*\)$/ {"\1", (void *) \&\1},/p' -e 's/^[ABCDGIRSTW][ABCDGIRSTW]* .* \(.*\)$/ {"lib\1", (void *) \&\1},/p'"
# The name lister interface.
nm_interface="BSD nm"
@@ -261,14 +261,14 @@
shlibpath_overrides_runpath=no
# Format of library name prefix.
-libname_spec="lib\$name"
+libname_spec="lib$name"
# List of archive names. First name is the real one, the rest are
links.
# The last name is the one that the linker finds with -lNAME
-library_names_spec="\$libname\$release\$shared_ext\$versuffix \$libname\$release\$shared_ext\$major \$libname\$shared_ext" +library_names_spec="$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext"
# The coded name of the library, if different from the real name.
-soname_spec="\$libname\$release\$shared_ext\$major" +soname_spec="$libname$release$shared_ext$major"
# Permission mode override for installation of shared libraries. install_override_mode=""
@@ -280,7 +280,7 @@
postuninstall_cmds=""
# Commands used to finish a libtool library installation in a
directory.
-finish_cmds="PATH=\\\"\\\$PATH:/sbin\\\" ldconfig -n \$libdir" +finish_cmds="PATH="\$PATH:/sbin" ldconfig -n $libdir"
# As "finish_cmds", except a single script fragment to be evaled but
# not shown. @@ -290,10 +290,10 @@ hardcode_into_libs=yes
# Compile-time system search path for libraries.
-sys_lib_search_path_spec="/usr/lib/gcc/x86_64-pc-linux-gnu/14.3.0 /usr/lib /lib " +sys_lib_search_path_spec="/usr/lib/gcc/aarch64-unknown-linux-gnu/14.3.0 /usr/lib /lib "
# Detected run-time system search path for libraries.
-sys_lib_dlsearch_path_spec="/lib /usr/lib /lib32 /usr/lib32 /usr/lib/openmpi " +sys_lib_dlsearch_path_spec="/lib /usr/lib "
# Explicit LT_SYS_LIBRARY_PATH set during ./configure time. configure_time_lt_sys_library_path=""
@@ -313,14 +313,14 @@
# The linker used to build libraries.
-LD="/usr/bin/ld -m elf_x86_64"
+LD="/usr/bin/ld"
# How to create reloadable object files. reload_flag=" -r"
-reload_cmds="\$LD\$reload_flag -o \$output\$reload_objs" +reload_cmds="$LD$reload_flag -o $output$reload_objs"
# Commands used to build an old-style archive.
-old_archive_cmds="\$AR \$AR_FLAGS \$oldlib\$oldobjs~\$RANLIB \$tool_oldlib" +old_archive_cmds="$AR $AR_FLAGS $oldlib$oldobjs~$RANLIB $tool_oldlib"
# A language specific compiler.
CC="gcc"
@@ -350,10 +350,10 @@
allow_libtool_libs_with_static_runtimes=no
# Compiler flag to allow reflexive dlopens.
-export_dynamic_flag_spec="\$wl--export-dynamic"
+export_dynamic_flag_spec="$wl--export-dynamic"
# Compiler flag to generate shared objects directly from archives.
-whole_archive_flag_spec="\$wl--whole-archive\$convenience \$wl--no-whole-archive" +whole_archive_flag_spec="$wl--whole-archive$convenience $wl--no-whole-archive"
# Whether the compiler copes with passing no objects directly. compiler_needs_object="no"
@@ -365,11 +365,11 @@
old_archive_from_expsyms_cmds=""
# Commands used to build a shared archive.
-archive_cmds="\$CC -shared \$pic_flag \$libobjs \$deplibs \$compiler_flags \$wl-soname \$wl\$soname -o \$lib" -archive_expsym_cmds="echo \\\"{ global:\\\" > \$output_objdir/\$libname.ver~
- cat \$export_symbols | \$SED -e \\\"s/\\\\(.*\\\\)/\\\\1;/\\\" >> \$output_objdir/\$libname.ver~
- echo \\\"local: *; };\\\" >> \$output_objdir/\$libname.ver~
- \$CC -shared \$pic_flag \$libobjs \$deplibs \$compiler_flags \$wl-soname \$wl\$soname \$wl-version-script \$wl\$output_objdir/\$libname.ver -o \$lib"
+archive_cmds="$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib"
+archive_expsym_cmds="echo "{ global:" > $output_objdir/$libname.ver~
+ cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+ echo "local: *; };" >> $output_objdir/$libname.ver~
+ $CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-version-script $wl$output_objdir/$libname.ver -o $lib"# Commands used to build a loadable module if different from building
# a shared archive. @@ -387,7 +387,7 @@
# Flag to hardcode $libdir into a binary during linking. # This must work even if $libdir does not exist
-hardcode_libdir_flag_spec="\$wl-rpath \$wl\$libdir" +hardcode_libdir_flag_spec="$wl-rpath $wl$libdir"
# Whether we need a single "-rpath" flag with a separated argument. hardcode_libdir_separator=""
@@ -426,7 +426,7 @@
always_export_symbols=no
# The commands to list exported symbols.
-export_symbols_cmds="\$NM \$libobjs \$convenience | \$global_symbol_pipe | \$SED 's/.* //' | sort | uniq > \$export_symbols" +export_symbols_cmds="$NM $libobjs $convenience | $global_symbol_pipe | $SED 's/.* //' | sort | uniq > $export_symbols"
# Symbols that should not be listed in the preloaded symbols. exclude_expsyms="_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*"
We can see that on ARM64 lot of '\' are missing.
The problem is fixed it we build dash with the '--enable-fnmatch' configure option! Hope this helps, if you need additional information, please ask.
Thanks for dash and best regards
Juergen
PATCH 1/1 shell: Fix unsigned char promotion and truncation
Quoted 3 lines · On Mon, Oct 20, 2025 at 12:31:03PM +0000, [email protected] wrote:
We are using dash 0.5.13.1 as
/bin/shand running into several build problems on ARM64,
for example curl:
Thanks for the report!
I can reproduce this and it appears to be a couple of instances of incorrect unsigned char (the default on arm64) promotion.
Please try this patch:
---8<---
When a char is promoted to an int, it needs to be signed as otherwise comparisons on it may fail. Alternatively, an integer needs to be truncated to char before comparing it against another char.
src/expand.c +2 -2
@@ -1914,7 +1914,7 @@ static int pmatch(char *pattern, const char *string)if (c =='?' || c =='[' ) c =CTLESC ;for (;;) { -if (c !=CTLESC ) { +if (c != (char )CTLESC ) {/* Stop should be null-terminated * as it is passed as a string to * strpbrk(3).
@@ -1985,7 +1985,7 @@ static int pmatch(char *pattern, const char *string) p++;if (*p == (char )CTLESC ) p++; -else if (*p ==CTLMBCHAR ) { +else if (*p == (char )CTLMBCHAR ) { mbp =mbnext (p); p += mbp &0xff ; p += mbp >>8 ;
src/parser.c +1 -1
@@ -1240,7 +1240,7 @@ checkend: { markloc = out - (char *)stackblock ();for (p = eofmark;STPUTC (c, out), *p; p++) { -if (c != *p) +if (c != (signed char )*p) goto more_heredoc; c =pgetc ();
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Re: [PATCH] shell: Fix unsigned char promotion and truncation
Quoted 11 lines · Herbert Xu
Quoted 3 lines · On Mon, Oct 20, 2025 at 12:31:03PM +0000, [email protected] wrote:
We are using dash 0.5.13.1 as
/bin/shand running into several build problems on ARM64,
for example curl:Thanks for the report!
I can reproduce this and it appears to be a couple of instances of incorrect unsigned char (the default on arm64) promotion.
Please try this patch:
Thanks for the quick fix!
We've tested 0.5.13.1 together with that patch by building a lot of important programs [1] with dash as /bin/sh and everything works fine now on x86_64 and ARM64.
IMO we are at a stable point in the dash development again, looking forward to see 0.5.14 ;)
Thanks again
Juergen
[1] https://git.crux.nu/ports/core
Quoted 52 lines
---8<---
When a char is promoted to an int, it needs to be signed as otherwise comparisons on it may fail. Alternatively, an integer needs to be truncated to char before comparing it against another char.Reported-by Juergen Daubert <[email protected]>Fixes e878137f63e6 ("expand: Do not call rmescapes in expari")Fixes c5bf9702ea11 ("expand: Add multi-byte support to pmatch")Fixes 8f01c3796f0f ("[PARSER] Add FAKEEOFMARK for expandstr")Signed-off-by Herbert Xu <[email protected]>src/expand.c +2
-2@@ -1914,7 +1914,7 @@ static int pmatch(char *pattern, const char *string)if (c =='?' || c =='[' ) c =CTLESC ;for (;;) { -if (c !=CTLESC ) { +if (c != (char )CTLESC ) {/* Stop should be null-terminated * as it is passed as a string to * strpbrk(3). @@ -1985,7 +1985,7 @@ static int pmatch(char *pattern, const char *string) p++;if (*p == (char )CTLESC ) p++; -else if (*p ==CTLMBCHAR ) { +else if (*p == (char )CTLMBCHAR ) { mbp =mbnext (p); p += mbp &0xff ; p += mbp >>8 ;src/parser.c +1
-1@@ -1240,7 +1240,7 @@ checkend: { markloc = out - (char *)stackblock ();for (p = eofmark;STPUTC (c, out), *p; p++) { -if (c != *p) +if (c != (signed char )*p) goto more_heredoc; c =pgetc ();Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Re: [PATCH] shell: Fix unsigned char promotion and truncation
In reply to Herbert XuQuoted 3 lines · Herbert Xu
When a char is promoted to an int, it needs to be signed as otherwise comparisons on it may fail. Alternatively, an integer needs to be truncated to char before comparing it against another char.
There’s another instance of this in argstr() case CTLMBCHAR:
case CTLMBCHAR:
c = (signed char)*p--;
mb = mbnext(p);
ml = (mb >> 8) - 2;
if (flag & (QUOTES_ESC | EXP_MBCHAR)) {
length = (mb >> 8) + (mb & 0xff); if (c == (char)CTLESC)
Since (signed char)CTLESC is negative, it never equals (char)CTLESC on unsigned char architectures.
Reproduction:
$ uname -m
aarch64
$ dash -c 'IFS=ë; set -- ${u-a\ëb}; echo $#'
2(Expected 1, as on x86_64.)
Anders
PATCH 1/1 expand: Drop incorrect CTLESC cast in argstr
Quoted 13 lines · Anders Kaseorg
There’s another instance of this in
argstr()case CTLMBCHAR:(quoted diff) +0
-0case CTLMBCHAR: c = (signed char)*p--; mb = mbnext(p); ml = (mb >> 8) - 2; if (flag & (QUOTES_ESC | EXP_MBCHAR)) { length = (mb >> 8) + (mb & 0xff);if (c == (char)CTLESC)Since (signed char)CTLESC is negative, it never equals (char)CTLESC on unsigned char architectures.
Quoted 8 lines
Reproduction:
$ uname -m aarch64 $ dash -c 'IFS=ë; set -- ${u-a\ëb}; echo $#' 2(Expected 1, as on
x86_64.)
Thanks for the report. Please try this patch.
---8<---
CTLESC needs to be cast to char when it's compared against a char value. However, when it is compared against an integer that was promoted from signed char, it must not be cast.
src/expand.c +1 -1
@@ -372,7 +372,7 @@ addquote: ml = (mb >>8 ) -2 ;if (flag & (QUOTES_ESC |EXP_MBCHAR )) { length = (mb >>8 ) + (mb &0xff ); -if (c == (char )CTLESC ) +if (c ==CTLESC ) startloc += length;break ; }
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Re: [PATCH] expand: Drop incorrect CTLESC cast in argstr
Quoted 13 lines · Herbert Xu
CTLESC needs to be cast to char when it's compared against a char value. However, when it is compared against an integer that was promoted from signed char, it must not be cast.
Reported-by Anders Kaseorg <[email protected]>Fixes 6c44f4ee0c2b ("parser: Add support for multi-byte characters")Signed-off-by Herbert Xu <[email protected]>src/expand.c +0
-0
src/expand.c addquote: · line 378
Quoted 8 lines
src/expand.c +1
-1@@ -372,7 +372,7 @@ addquote: ml = (mb >>8 ) -2 ;if (flag & (QUOTES_ESC |EXP_MBCHAR )) { length = (mb >>8 ) + (mb &0xff ); -if (c == (char )CTLESC ) +if (c ==CTLESC ) startloc += length;break ; }
Works for me, thanks.
Anders