Implement #[link_section]

Fixes #1047
This commit is contained in:
bjorn3 2020-06-20 12:01:24 +02:00
parent f718378f11
commit 5c6bf836fe
5 changed files with 14 additions and 36 deletions

View File

@ -5,6 +5,8 @@ use std::io::Write;
use std::ops::Generator;
fn main() {
println!("{:?}", std::env::args().collect::<Vec<_>>());
let mutex = std::sync::Mutex::new(());
let _guard = mutex.lock().unwrap();

View File

@ -1,26 +0,0 @@
From eaa0c3eac2067c7c08913653ebef10c103c1255f Mon Sep 17 00:00:00 2001
From: bjorn3 <bjorn3@users.noreply.github.com>
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

View File

@ -264,7 +264,7 @@ fn data_id_for_static(
fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut Module<impl Backend>, 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<impl Backend>, 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<impl Backend>, 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<impl Backend>, 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());

View File

@ -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::<Vec<_>>();
let argv = args.iter().map(|arg| arg.as_ptr()).collect::<Vec<_>>();

View File

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