about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <bjorn3@users.noreply.github.com>2020-06-20 12:01:24 +0200
committerbjorn3 <bjorn3@users.noreply.github.com>2020-06-20 12:01:24 +0200
commit5c6bf836fe3d4cfda1b827a5cd3982e5a588c0ff (patch)
tree02d019499f0cae68d666db04dcb0ac7294b09cc1
parentf718378f115f487b5ff6270453a9cbb79d808562 (diff)
downloadrust-5c6bf836fe3d4cfda1b827a5cd3982e5a588c0ff.tar.gz
rust-5c6bf836fe3d4cfda1b827a5cd3982e5a588c0ff.zip
Implement #[link_section]
Fixes #1047
-rw-r--r--example/std_example.rs2
-rw-r--r--patches/0024-libstd-Revert-arg-initialization-on-linux-to-not-req.patch26
-rw-r--r--src/constant.rs15
-rw-r--r--src/driver/jit.rs5
-rwxr-xr-xtest.sh2
5 files changed, 14 insertions, 36 deletions
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::<Vec<_>>());
+
     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 <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
-
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<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());
 
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::<Vec<_>>();
     let argv = args.iter().map(|arg| arg.as_ptr()).collect::<Vec<_>>();
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