Set correct segment from #[link_section] for MachO

This commit is contained in:
Alan Egerton 2021-04-30 11:02:34 +01:00
parent ddd4ce2553
commit 95e6481d02
No known key found for this signature in database
GPG Key ID: 68A65BCD9D289FFE

View File

@ -374,8 +374,19 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
data_ctx.set_align(alloc.align.bytes()); data_ctx.set_align(alloc.align.bytes());
if let Some(section_name) = section_name { if let Some(section_name) = section_name {
// FIXME set correct segment for Mach-O files let (segment_name, section_name) = if tcx.sess.target.is_like_osx {
data_ctx.set_segment_section("", &*section_name); if let Some(names) = section_name.split_once(',') {
names
} else {
tcx.sess.fatal(&format!(
"#[link_section = \"{}\"] is not valid for macos target: must be segment and section separated by comma",
section_name
));
}
} else {
("", &*section_name)
};
data_ctx.set_segment_section(segment_name, section_name);
} }
let bytes = alloc.inspect_with_uninit_and_ptr_outside_interpreter(0..alloc.len()).to_vec(); let bytes = alloc.inspect_with_uninit_and_ptr_outside_interpreter(0..alloc.len()).to_vec();