Skip to content

Commit 201e632

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

5 files changed

Lines changed: 87 additions & 3 deletions

File tree

‎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
usecrate::builder::SBuilder;
1314
usecrate::declare::declare_simple_fn;
1415
usecrate::llvm::{self,False,True,Type,Value};
15-
usecrate::{SimpleCx, attributes, debuginfo};
16+
usecrate::{SimpleCx, attributes, debuginfo, llvm_util};
1617

1718
pub(crate)unsafefncodegen(
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+
letmut 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+
unsafefn__rust_alloc(_size:usize,_align:usize) -> *mutu8{
9+
0as*mutu8
10+
}
11+
12+
unsafeextern"Rust"{
13+
#[rustc_std_internal_symbol]
14+
fn__rust_alloc_error_handler(size:usize,align:usize) -> !;
15+
}
16+
17+
#[used]
18+
staticmutBUF:[u8;1024] = [0;1024];
19+
20+
#[unsafe(no_mangle)]
21+
extern"C"fninit(){
22+
unsafe{
23+
__rust_alloc_error_handler(0,0);
24+
}
25+
}
26+
27+
mod minicore {
28+
#[lang = "pointee_sized"]
29+
pubtraitPointeeSized{}
30+
31+
#[lang = "meta_sized"]
32+
pubtraitMetaSized:PointeeSized{}
33+
34+
#[lang = "sized"]
35+
pubtraitSized:MetaSized{}
36+
37+
#[lang = "copy"]
38+
pubtraitCopy{}
39+
implCopyforu8{}
40+
41+
#[lang = "drop_in_place"]
42+
fndrop_in_place<T>(_:*mutT){}
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+
fnmain(){
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+
fnverify_features(path:&Path){
21+
eprintln!("verify {path:?}");
22+
let file = rfs::read(&path);
23+
24+
letmut validator = wasmparser::Validator::new_with_features(wasmparser::WasmFeatures::WASM1);
25+
validator.validate_all(&file).unwrap();
26+
}

0 commit comments

Comments
 (0)