From 27633432b969df2bc626369b5fa7f43e1fb97f0c Mon Sep 17 00:00:00 2001 From: Johnothan King Date: Mon, 9 Mar 2026 00:27:43 -0700 Subject: [PATCH 1/3] Fix fakeroot build by using od(1) to check 64-bit ELFs bin/package: - Use od(1) to check the ELF header if the file command fails. This allows ksh to build and install correctly in fakeroot environments without encountering bogus seccomp restrictions. Fixes https://github.com/ksh93/ksh/issues/919 --- bin/package | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/bin/package b/bin/package index 0117c1989b33..1dc30805d96e 100755 --- a/bin/package +++ b/bin/package @@ -1506,7 +1506,16 @@ int b(void) { return 0; } echo 'int main(void) { return 0; }' > $tmp.a.c checkcc $cc $CCFLAGS -o $tmp.a.exe $tmp.a.c /dev/null 2>&1 - file $tmp.a.exe 2>/dev/null | sed "s/$tmp\.a\.exe//g" ) + file_result=$(file $tmp.a.exe 2>/dev/null | sed "s/$tmp\.a\.exe//g") || true + # Use od(1) to check the ELF header directly if file(1) failed + if test -z "$file_result" && test "$(uname -s | sed 's/-.*//')" != CYGWIN + then elfbyte=$(( $(od -An -t x1 -j 4 -N 1 $tmp.a.exe) )) + if test "$elfbyte" = 2 + then echo "ELF 64-bit" + else echo "ELF 32-bit" + fi + else echo "$file_result" + fi ) case $bits in *\ 64-bit* | *\ 64\ bit* | *\ 64bit*) bits=64 ;; From 36be3592dcb48c72090166da14e0e0b1b654a423 Mon Sep 17 00:00:00 2001 From: Johnothan King Date: Tue, 31 Mar 2026 13:29:40 -0700 Subject: [PATCH 2/3] Use more robust check - Check the first five bytes to guarantee it's actually an ELF binary. - Return 'Unknown bits' if it's neither a 64-bit ELF nor 32-bit ELF (i.e. it could be anything). This isn't functionally different but is better for clarity. - Pass '-A n' to od(1) rather than '-An' for what should be better portability. - locale.sh: Also apply that change here since a quick grep showed this file was also passing -An to od. --- bin/package | 8 +++++--- src/cmd/ksh93/tests/locale.sh | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/bin/package b/bin/package index 1dc30805d96e..0c03be5348d9 100755 --- a/bin/package +++ b/bin/package @@ -1509,10 +1509,12 @@ int b(void) { return 0; } file_result=$(file $tmp.a.exe 2>/dev/null | sed "s/$tmp\.a\.exe//g") || true # Use od(1) to check the ELF header directly if file(1) failed if test -z "$file_result" && test "$(uname -s | sed 's/-.*//')" != CYGWIN - then elfbyte=$(( $(od -An -t x1 -j 4 -N 1 $tmp.a.exe) )) - if test "$elfbyte" = 2 + then elfbytes=$(od -A n -t x1 -N 5 $tmp.a.exe | tr -d ' \n') + if test "$elfbytes" = "7f454c4602" then echo "ELF 64-bit" - else echo "ELF 32-bit" + elif test "$elfbytes" = "7f454c4601" + then echo "ELF 32-bit" + else echo "Unknown bits" fi else echo "$file_result" fi ) diff --git a/src/cmd/ksh93/tests/locale.sh b/src/cmd/ksh93/tests/locale.sh index d1838b3ec79c..cb6400422f1c 100755 --- a/src/cmd/ksh93/tests/locale.sh +++ b/src/cmd/ksh93/tests/locale.sh @@ -394,7 +394,7 @@ then LC_ALL=en_US.UTF-8 LC_ALL=C.UTF-8 eval $'[[ $(print -r -- "$x") == $\'hello\\u[20ac]\\xee world\' ]]' || err_exit '%q with unicode and non-unicode not working' if [[ $(whence od) ]] then got='68656c6c6fe282acee20776f726c640a' - [[ $(print -r -- "$x" | od -An -tx1 \ + [[ $(print -r -- "$x" | od -A n -tx1 \ | awk 'BEGIN { ORS=""; } { for (i=1; i<=NF; i++) print $i; }') \ == "$got" ]] \ || err_exit "incorrect string from printf %q" From bee7170753da783561ec046e4bc9583a3dae3a45 Mon Sep 17 00:00:00 2001 From: Johnothan King Date: Wed, 1 Apr 2026 08:34:26 -0700 Subject: [PATCH 3/3] Revert to -An --- bin/package | 2 +- src/cmd/ksh93/tests/locale.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/package b/bin/package index d4f308f96882..9fbbb1cb2d7f 100755 --- a/bin/package +++ b/bin/package @@ -1526,7 +1526,7 @@ int b(void) { return 0; } file_result=$(file $tmp.a.exe 2>/dev/null | sed "s/$tmp\.a\.exe//g") || true # Use od(1) to check the ELF header directly if file(1) failed if test -z "$file_result" && test "$(uname -s | sed 's/-.*//')" != CYGWIN - then elfbytes=$(od -A n -t x1 -N 5 $tmp.a.exe | tr -d ' \n') + then elfbytes=$(od -An -tx1 -N 5 $tmp.a.exe | tr -d ' \n') if test "$elfbytes" = "7f454c4602" then echo "ELF 64-bit" elif test "$elfbytes" = "7f454c4601" diff --git a/src/cmd/ksh93/tests/locale.sh b/src/cmd/ksh93/tests/locale.sh index cb6400422f1c..d1838b3ec79c 100755 --- a/src/cmd/ksh93/tests/locale.sh +++ b/src/cmd/ksh93/tests/locale.sh @@ -394,7 +394,7 @@ then LC_ALL=en_US.UTF-8 LC_ALL=C.UTF-8 eval $'[[ $(print -r -- "$x") == $\'hello\\u[20ac]\\xee world\' ]]' || err_exit '%q with unicode and non-unicode not working' if [[ $(whence od) ]] then got='68656c6c6fe282acee20776f726c640a' - [[ $(print -r -- "$x" | od -A n -tx1 \ + [[ $(print -r -- "$x" | od -An -tx1 \ | awk 'BEGIN { ORS=""; } { for (i=1; i<=NF; i++) print $i; }') \ == "$got" ]] \ || err_exit "incorrect string from printf %q"