Skip to content

Commit 5c6bf83

Browse files
committed
Implement #[link_section]
Fixes #1047
1 parent f718378 commit 5c6bf83

File tree

5 files changed

+14
-36
lines changed

5 files changed

+14
-36
lines changed

example/std_example.rs

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use std::io::Write;
55
use std::ops::Generator;
66

77
fn main() {
8+
println!("{:?}", std::env::args().collect::<Vec<_>>());
9+
810
let mutex = std::sync::Mutex::new(());
911
let _guard = mutex.lock().unwrap();
1012

patches/0024-libstd-Revert-arg-initialization-on-linux-to-not-req.patch

-26
This file was deleted.

src/constant.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -264,22 +264,20 @@ fn data_id_for_static(
264264

265265
fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut Module<impl Backend>, cx: &mut ConstantCx) {
266266
while let Some(todo_item) = cx.todo.pop() {
267-
let (data_id, alloc) = match todo_item {
267+
let (data_id, alloc, section_name) = match todo_item {
268268
TodoItem::Alloc(alloc_id) => {
269269
//println!("alloc_id {}", alloc_id);
270270
let alloc = match tcx.get_global_alloc(alloc_id).unwrap() {
271271
GlobalAlloc::Memory(alloc) => alloc,
272272
GlobalAlloc::Function(_) | GlobalAlloc::Static(_) => unreachable!(),
273273
};
274274
let data_id = data_id_for_alloc_id(module, alloc_id, alloc.align);
275-
(data_id, alloc)
275+
(data_id, alloc, None)
276276
}
277277
TodoItem::Static(def_id) => {
278278
//println!("static {:?}", def_id);
279279

280-
if tcx.is_foreign_item(def_id) {
281-
continue;
282-
}
280+
let section_name = tcx.codegen_fn_attrs(def_id).link_section.map(|s| s.as_str());
283281

284282
let const_ = tcx.const_eval_poly(def_id).unwrap();
285283

@@ -298,7 +296,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut Module<impl Backend>, cx: &mu
298296
Linkage::Export // FIXME Set hidden visibility
299297
},
300298
);
301-
(data_id, alloc)
299+
(data_id, alloc, section_name)
302300
}
303301
};
304302

@@ -309,6 +307,11 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut Module<impl Backend>, cx: &mu
309307

310308
let mut data_ctx = DataContext::new();
311309

310+
if let Some(section_name) = section_name {
311+
// FIXME set correct segment for Mach-O files
312+
data_ctx.set_segment_section("", &*section_name);
313+
}
314+
312315
let bytes = alloc.inspect_with_undef_and_ptr_outside_interpreter(0..alloc.len()).to_vec();
313316
data_ctx.define(bytes.into_boxed_slice());
314317

src/driver/jit.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,8 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>) -> ! {
7575
unsafe { ::std::mem::transmute(finalized_main) };
7676

7777
let args = ::std::env::var("CG_CLIF_JIT_ARGS").unwrap_or_else(|_| String::new());
78-
let args = args
79-
.split(" ")
80-
.chain(Some(&*tcx.crate_name(LOCAL_CRATE).as_str().to_string()))
78+
let args = std::iter::once(&*tcx.crate_name(LOCAL_CRATE).as_str().to_string())
79+
.chain(args.split(" "))
8180
.map(|arg| CString::new(arg).unwrap())
8281
.collect::<Vec<_>>();
8382
let argv = args.iter().map(|arg| arg.as_ptr()).collect::<Vec<_>>();

test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ $RUN_WRAPPER ./target/out/dst_field_align || (echo $?; false)
5858

5959
echo "[AOT] std_example"
6060
$RUSTC example/std_example.rs --crate-type bin --target $TARGET_TRIPLE
61-
$RUN_WRAPPER ./target/out/std_example --target $TARGET_TRIPLE
61+
$RUN_WRAPPER ./target/out/std_example arg
6262

6363
echo "[AOT] subslice-patterns-const-eval"
6464
$RUSTC example/subslice-patterns-const-eval.rs --crate-type bin -Cpanic=abort --target $TARGET_TRIPLE

0 commit comments

Comments
 (0)