@@ -177,12 +177,23 @@ main() {
177
177
return " $_retval "
178
178
}
179
179
180
- check_proc () {
181
- # Check for /proc by looking for the /proc/self/exe link
180
+ get_current_exe () {
181
+ # Returns the executable used for system architecture detection
182
182
# This is only run on Linux
183
- if ! test -L /proc/self/exe ; then
184
- err " fatal: Unable to find /proc/self/exe. Is /proc mounted? Installation cannot proceed without /proc."
183
+ local _current_exe
184
+ if test -L /proc/self/exe ; then
185
+ _current_exe=/proc/self/exe
186
+ else
187
+ echo " Warning: Unable to find /proc/self/exe. System architecture detection might be inaccurate."
188
+ if test -n " $SHELL " ; then
189
+ _current_exe=$SHELL
190
+ else
191
+ need_cmd /bin/sh
192
+ _current_exe=/bin/sh
193
+ fi
194
+ echo " Warning: Falling back to $_current_exe ."
185
195
fi
196
+ RETVAL=" $_current_exe "
186
197
}
187
198
188
199
get_bitness () {
@@ -193,8 +204,9 @@ get_bitness() {
193
204
# 0x02 for 64-bit.
194
205
# The printf builtin on some shells like dash only supports octal
195
206
# escape sequences, so we use those.
207
+ local _current_exe=$1
196
208
local _current_exe_head
197
- _current_exe_head=$( head -c 5 /proc/self/exe )
209
+ _current_exe_head=$( head -c 5 " $_current_exe " )
198
210
if [ " $_current_exe_head " = " $( printf ' \177ELF\001' ) " ]; then
199
211
echo 32
200
212
elif [ " $_current_exe_head " = " $( printf ' \177ELF\002' ) " ]; then
@@ -205,27 +217,30 @@ get_bitness() {
205
217
}
206
218
207
219
is_host_amd64_elf () {
220
+ local _current_exe=$1
221
+
208
222
need_cmd head
209
223
need_cmd tail
210
224
# ELF e_machine detection without dependencies beyond coreutils.
211
225
# Two-byte field at offset 0x12 indicates the CPU,
212
226
# but we're interested in it being 0x3E to indicate amd64, or not that.
213
227
local _current_exe_machine
214
- _current_exe_machine=$( head -c 19 /proc/self/exe | tail -c 1)
228
+ _current_exe_machine=$( head -c 19 " $_current_exe " | tail -c 1)
215
229
[ " $_current_exe_machine " = " $( printf ' \076' ) " ]
216
230
}
217
231
218
232
get_endianness () {
219
- local cputype=$1
220
- local suffix_eb=$2
221
- local suffix_el=$3
233
+ local _current_exe=$1
234
+ local cputype=$2
235
+ local suffix_eb=$3
236
+ local suffix_el=$4
222
237
223
238
# detect endianness without od/hexdump, like get_bitness() does.
224
239
need_cmd head
225
240
need_cmd tail
226
241
227
242
local _current_exe_endianness
228
- _current_exe_endianness=" $( head -c 6 /proc/self/exe | tail -c 1) "
243
+ _current_exe_endianness=" $( head -c 6 " $_current_exe " | tail -c 1) "
229
244
if [ " $_current_exe_endianness " = " $( printf ' \001' ) " ]; then
230
245
echo " ${cputype}${suffix_el} "
231
246
elif [ " $_current_exe_endianness " = " $( printf ' \002' ) " ]; then
@@ -356,16 +371,18 @@ get_architecture() {
356
371
fi
357
372
fi
358
373
374
+ local _current_exe
359
375
case " $_ostype " in
360
376
361
377
Android)
362
378
_ostype=linux-android
363
379
;;
364
380
365
381
Linux)
366
- check_proc
382
+ get_current_exe
383
+ _current_exe=$RETVAL
367
384
_ostype=unknown-linux-$_clibtype
368
- _bitness=$( get_bitness)
385
+ _bitness=$( get_bitness " $_current_exe " )
369
386
;;
370
387
371
388
FreeBSD)
@@ -438,14 +455,14 @@ get_architecture() {
438
455
;;
439
456
440
457
mips)
441
- _cputype=$( get_endianness mips ' ' el)
458
+ _cputype=$( get_endianness " $_current_exe " mips ' ' el)
442
459
;;
443
460
444
461
mips64)
445
462
if [ " $_bitness " -eq 64 ]; then
446
463
# only n64 ABI is supported for now
447
464
_ostype=" ${_ostype} abi64"
448
- _cputype=$( get_endianness mips64 ' ' el)
465
+ _cputype=$( get_endianness " $_current_exe " mips64 ' ' el)
449
466
fi
450
467
;;
451
468
@@ -484,7 +501,7 @@ get_architecture() {
484
501
_cputype=" $RUSTUP_CPUTYPE "
485
502
else {
486
503
# 32-bit executable for amd64 = x32
487
- if is_host_amd64_elf; then {
504
+ if is_host_amd64_elf " $_current_exe " ; then {
488
505
echo " This host is running an x32 userland; as it stands, x32 support is poor," 1>&2
489
506
echo " and there isn't a native toolchain -- you will have to install" 1>&2
490
507
echo " multiarch compatibility with i686 and/or amd64, then select one" 1>&2
@@ -500,7 +517,7 @@ get_architecture() {
500
517
}; fi
501
518
;;
502
519
mips64)
503
- _cputype=$( get_endianness mips ' ' el)
520
+ _cputype=$( get_endianness " $_current_exe " mips ' ' el)
504
521
;;
505
522
powerpc64)
506
523
_cputype=powerpc
0 commit comments