Skip to content

Commit ecd6cb3

Browse files
authored
Merge pull request #2622 from nabijaczleweli/master
Detect and warn about x32
2 parents ca6cd05 + 8e9570c commit ecd6cb3

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

rustup-init.sh

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,17 @@ get_bitness() {
159159
fi
160160
}
161161

162+
is_host_amd64_elf() {
163+
need_cmd head
164+
need_cmd tail
165+
# ELF e_machine detection without dependencies beyond coreutils.
166+
# Two-byte field at offset 0x12 indicates the CPU,
167+
# but we're interested in it being 0x3E to indicate amd64, or not that.
168+
local _current_exe_machine
169+
_current_exe_machine=$(head -c 19 /proc/self/exe | tail -c 1)
170+
[ "$_current_exe_machine" = "$(printf '\076')" ]
171+
}
172+
162173
get_endianness() {
163174
local cputype=$1
164175
local suffix_eb=$2
@@ -338,7 +349,24 @@ get_architecture() {
338349
if [ "${_ostype}" = unknown-linux-gnu ] && [ "${_bitness}" -eq 32 ]; then
339350
case $_cputype in
340351
x86_64)
341-
_cputype=i686
352+
if [ -n "${RUSTUP_CPUTYPE:-}" ]; then
353+
_cputype="$RUSTUP_CPUTYPE"
354+
else {
355+
# 32-bit executable for amd64 = x32
356+
if is_host_amd64_elf; then {
357+
echo "This host is running an x32 userland; as it stands, x32 support is poor," 1>&2
358+
echo "and there isn't a native toolchain -- you will have to install" 1>&2
359+
echo "multiarch compatibility with i686 and/or amd64, then select one" 1>&2
360+
echo "by re-running this script with the RUSTUP_CPUTYPE environment variable" 1>&2
361+
echo "set to i686 or x86_64, respectively." 1>&2
362+
echo 1>&2
363+
echo "You will be able to add an x32 target after installation by running" 1>&2
364+
echo " rustup target add x86_64-unknown-linux-gnux32" 1>&2
365+
exit 1
366+
}; else
367+
_cputype=i686
368+
fi
369+
}; fi
342370
;;
343371
mips64)
344372
_cputype=$(get_endianness mips '' el)

0 commit comments

Comments
 (0)