Skip to content

Commit 6d30315

Browse files
authored
Merge pull request #1169 from eggyal/macho-link-section
Set correct segment from #[link_section] for MachO
2 parents 15c8d31 + 95e6481 commit 6d30315

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/constant.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,19 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
374374
data_ctx.set_align(alloc.align.bytes());
375375

376376
if let Some(section_name) = section_name {
377-
// FIXME set correct segment for Mach-O files
378-
data_ctx.set_segment_section("", &*section_name);
377+
let (segment_name, section_name) = if tcx.sess.target.is_like_osx {
378+
if let Some(names) = section_name.split_once(',') {
379+
names
380+
} else {
381+
tcx.sess.fatal(&format!(
382+
"#[link_section = \"{}\"] is not valid for macos target: must be segment and section separated by comma",
383+
section_name
384+
));
385+
}
386+
} else {
387+
("", &*section_name)
388+
};
389+
data_ctx.set_segment_section(segment_name, section_name);
379390
}
380391

381392
let bytes = alloc.inspect_with_uninit_and_ptr_outside_interpreter(0..alloc.len()).to_vec();

0 commit comments

Comments
 (0)