Remove strip_linker_suffix

This commit is contained in:
hyd-dev 2021-06-15 01:16:38 +08:00
parent a67a65359f
commit 9011524454
No known key found for this signature in database
GPG Key ID: 74FA7FD5B8DA14B8
6 changed files with 10 additions and 23 deletions

View File

@ -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",

View File

@ -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!(),

View File

@ -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)?;

View File

@ -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)?;

View File

@ -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)?;

View File

@ -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] =