From 38531b8f426a5eb9c0b96dd2e83fa4e2ca917db5 Mon Sep 17 00:00:00 2001 From: Carlo Kok Date: Mon, 8 Jun 2020 19:56:21 +0200 Subject: [PATCH] Rust fmt fixes --- cranelift/faerie/src/backend.rs | 2 +- cranelift/module/src/data_context.rs | 9 +++-- cranelift/object/src/backend.rs | 51 +++++++++++++++------------- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/cranelift/faerie/src/backend.rs b/cranelift/faerie/src/backend.rs index 29ae59907f..192cf455f2 100644 --- a/cranelift/faerie/src/backend.rs +++ b/cranelift/faerie/src/backend.rs @@ -211,7 +211,7 @@ impl Backend for FaerieBackend { ref data_decls, ref function_relocs, ref data_relocs, - section: ref datasection + section: ref datasection, } = data_ctx.description(); assert!(datasection.is_none(), "Custom sections not supported"); diff --git a/cranelift/module/src/data_context.rs b/cranelift/module/src/data_context.rs index a20d734cd2..0b732b41f7 100644 --- a/cranelift/module/src/data_context.rs +++ b/cranelift/module/src/data_context.rs @@ -47,7 +47,7 @@ pub struct DataDescription { /// Data addresses to write at specified offsets. pub data_relocs: Vec<(CodeOffset, ir::GlobalValue, Addend)>, /// Object file section - pub section: Option<(std::string::String, std::string::String)> + pub section: Option<(std::string::String, std::string::String)>, } /// This is to data objects what cranelift_codegen::Context is to functions. @@ -65,7 +65,7 @@ impl DataContext { data_decls: PrimaryMap::new(), function_relocs: vec![], data_relocs: vec![], - section: None + section: None, }, } } @@ -95,7 +95,10 @@ impl DataContext { /// Override the segment/section for data, only supported on Object backend pub fn set_section(&mut self, seg: &str, sec: &str) { - self.description.section = Some((std::string::String::from(seg), std::string::String::from(sec))) + self.description.section = Some(( + std::string::String::from(seg), + std::string::String::from(sec), + )) } /// Declare an external function import. diff --git a/cranelift/object/src/backend.rs b/cranelift/object/src/backend.rs index 7342839fd5..1b88023028 100644 --- a/cranelift/object/src/backend.rs +++ b/cranelift/object/src/backend.rs @@ -234,7 +234,7 @@ impl Backend for ObjectBackend { ref data_decls, ref function_relocs, ref data_relocs, - section: ref datasection + section: ref datasection, } = data_ctx.description(); let reloc_size = match self.isa.triple().pointer_width().unwrap() { @@ -265,31 +265,36 @@ impl Backend for ObjectBackend { } let symbol = self.data_objects[data_id].unwrap(); - let section = - if datasection.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 + let section = if datasection.is_none() { + let section_kind = if let Init::Zeros { .. } = *init { + if tls { + StandardSection::UninitializedTls } else { - StandardSection::ReadOnlyDataWithRel - }; - self.object.section_id(section_kind) + StandardSection::UninitializedData + } + } else if tls { + StandardSection::Tls + } else if writable { + StandardSection::Data + } else if relocs.is_empty() { + StandardSection::ReadOnlyData } else { - assert!(!tls, "Tls data cannot be in named section"); - let (seg, sec) = &datasection.as_ref().unwrap(); - self.object.add_section(seg.clone().into_bytes(), sec.clone().into_bytes(), - if writable { SectionKind::Data } else { SectionKind::ReadOnlyData } - ) + StandardSection::ReadOnlyDataWithRel }; + self.object.section_id(section_kind) + } else { + assert!(!tls, "Tls data cannot be in named section"); + let (seg, sec) = &datasection.as_ref().unwrap(); + self.object.add_section( + seg.clone().into_bytes(), + sec.clone().into_bytes(), + if writable { + SectionKind::Data + } else { + SectionKind::ReadOnlyData + }, + ) + }; let align = u64::from(align.unwrap_or(1)); let offset = match *init {