From 95e6481d02ed600ca19775414231de774febe9a7 Mon Sep 17 00:00:00 2001 From: Alan Egerton Date: Fri, 30 Apr 2021 11:02:34 +0100 Subject: [PATCH] Set correct segment from #[link_section] for MachO --- src/constant.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/constant.rs b/src/constant.rs index 0a0e02d2639..39daf887a22 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -374,8 +374,19 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant data_ctx.set_align(alloc.align.bytes()); if let Some(section_name) = section_name { - // FIXME set correct segment for Mach-O files - data_ctx.set_segment_section("", &*section_name); + let (segment_name, section_name) = if tcx.sess.target.is_like_osx { + 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();