Skip to content

Commit 53cbe59

Browse files
authored
Rollup merge of rust-lang#145275 - StackOverflowExcept1on:fix-wasm32v1-none, r=alexcrichton
fix(compiler/rustc_codegen_llvm): apply `target-cpu` attribute Resolves rust-lang#140174 r? ``@alexcrichton`` try-job: `test-various*`
2 parents 46bed97 + 3a250b7 commit 53cbe59

File tree

5 files changed

+87
-3
lines changed

5 files changed

+87
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3283,7 +3283,7 @@ dependencies = [
32833283
"regex",
32843284
"serde_json",
32853285
"similar",
3286-
"wasmparser 0.219.2",
3286+
"wasmparser 0.236.0",
32873287
]
32883288

32893289
[[package]]

compiler/rustc_codegen_llvm/src/allocator.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ use rustc_middle::bug;
88
use rustc_middle::ty::TyCtxt;
99
use rustc_session::config::{DebugInfo, OomStrategy};
1010
use rustc_symbol_mangling::mangle_internal_symbol;
11+
use smallvec::SmallVec;
1112

1213
use crate::builder::SBuilder;
1314
use crate::declare::declare_simple_fn;
1415
use crate::llvm::{self, False, True, Type, Value};
15-
use crate::{SimpleCx, attributes, debuginfo};
16+
use crate::{SimpleCx, attributes, debuginfo, llvm_util};
1617

1718
pub(crate) unsafe fn codegen(
1819
tcx: TyCtxt<'_>,
@@ -147,6 +148,20 @@ fn create_wrapper_function(
147148
llvm::Visibility::from_generic(tcx.sess.default_visibility()),
148149
ty,
149150
);
151+
152+
let mut attrs = SmallVec::<[_; 2]>::new();
153+
154+
let target_cpu = llvm_util::target_cpu(tcx.sess);
155+
let target_cpu_attr = llvm::CreateAttrStringValue(cx.llcx, "target-cpu", target_cpu);
156+
157+
let tune_cpu_attr = llvm_util::tune_cpu(tcx.sess)
158+
.map(|tune_cpu| llvm::CreateAttrStringValue(cx.llcx, "tune-cpu", tune_cpu));
159+
160+
attrs.push(target_cpu_attr);
161+
attrs.extend(tune_cpu_attr);
162+
163+
attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &attrs);
164+
150165
let no_return = if no_return {
151166
// -> ! DIFlagNoReturn
152167
let no_return = llvm::AttributeKind::NoReturn.create_attr(cx.llcx);

src/tools/run-make-support/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ object = "0.37"
1717
regex = "1.11"
1818
serde_json = "1.0"
1919
similar = "2.7"
20-
wasmparser = { version = "0.219", default-features = false, features = ["std"] }
20+
wasmparser = { version = "0.236", default-features = false, features = ["std", "features", "validate"] }
2121
# tidy-alphabetical-end
2222

2323
# Shared with bootstrap and compiletest
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#![no_core]
2+
#![crate_type = "cdylib"]
3+
#![feature(no_core, lang_items, allocator_internals, rustc_attrs)]
4+
#![needs_allocator]
5+
#![allow(internal_features)]
6+
7+
#[rustc_std_internal_symbol]
8+
unsafe fn __rust_alloc(_size: usize, _align: usize) -> *mut u8 {
9+
0 as *mut u8
10+
}
11+
12+
unsafe extern "Rust" {
13+
#[rustc_std_internal_symbol]
14+
fn __rust_alloc_error_handler(size: usize, align: usize) -> !;
15+
}
16+
17+
#[used]
18+
static mut BUF: [u8; 1024] = [0; 1024];
19+
20+
#[unsafe(no_mangle)]
21+
extern "C" fn init() {
22+
unsafe {
23+
__rust_alloc_error_handler(0, 0);
24+
}
25+
}
26+
27+
mod minicore {
28+
#[lang = "pointee_sized"]
29+
pub trait PointeeSized {}
30+
31+
#[lang = "meta_sized"]
32+
pub trait MetaSized: PointeeSized {}
33+
34+
#[lang = "sized"]
35+
pub trait Sized: MetaSized {}
36+
37+
#[lang = "copy"]
38+
pub trait Copy {}
39+
impl Copy for u8 {}
40+
41+
#[lang = "drop_in_place"]
42+
fn drop_in_place<T>(_: *mut T) {}
43+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//@ only-wasm32-wasip1
2+
3+
use std::path::Path;
4+
5+
use run_make_support::{rfs, rustc, wasmparser};
6+
7+
fn main() {
8+
rustc()
9+
.input("foo.rs")
10+
.target("wasm32-wasip1")
11+
.target_cpu("mvp")
12+
.opt_level("z")
13+
.lto("fat")
14+
.linker_plugin_lto("on")
15+
.link_arg("--import-memory")
16+
.run();
17+
verify_features(Path::new("foo.wasm"));
18+
}
19+
20+
fn verify_features(path: &Path) {
21+
eprintln!("verify {path:?}");
22+
let file = rfs::read(&path);
23+
24+
let mut validator = wasmparser::Validator::new_with_features(wasmparser::WasmFeatures::WASM1);
25+
validator.validate_all(&file).unwrap();
26+
}

0 commit comments

Comments
 (0)