public inbox for dash@vger.kernel.org
 help / color / mirror / Atom feed
* dash 0.5.13.1: problems with dash as /bin/sh on ARM64
@ 2025-10-20 12:31 j.daubert
  2025-10-21 13:29 ` [PATCH] shell: Fix unsigned char promotion and truncation Herbert Xu
  0 siblings, 1 reply; 3+ messages in thread
From: j.daubert @ 2025-10-20 12:31 UTC (permalink / raw)
  To: Dash

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	2025-10-15 13:39:32.088306752 +0200
+++ /tmp/libtool_arm64	2025-10-15 13:39:11.089769791 +0200
@@ -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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] shell: Fix unsigned char promotion and truncation
  2025-10-20 12:31 dash 0.5.13.1: problems with dash as /bin/sh on ARM64 j.daubert
@ 2025-10-21 13:29 ` Herbert Xu
  2025-10-23 11:29   ` Juergen Daubert
  0 siblings, 1 reply; 3+ messages in thread
From: Herbert Xu @ 2025-10-21 13:29 UTC (permalink / raw)
  To: j.daubert; +Cc: Dash

On Mon, Oct 20, 2025 at 12:31:03PM +0000, j.daubert@posteo.de wrote:
> We are using dash 0.5.13.1 as /bin/sh and 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.

Reported-by: Juergen Daubert <j.daubert@posteo.de> 
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 <herbert@gondor.apana.org.au>

diff --git a/src/expand.c b/src/expand.c
index 912384d..8c8bf0e 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -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;
diff --git a/src/parser.c b/src/parser.c
index eb402a7..5714958 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -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();
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] shell: Fix unsigned char promotion and truncation
  2025-10-21 13:29 ` [PATCH] shell: Fix unsigned char promotion and truncation Herbert Xu
@ 2025-10-23 11:29   ` Juergen Daubert
  0 siblings, 0 replies; 3+ messages in thread
From: Juergen Daubert @ 2025-10-23 11:29 UTC (permalink / raw)
  To: Herbert Xu; +Cc: Dash

On Tue, Oct 21, 2025 at 09:29:32PM +0800, Herbert Xu wrote:
> On Mon, Oct 20, 2025 at 12:31:03PM +0000, j.daubert@posteo.de wrote:
> > We are using dash 0.5.13.1 as /bin/sh and 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


> 
> ---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 <j.daubert@posteo.de> 
> 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 <herbert@gondor.apana.org.au>
> 
> diff --git a/src/expand.c b/src/expand.c
> index 912384d..8c8bf0e 100644
> --- a/src/expand.c
> +++ b/src/expand.c
> @@ -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;
> diff --git a/src/parser.c b/src/parser.c
> index eb402a7..5714958 100644
> --- a/src/parser.c
> +++ b/src/parser.c
> @@ -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();
> -- 
> Email: Herbert Xu <herbert@gondor.apana.org.au>
> Home Page: http://gondor.apana.org.au/~herbert/
> PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-10-23 11:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-20 12:31 dash 0.5.13.1: problems with dash as /bin/sh on ARM64 j.daubert
2025-10-21 13:29 ` [PATCH] shell: Fix unsigned char promotion and truncation Herbert Xu
2025-10-23 11:29   ` Juergen Daubert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox