Merge pull request #1836 from carlokok/feature/object_file_section

Cranelift: Module data apis should allow specifying the object file section
This commit is contained in:
Pat Hickey
2020-06-17 10:49:09 -07:00
committed by GitHub
4 changed files with 52 additions and 13 deletions

View File

@@ -3,7 +3,9 @@
use cranelift_codegen::binemit::{Addend, CodeOffset};
use cranelift_codegen::entity::PrimaryMap;
use cranelift_codegen::ir;
use std::borrow::ToOwned;
use std::boxed::Box;
use std::string::String;
use std::vec::Vec;
/// This specifies how data is to be initialized.
@@ -46,6 +48,8 @@ pub struct DataDescription {
pub function_relocs: Vec<(CodeOffset, ir::FuncRef)>,
/// Data addresses to write at specified offsets.
pub data_relocs: Vec<(CodeOffset, ir::GlobalValue, Addend)>,
/// Object file section
pub custom_segment_section: Option<(String, String)>,
}
/// This is to data objects what cranelift_codegen::Context is to functions.
@@ -63,6 +67,7 @@ impl DataContext {
data_decls: PrimaryMap::new(),
function_relocs: vec![],
data_relocs: vec![],
custom_segment_section: None,
},
}
}
@@ -90,6 +95,11 @@ impl DataContext {
self.description.init = Init::Bytes { contents };
}
/// Override the segment/section for data, only supported on Object backend
pub fn set_segment_section(&mut self, seg: &str, sec: &str) {
self.description.custom_segment_section = Some((seg.to_owned(), sec.to_owned()))
}
/// Declare an external function import.
///
/// Users of the `Module` API generally should call