From 9a48ba15572cc6f4b36245b234f8cfe003f25662 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Sat, 16 Jan 2021 22:53:35 +0000 Subject: [PATCH] package: fix code for detecting 64-bit compiler bin/package, src/cmd/INIT/package.sh: - The code for detecting a 64-bit object file was seriously broken: the temporary file name could contain '64' because it included $$, the current PID, and 64-bit was detected if the output of 'file' (which includes the complete file name) contained '64'. Fix by removing the file name from 'file' output before testing. - Also refactor that code a bit and remove the nonsensical test if /bin/sh is a 64-bit binary, which is neither here nor there. It's what the compiler produces that we need to care about. --- bin/package | 23 +++++++---------------- src/cmd/INIT/package.sh | 23 +++++++---------------- 2 files changed, 14 insertions(+), 32 deletions(-) diff --git a/bin/package b/bin/package index 21605f5df..ee350dea0 100755 --- a/bin/package +++ b/bin/package @@ -2491,24 +2491,15 @@ int b() { return 0; } esac ;; *) case $bits in - '') case `file /bin/sh 2>/dev/null` in - *universal*64* | *64-bit* | *x86[_-]64*) - pwd=`pwd` - cd "$TMPDIR" + '') bits=` cd "$TMPDIR" tmp=hi$$ trap 'rm -f $tmp.*' 0 1 2 - cat > $tmp.a.c </dev/null 2>&1 - rm -f $tmp.* - trap - 0 1 2 - cd $pwd - ;; + echo 'int main() { return 0; }' > $tmp.a.c + $cc -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 ;; + *) bits= ;; esac ;; esac diff --git a/src/cmd/INIT/package.sh b/src/cmd/INIT/package.sh index 1ced626de..ea7037d12 100644 --- a/src/cmd/INIT/package.sh +++ b/src/cmd/INIT/package.sh @@ -2490,24 +2490,15 @@ int b() { return 0; } esac ;; *) case $bits in - '') case `file /bin/sh 2>/dev/null` in - *universal*64* | *64-bit* | *x86[_-]64*) - pwd=`pwd` - cd "$TMPDIR" + '') bits=` cd "$TMPDIR" tmp=hi$$ trap 'rm -f $tmp.*' 0 1 2 - cat > $tmp.a.c </dev/null 2>&1 - rm -f $tmp.* - trap - 0 1 2 - cd $pwd - ;; + echo 'int main() { return 0; }' > $tmp.a.c + $cc -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 ;; + *) bits= ;; esac ;; esac