From 6b9a668f981d0bf841f615fcecbc67a3f2ca3d16 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Wed, 7 Apr 2021 01:28:17 +0100 Subject: [PATCH] package: fix detection of 64-bit architectures On some systems (such as Ubuntu on ARM), the output of `file` contains a build hash, such as: SomeExecutable: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=8934dd61657aac875c190535066466849687a56b, not stripped This build hash can contain the string '64', which caused package to wrongly detect a 64-bit architecture. bin/package, src/cmd/INIT/package.sh: - Export LC_ALL=C to ensure 'file' output in English. - To detect a 64-bit architecture, require the string "64-bit", "64 bit" or "64bit" in 'file' output. The letters 'i' and 't' cannot occur in a hexadecimal hash, so hopefully that is safe enough. It is impossible to make this method completely safe, so in the long term it should be replaced. Progresses: https://github.com/ksh93/ksh/issues/253 --- bin/package | 5 ++++- src/cmd/INIT/package.sh | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/bin/package b/bin/package index 0633587fa..401b965e5 100755 --- a/bin/package +++ b/bin/package @@ -2571,13 +2571,16 @@ int b() { return 0; } ;; *) case $bits in '') bits=` cd "$TMPDIR" + LC_ALL=C + export LC_ALL tmp=hi$$ trap 'rm -f $tmp.*' 0 1 2 echo 'int main() { return 0; }' > $tmp.a.c $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" ` case $bits in - *64*) bits=64 ;; + *\ 64-bit* | *\ 64\ bit* | *\ 64bit*) + bits=64 ;; *) bits= ;; esac ;; diff --git a/src/cmd/INIT/package.sh b/src/cmd/INIT/package.sh index 0633587fa..401b965e5 100644 --- a/src/cmd/INIT/package.sh +++ b/src/cmd/INIT/package.sh @@ -2571,13 +2571,16 @@ int b() { return 0; } ;; *) case $bits in '') bits=` cd "$TMPDIR" + LC_ALL=C + export LC_ALL tmp=hi$$ trap 'rm -f $tmp.*' 0 1 2 echo 'int main() { return 0; }' > $tmp.a.c $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" ` case $bits in - *64*) bits=64 ;; + *\ 64-bit* | *\ 64\ bit* | *\ 64bit*) + bits=64 ;; *) bits= ;; esac ;;