Skip to content

Commit

Permalink
package: fix code for detecting 64-bit compiler
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
McDutchie committed Jan 16, 2021
1 parent 6025c81 commit 9a48ba1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 32 deletions.
23 changes: 7 additions & 16 deletions bin/package
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<!
int main() { return 0; }
!
if $cc -o $tmp.a.exe $tmp.a.c
then case `file $tmp.a.exe` in
*64*) bits=64 ;;
esac
fi </dev/null >/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 >/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
Expand Down
23 changes: 7 additions & 16 deletions src/cmd/INIT/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<!
int main() { return 0; }
!
if $cc -o $tmp.a.exe $tmp.a.c
then case `file $tmp.a.exe` in
*64*) bits=64 ;;
esac
fi </dev/null >/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 >/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
Expand Down

0 comments on commit 9a48ba1

Please sign in to comment.