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:
@@ -271,6 +271,7 @@ impl Backend for ObjectBackend {
|
||||
ref data_decls,
|
||||
ref function_relocs,
|
||||
ref data_relocs,
|
||||
ref custom_segment_section,
|
||||
} = data_ctx.description();
|
||||
|
||||
let reloc_size = match self.isa.triple().pointer_width().unwrap() {
|
||||
@@ -301,22 +302,40 @@ impl Backend for ObjectBackend {
|
||||
}
|
||||
|
||||
let symbol = self.data_objects[data_id].unwrap();
|
||||
let section_kind = if let Init::Zeros { .. } = *init {
|
||||
if tls {
|
||||
StandardSection::UninitializedTls
|
||||
let section = if custom_segment_section.is_none() {
|
||||
let section_kind = if let Init::Zeros { .. } = *init {
|
||||
if tls {
|
||||
StandardSection::UninitializedTls
|
||||
} else {
|
||||
StandardSection::UninitializedData
|
||||
}
|
||||
} else if tls {
|
||||
StandardSection::Tls
|
||||
} else if writable {
|
||||
StandardSection::Data
|
||||
} else if relocs.is_empty() {
|
||||
StandardSection::ReadOnlyData
|
||||
} else {
|
||||
StandardSection::UninitializedData
|
||||
}
|
||||
} else if tls {
|
||||
StandardSection::Tls
|
||||
} else if writable {
|
||||
StandardSection::Data
|
||||
} else if relocs.is_empty() {
|
||||
StandardSection::ReadOnlyData
|
||||
StandardSection::ReadOnlyDataWithRel
|
||||
};
|
||||
self.object.section_id(section_kind)
|
||||
} else {
|
||||
StandardSection::ReadOnlyDataWithRel
|
||||
if tls {
|
||||
return Err(cranelift_module::ModuleError::Backend(anyhow::anyhow!(
|
||||
"Custom section not supported for TLS"
|
||||
)));
|
||||
}
|
||||
let (seg, sec) = &custom_segment_section.as_ref().unwrap();
|
||||
self.object.add_section(
|
||||
seg.clone().into_bytes(),
|
||||
sec.clone().into_bytes(),
|
||||
if writable {
|
||||
SectionKind::Data
|
||||
} else {
|
||||
SectionKind::ReadOnlyData
|
||||
},
|
||||
)
|
||||
};
|
||||
let section = self.object.section_id(section_kind);
|
||||
|
||||
let align = u64::from(align.unwrap_or(1));
|
||||
let offset = match *init {
|
||||
|
||||
Reference in New Issue
Block a user