diff --git a/example/std_example.rs b/example/std_example.rs index d7e8cf73ea8..530e5549b43 100644 --- a/example/std_example.rs +++ b/example/std_example.rs @@ -5,6 +5,8 @@ use std::io::Write; use std::ops::Generator; fn main() { + println!("{:?}", std::env::args().collect::>()); + let mutex = std::sync::Mutex::new(()); let _guard = mutex.lock().unwrap(); diff --git a/patches/0024-libstd-Revert-arg-initialization-on-linux-to-not-req.patch b/patches/0024-libstd-Revert-arg-initialization-on-linux-to-not-req.patch deleted file mode 100644 index 599da32ee82..00000000000 --- a/patches/0024-libstd-Revert-arg-initialization-on-linux-to-not-req.patch +++ /dev/null @@ -1,26 +0,0 @@ -From eaa0c3eac2067c7c08913653ebef10c103c1255f Mon Sep 17 00:00:00 2001 -From: bjorn3 -Date: Mon, 16 Dec 2019 11:46:10 +0100 -Subject: [PATCH] [libstd] Revert arg initialization on linux to not require - #[link_section] - ---- - src/libstd/sys/unix/args.rs | 5 +---- - 1 file changed, 1 insertion(+), 4 deletions(-) - -diff --git a/src/libstd/sys/unix/args.rs b/src/libstd/sys/unix/args.rs -index 2ed1585..b4b021a 100644 ---- a/src/libstd/sys/unix/args.rs -+++ b/src/libstd/sys/unix/args.rs -@@ -83,7 +83,7 @@ mod imp { - // On Linux-GNU, we rely on `ARGV_INIT_ARRAY` below to initialize - // `ARGC` and `ARGV`. But in Miri that does not actually happen so we - // still initialize here. -- #[cfg(any(miri, not(all(target_os = "linux", target_env = "gnu"))))] -+ // `#[link_section]` is not yet supported by cg_clif - really_init(_argc, _argv); - } - --- -2.20.1 - diff --git a/src/constant.rs b/src/constant.rs index 84981c72fc0..cb797b3a5fe 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -264,7 +264,7 @@ fn data_id_for_static( fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut Module, cx: &mut ConstantCx) { while let Some(todo_item) = cx.todo.pop() { - let (data_id, alloc) = match todo_item { + let (data_id, alloc, section_name) = match todo_item { TodoItem::Alloc(alloc_id) => { //println!("alloc_id {}", alloc_id); let alloc = match tcx.get_global_alloc(alloc_id).unwrap() { @@ -272,14 +272,12 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut Module, cx: &mu GlobalAlloc::Function(_) | GlobalAlloc::Static(_) => unreachable!(), }; let data_id = data_id_for_alloc_id(module, alloc_id, alloc.align); - (data_id, alloc) + (data_id, alloc, None) } TodoItem::Static(def_id) => { //println!("static {:?}", def_id); - if tcx.is_foreign_item(def_id) { - continue; - } + let section_name = tcx.codegen_fn_attrs(def_id).link_section.map(|s| s.as_str()); let const_ = tcx.const_eval_poly(def_id).unwrap(); @@ -298,7 +296,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut Module, cx: &mu Linkage::Export // FIXME Set hidden visibility }, ); - (data_id, alloc) + (data_id, alloc, section_name) } }; @@ -309,6 +307,11 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut Module, cx: &mu let mut data_ctx = DataContext::new(); + if let Some(section_name) = section_name { + // FIXME set correct segment for Mach-O files + data_ctx.set_segment_section("", &*section_name); + } + let bytes = alloc.inspect_with_undef_and_ptr_outside_interpreter(0..alloc.len()).to_vec(); data_ctx.define(bytes.into_boxed_slice()); diff --git a/src/driver/jit.rs b/src/driver/jit.rs index ab6c9da25ad..15e4947ca46 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -75,9 +75,8 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>) -> ! { unsafe { ::std::mem::transmute(finalized_main) }; let args = ::std::env::var("CG_CLIF_JIT_ARGS").unwrap_or_else(|_| String::new()); - let args = args - .split(" ") - .chain(Some(&*tcx.crate_name(LOCAL_CRATE).as_str().to_string())) + let args = std::iter::once(&*tcx.crate_name(LOCAL_CRATE).as_str().to_string()) + .chain(args.split(" ")) .map(|arg| CString::new(arg).unwrap()) .collect::>(); let argv = args.iter().map(|arg| arg.as_ptr()).collect::>(); diff --git a/test.sh b/test.sh index cea435d8963..7127ba79fe9 100755 --- a/test.sh +++ b/test.sh @@ -58,7 +58,7 @@ $RUN_WRAPPER ./target/out/dst_field_align || (echo $?; false) echo "[AOT] std_example" $RUSTC example/std_example.rs --crate-type bin --target $TARGET_TRIPLE -$RUN_WRAPPER ./target/out/std_example --target $TARGET_TRIPLE +$RUN_WRAPPER ./target/out/std_example arg echo "[AOT] subslice-patterns-const-eval" $RUSTC example/subslice-patterns-const-eval.rs --crate-type bin -Cpanic=abort --target $TARGET_TRIPLE