Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at 17.09 75 lines 2.4 kB view raw
1From 36c053f37670c6003f9e8dc001741f7c49e9526a Mon Sep 17 00:00:00 2001 2From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= <joerg@thalheim.io> 3Date: Sat, 15 Apr 2017 20:42:10 +0200 4Subject: [PATCH] use hardcoded dynamic-linker 5MIME-Version: 1.0 6Content-Type: text/plain; charset=UTF-8 7Content-Transfer-Encoding: 8bit 8 9Signed-off-by: Jörg Thalheim <joerg@thalheim.io> 10--- 11 src/rustup-cli/common.rs | 3 ++- 12 src/rustup/toolchain.rs | 22 ++++++++++++++++++++-- 13 2 files changed, 22 insertions(+), 3 deletions(-) 14 15diff --git a/src/rustup-cli/common.rs b/src/rustup-cli/common.rs 16index 1abf345..21096e7 100644 17--- a/src/rustup-cli/common.rs 18+++ b/src/rustup-cli/common.rs 19@@ -220,7 +220,8 @@ pub fn rustc_version(toolchain: &Toolchain) -> String { 20 if toolchain.exists() { 21 let rustc_path = toolchain.binary_file("rustc"); 22 if utils::is_file(&rustc_path) { 23- let mut cmd = Command::new(&rustc_path); 24+ let mut cmd = Command::new("@dynamicLinker@"); 25+ cmd.arg(&rustc_path); 26 cmd.arg("--version"); 27 toolchain.set_ldpath(&mut cmd); 28 29diff --git a/src/rustup/toolchain.rs b/src/rustup/toolchain.rs 30index dc29c32..212a4ab 100644 31--- a/src/rustup/toolchain.rs 32+++ b/src/rustup/toolchain.rs 33@@ -315,7 +315,7 @@ impl<'a> Toolchain<'a> { 34 } 35 Path::new(&binary) 36 }; 37- let mut cmd = Command::new(&path); 38+ let mut cmd = wrap_elf_interpreter(&path); 39 self.set_env(&mut cmd); 40 Ok(cmd) 41 } 42@@ -363,7 +363,7 @@ impl<'a> Toolchain<'a> { 43 } else { 44 src_file 45 }; 46- let mut cmd = Command::new(exe_path); 47+ let mut cmd = wrap_elf_interpreter(exe_path); 48 self.set_env(&mut cmd); 49 cmd.env("RUSTUP_TOOLCHAIN", &primary_toolchain.name); 50 Ok(cmd) 51@@ -648,3 +648,21 @@ impl<'a> Toolchain<'a> { 52 path 53 } 54 } 55+ 56+fn wrap_elf_interpreter<S: AsRef<OsStr>>(p: S) -> Command { 57+ use std::fs::File; 58+ use std::io::Read; 59+ let path = Path::new(&p); 60+ let is_elf = File::open(path).map(|mut f| { 61+ let mut buf = [0; 4]; 62+ let _ = f.read(&mut buf); 63+ buf == b"\x7fELF"[..] 64+ }).unwrap_or(false); 65+ if is_elf { 66+ let mut cmd = Command::new("@dynamicLinker@"); 67+ cmd.arg(&path); 68+ cmd 69+ } else { 70+ Command::new(&path) 71+ } 72+} 73-- 742.12.2 75