]> git.lizzy.rs Git - rust.git/blobdiff - src/backend.rs
Rollup merge of #81618 - bjorn3:sync_cg_clif-2021-02-01, r=bjorn3
[rust.git] / src / backend.rs
index c0df85f681c92738f2213fb504a80f1c7a678415..0ce34c904bdcc43d274263f46035c5302d5b5a78 100644 (file)
@@ -73,7 +73,7 @@ fn add_debug_section(
         // FIXME use SHT_X86_64_UNWIND for .eh_frame
         let section_id = self.object.add_section(
             segment,
-            name.clone(),
+            name,
             if id == SectionId::EhFrame {
                 SectionKind::ReadOnlyData
             } else {
@@ -132,10 +132,16 @@ fn add_constructor(&mut self, func_id: FuncId) {
         let init_array_section =
             self.object
                 .add_section(segment.to_vec(), b".init_array".to_vec(), SectionKind::Data);
+        let address_size = self
+            .object
+            .architecture()
+            .address_size()
+            .expect("address_size must be known")
+            .bytes();
         self.object.append_section_data(
             init_array_section,
             &std::iter::repeat(0)
-                .take(8 /*FIXME pointer size*/)
+                .take(address_size.into())
                 .collect::<Vec<u8>>(),
             8,
         );
@@ -144,7 +150,7 @@ fn add_constructor(&mut self, func_id: FuncId) {
                 init_array_section,
                 object::write::Relocation {
                     offset: 0,
-                    size: 64, // FIXME pointer size
+                    size: address_size * 8,
                     kind: RelocationKind::Absolute,
                     encoding: RelocationEncoding::Generic,
                     symbol,
@@ -156,7 +162,7 @@ fn add_constructor(&mut self, func_id: FuncId) {
 }
 
 pub(crate) fn with_object(sess: &Session, name: &str, f: impl FnOnce(&mut Object)) -> Vec<u8> {
-    let triple = crate::build_isa(sess, true).triple().clone();
+    let triple = crate::build_isa(sess).triple().clone();
 
     let binary_format = match triple.binary_format {
         target_lexicon::BinaryFormat::Elf => object::BinaryFormat::Elf,
@@ -187,14 +193,14 @@ pub(crate) fn with_object(sess: &Session, name: &str, f: impl FnOnce(&mut Object
 
 pub(crate) fn make_module(sess: &Session, name: String) -> ObjectModule {
     let mut builder = ObjectBuilder::new(
-        crate::build_isa(sess, true),
+        crate::build_isa(sess),
         name + ".o",
         cranelift_module::default_libcall_names(),
     )
     .unwrap();
-    if std::env::var("CG_CLIF_FUNCTION_SECTIONS").is_ok() {
-        builder.per_function_section(true);
-    }
-    let module = ObjectModule::new(builder);
-    module
+    // Unlike cg_llvm, cg_clif defaults to disabling -Zfunction-sections. For cg_llvm binary size
+    // is important, while cg_clif cares more about compilation times. Enabling -Zfunction-sections
+    // can easily double the amount of time necessary to perform linking.
+    builder.per_function_section(sess.opts.debugging_opts.function_sections.unwrap_or(false));
+    ObjectModule::new(builder)
 }