|
1 | 1 | use std::collections::HashSet;
|
2 | 2 | use std::env;
|
3 | 3 | use std::fmt;
|
4 |
| -use std::io::Write; |
| 4 | +use std::fs; |
| 5 | +use std::io::{self, Read, Write}; |
5 | 6 | use std::ops::Deref;
|
6 | 7 | use std::path::Path;
|
7 | 8 | use std::str::FromStr;
|
@@ -219,6 +220,26 @@ impl Deref for TargetTriple {
|
219 | 220 | }
|
220 | 221 | }
|
221 | 222 |
|
| 223 | +fn is_32bit_userspace() -> bool { |
| 224 | + // Check if /bin/sh is a 32-bit binary. If it doesn't exist, fall back to |
| 225 | + // checking if _we_ are a 32-bit binary. |
| 226 | + // rustup-init.sh also relies on checking /bin/sh for bitness. |
| 227 | + |
| 228 | + // inner function is to simplify error handling. |
| 229 | + fn inner() -> io::Result<bool> { |
| 230 | + let mut f = fs::File::open("/bin/sh")?; |
| 231 | + let mut buf = [0; 5]; |
| 232 | + f.read_exact(&mut buf)?; |
| 233 | + |
| 234 | + // ELF files start out "\x7fELF", and the following byte is |
| 235 | + // 0x01 for 32-bit and |
| 236 | + // 0x02 for 64-bit. |
| 237 | + Ok(&buf == b"\x7fELF\x01") |
| 238 | + } |
| 239 | + |
| 240 | + inner().unwrap_or(cfg!(target_pointer_width = "32")) |
| 241 | +} |
| 242 | + |
222 | 243 | impl TargetTriple {
|
223 | 244 | pub fn new(name: &str) -> Self {
|
224 | 245 | Self(name.to_string())
|
@@ -346,7 +367,13 @@ impl TargetTriple {
|
346 | 367 | (b"Linux", b"arm") => Some("arm-unknown-linux-gnueabi"),
|
347 | 368 | (b"Linux", b"armv7l") => Some("armv7-unknown-linux-gnueabihf"),
|
348 | 369 | (b"Linux", b"armv8l") => Some("armv7-unknown-linux-gnueabihf"),
|
349 |
| - (b"Linux", b"aarch64") => Some(TRIPLE_AARCH64_UNKNOWN_LINUX), |
| 370 | + (b"Linux", b"aarch64") => { |
| 371 | + if is_32bit_userspace() { |
| 372 | + Some("armv7-unknown-linux-gnueabihf") |
| 373 | + } else { |
| 374 | + Some(TRIPLE_AARCH64_UNKNOWN_LINUX) |
| 375 | + } |
| 376 | + } |
350 | 377 | (b"Darwin", b"x86_64") => Some("x86_64-apple-darwin"),
|
351 | 378 | (b"Darwin", b"i686") => Some("i686-apple-darwin"),
|
352 | 379 | (b"FreeBSD", b"x86_64") => Some("x86_64-unknown-freebsd"),
|
|
0 commit comments