From 9011524454aff19110a3efc1cd3bb68657a0f8ee Mon Sep 17 00:00:00 2001 From: hyd-dev Date: Tue, 15 Jun 2021 01:16:38 +0800 Subject: [PATCH] Remove `strip_linker_suffix` --- src/helpers.rs | 5 ----- src/shims/foreign_items.rs | 16 ++++++---------- src/shims/posix/foreign_items.rs | 3 +-- src/shims/posix/linux/foreign_items.rs | 3 +-- src/shims/posix/macos/foreign_items.rs | 3 +-- src/shims/windows/foreign_items.rs | 3 +-- 6 files changed, 10 insertions(+), 23 deletions(-) diff --git a/src/helpers.rs b/src/helpers.rs index 1a12d19e124..b99a446577a 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -723,11 +723,6 @@ pub fn check_arg_count<'a, 'tcx, const N: usize>( throw_ub_format!("incorrect number of arguments: got {}, expected {}", args.len(), N) } -/// Strip linker suffixes (seen on 32-bit macOS). -pub fn strip_linker_suffix(link_name: &str) -> &str { - link_name.trim_end_matches("$UNIX2003") -} - pub fn isolation_abort_error(name: &str) -> InterpResult<'static> { throw_machine_stop!(TerminationInfo::UnsupportedInIsolation(format!( "{} not available when isolation is enabled", diff --git a/src/shims/foreign_items.rs b/src/shims/foreign_items.rs index 36d075e32df..3745b8cf2fa 100644 --- a/src/shims/foreign_items.rs +++ b/src/shims/foreign_items.rs @@ -25,7 +25,6 @@ use super::backtrace::EvalContextExt as _; use crate::*; -use helpers::strip_linker_suffix; /// Returned by `emulate_foreign_item_by_name`. pub enum EmulateByNameResult { @@ -216,12 +215,11 @@ fn emulate_foreign_item( .first_attr_value_str_by_name(&attrs, sym::link_name) .unwrap_or_else(|| this.tcx.item_name(def_id)); let link_name = link_name_sym.as_str(); - let link_name = strip_linker_suffix(&link_name); let tcx = this.tcx.tcx; // First: functions that diverge. let (dest, ret) = match ret { - None => match link_name { + None => match &*link_name { "miri_start_panic" => { // `check_shim` happens inside `handle_miri_start_panic`. this.handle_miri_start_panic(abi, link_name_sym, args, unwind)?; @@ -306,9 +304,7 @@ fn emulate_foreign_item_by_name( // Here we dispatch all the shims for foreign functions. If you have a platform specific // shim, add it to the corresponding submodule. - let shim_name = link_name.as_str(); - let shim_name = strip_linker_suffix(&shim_name); - match shim_name { + match &*link_name.as_str() { // Miri-specific extern functions "miri_static_root" => { let &[ref ptr] = this.check_shim(abi, Abi::Rust, link_name, args)?; @@ -499,7 +495,7 @@ fn emulate_foreign_item_by_name( let &[ref f] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; // FIXME: Using host floats. let f = f32::from_bits(this.read_scalar(f)?.to_u32()?); - let f = match shim_name { + let f = match &*link_name.as_str() { "cbrtf" => f.cbrt(), "coshf" => f.cosh(), "sinhf" => f.sinh(), @@ -522,7 +518,7 @@ fn emulate_foreign_item_by_name( // FIXME: Using host floats. let f1 = f32::from_bits(this.read_scalar(f1)?.to_u32()?); let f2 = f32::from_bits(this.read_scalar(f2)?.to_u32()?); - let n = match shim_name { + let n = match &*link_name.as_str() { "_hypotf" | "hypotf" => f1.hypot(f2), "atan2f" => f1.atan2(f2), _ => bug!(), @@ -541,7 +537,7 @@ fn emulate_foreign_item_by_name( let &[ref f] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; // FIXME: Using host floats. let f = f64::from_bits(this.read_scalar(f)?.to_u64()?); - let f = match shim_name { + let f = match &*link_name.as_str() { "cbrt" => f.cbrt(), "cosh" => f.cosh(), "sinh" => f.sinh(), @@ -562,7 +558,7 @@ fn emulate_foreign_item_by_name( // FIXME: Using host floats. let f1 = f64::from_bits(this.read_scalar(f1)?.to_u64()?); let f2 = f64::from_bits(this.read_scalar(f2)?.to_u64()?); - let n = match shim_name { + let n = match &*link_name.as_str() { "_hypot" | "hypot" => f1.hypot(f2), "atan2" => f1.atan2(f2), _ => bug!(), diff --git a/src/shims/posix/foreign_items.rs b/src/shims/posix/foreign_items.rs index 2585b562f23..4035deff63e 100644 --- a/src/shims/posix/foreign_items.rs +++ b/src/shims/posix/foreign_items.rs @@ -6,7 +6,6 @@ use rustc_target::spec::abi::Abi; use crate::*; -use helpers::strip_linker_suffix; use shims::foreign_items::EmulateByNameResult; use shims::posix::fs::EvalContextExt as _; use shims::posix::sync::EvalContextExt as _; @@ -24,7 +23,7 @@ fn emulate_foreign_item_by_name( ) -> InterpResult<'tcx, EmulateByNameResult> { let this = self.eval_context_mut(); - match strip_linker_suffix(&link_name.as_str()) { + match &*link_name.as_str() { // Environment related shims "getenv" => { let &[ref name] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; diff --git a/src/shims/posix/linux/foreign_items.rs b/src/shims/posix/linux/foreign_items.rs index 160e27f395e..33889963bc4 100644 --- a/src/shims/posix/linux/foreign_items.rs +++ b/src/shims/posix/linux/foreign_items.rs @@ -3,7 +3,6 @@ use rustc_target::spec::abi::Abi; use crate::*; -use helpers::strip_linker_suffix; use shims::foreign_items::EmulateByNameResult; use shims::posix::fs::EvalContextExt as _; use shims::posix::linux::sync::futex; @@ -22,7 +21,7 @@ fn emulate_foreign_item_by_name( ) -> InterpResult<'tcx, EmulateByNameResult> { let this = self.eval_context_mut(); - match strip_linker_suffix(&link_name.as_str()) { + match &*link_name.as_str() { // errno "__errno_location" => { let &[] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; diff --git a/src/shims/posix/macos/foreign_items.rs b/src/shims/posix/macos/foreign_items.rs index 45d6f5b4495..47a860b96a8 100644 --- a/src/shims/posix/macos/foreign_items.rs +++ b/src/shims/posix/macos/foreign_items.rs @@ -3,7 +3,6 @@ use rustc_target::spec::abi::Abi; use crate::*; -use helpers::strip_linker_suffix; use shims::foreign_items::EmulateByNameResult; use shims::posix::fs::EvalContextExt as _; use shims::posix::thread::EvalContextExt as _; @@ -20,7 +19,7 @@ fn emulate_foreign_item_by_name( ) -> InterpResult<'tcx, EmulateByNameResult> { let this = self.eval_context_mut(); - match strip_linker_suffix(&link_name.as_str()) { + match &*link_name.as_str() { // errno "__error" => { let &[] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; diff --git a/src/shims/windows/foreign_items.rs b/src/shims/windows/foreign_items.rs index 77f80753614..1921af35942 100644 --- a/src/shims/windows/foreign_items.rs +++ b/src/shims/windows/foreign_items.rs @@ -6,7 +6,6 @@ use rustc_target::spec::abi::Abi; use crate::*; -use helpers::strip_linker_suffix; use shims::foreign_items::EmulateByNameResult; use shims::windows::sync::EvalContextExt as _; @@ -27,7 +26,7 @@ fn emulate_foreign_item_by_name( // DWORD = ULONG = u32 // BOOL = i32 // BOOLEAN = u8 - match strip_linker_suffix(&link_name.as_str()) { + match &*link_name.as_str() { // Environment related shims "GetEnvironmentVariableW" => { let &[ref name, ref buf, ref size] =