@@ -11,8 +11,10 @@ use rustc_middle::middle::cstore::EncodedMetadata;
1111use rustc_middle:: mir:: mono:: { CodegenUnit , MonoItem } ;
1212use rustc_session:: cgu_reuse_tracker:: CguReuse ;
1313use rustc_session:: config:: { DebugInfo , OutputType } ;
14+ use rustc_session:: Session ;
1415
15- use cranelift_object:: ObjectModule ;
16+ use cranelift_codegen:: isa:: TargetIsa ;
17+ use cranelift_object:: { ObjectBuilder , ObjectModule } ;
1618
1719use crate :: { prelude:: * , BackendConfig } ;
1820
@@ -24,6 +26,16 @@ impl<HCX> HashStable<HCX> for ModuleCodegenResult {
2426 }
2527}
2628
29+ fn make_module ( sess : & Session , isa : Box < dyn TargetIsa > , name : String ) -> ObjectModule {
30+ let mut builder =
31+ ObjectBuilder :: new ( isa, name + ".o" , cranelift_module:: default_libcall_names ( ) ) . unwrap ( ) ;
32+ // Unlike cg_llvm, cg_clif defaults to disabling -Zfunction-sections. For cg_llvm binary size
33+ // is important, while cg_clif cares more about compilation times. Enabling -Zfunction-sections
34+ // can easily double the amount of time necessary to perform linking.
35+ builder. per_function_section ( sess. opts . debugging_opts . function_sections . unwrap_or ( false ) ) ;
36+ ObjectModule :: new ( builder)
37+ }
38+
2739fn emit_module (
2840 tcx : TyCtxt < ' _ > ,
2941 backend_config : & BackendConfig ,
@@ -105,7 +117,7 @@ fn module_codegen(
105117 let mono_items = cgu. items_in_deterministic_order ( tcx) ;
106118
107119 let isa = crate :: build_isa ( tcx. sess , & backend_config) ;
108- let mut module = crate :: backend :: make_module ( tcx. sess , isa, cgu_name. as_str ( ) . to_string ( ) ) ;
120+ let mut module = make_module ( tcx. sess , isa, cgu_name. as_str ( ) . to_string ( ) ) ;
109121
110122 let mut cx = crate :: CodegenCx :: new (
111123 tcx,
@@ -228,8 +240,7 @@ pub(crate) fn run_aot(
228240 tcx. sess . abort_if_errors ( ) ;
229241
230242 let isa = crate :: build_isa ( tcx. sess , & backend_config) ;
231- let mut allocator_module =
232- crate :: backend:: make_module ( tcx. sess , isa, "allocator_shim" . to_string ( ) ) ;
243+ let mut allocator_module = make_module ( tcx. sess , isa, "allocator_shim" . to_string ( ) ) ;
233244 assert_eq ! ( pointer_ty( tcx) , allocator_module. target_config( ) . pointer_type( ) ) ;
234245 let mut allocator_unwind_context = UnwindContext :: new ( tcx, allocator_module. isa ( ) , true ) ;
235246 let created_alloc_shim =
0 commit comments