1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

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
This commit is contained in:
Martijn Dekker 2021-04-07 01:28:17 +01:00
parent 6b9703ffdd
commit 6b9a668f98
2 changed files with 8 additions and 2 deletions

View file

@ -2571,13 +2571,16 @@ int b() { return 0; }
;; ;;
*) case $bits in *) case $bits in
'') bits=` cd "$TMPDIR" '') bits=` cd "$TMPDIR"
LC_ALL=C
export LC_ALL
tmp=hi$$ tmp=hi$$
trap 'rm -f $tmp.*' 0 1 2 trap 'rm -f $tmp.*' 0 1 2
echo 'int main() { return 0; }' > $tmp.a.c echo 'int main() { return 0; }' > $tmp.a.c
$cc $CCFLAGS -o $tmp.a.exe $tmp.a.c </dev/null >/dev/null 2>&1 $cc $CCFLAGS -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" ` file $tmp.a.exe 2>/dev/null | sed "s/$tmp\.a\.exe//g" `
case $bits in case $bits in
*64*) bits=64 ;; *\ 64-bit* | *\ 64\ bit* | *\ 64bit*)
bits=64 ;;
*) bits= ;; *) bits= ;;
esac esac
;; ;;

View file

@ -2571,13 +2571,16 @@ int b() { return 0; }
;; ;;
*) case $bits in *) case $bits in
'') bits=` cd "$TMPDIR" '') bits=` cd "$TMPDIR"
LC_ALL=C
export LC_ALL
tmp=hi$$ tmp=hi$$
trap 'rm -f $tmp.*' 0 1 2 trap 'rm -f $tmp.*' 0 1 2
echo 'int main() { return 0; }' > $tmp.a.c echo 'int main() { return 0; }' > $tmp.a.c
$cc $CCFLAGS -o $tmp.a.exe $tmp.a.c </dev/null >/dev/null 2>&1 $cc $CCFLAGS -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" ` file $tmp.a.exe 2>/dev/null | sed "s/$tmp\.a\.exe//g" `
case $bits in case $bits in
*64*) bits=64 ;; *\ 64-bit* | *\ 64\ bit* | *\ 64bit*)
bits=64 ;;
*) bits= ;; *) bits= ;;
esac esac
;; ;;