Skip to content

Commit 47e4a62

Browse files
committed
Move all code out of backend.rs
1 parent 1461751 commit 47e4a62

File tree

6 files changed

+20
-24
lines changed

6 files changed

+20
-24
lines changed

src/debuginfo/emit.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ use rustc_data_structures::fx::FxHashMap;
66
use gimli::write::{Address, AttributeValue, EndianVec, Result, Sections, Writer};
77
use gimli::{RunTimeEndian, SectionId};
88

9-
use crate::backend::WriteDebugInfo;
10-
9+
use super::object::WriteDebugInfo;
1110
use super::DebugContext;
1211

1312
impl DebugContext<'_> {

src/debuginfo/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
mod emit;
44
mod line_info;
5+
mod object;
56
mod unwind;
67

78
use crate::prelude::*;

src/backend.rs renamed to src/debuginfo/object.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
//! Abstraction around the object writing crate
2-
31
use std::convert::{TryFrom, TryInto};
42

53
use rustc_data_structures::fx::FxHashMap;
6-
use rustc_session::Session;
74

8-
use cranelift_codegen::isa::TargetIsa;
95
use cranelift_module::FuncId;
10-
use cranelift_object::{ObjectBuilder, ObjectModule, ObjectProduct};
6+
use cranelift_object::ObjectProduct;
117

128
use object::write::{Relocation, StandardSegment};
139
use object::{RelocationEncoding, SectionKind};
@@ -16,7 +12,7 @@ use gimli::SectionId;
1612

1713
use crate::debuginfo::{DebugReloc, DebugRelocName};
1814

19-
pub(crate) trait WriteDebugInfo {
15+
pub(super) trait WriteDebugInfo {
2016
type SectionId: Copy;
2117

2218
fn add_debug_section(&mut self, name: SectionId, data: Vec<u8>) -> Self::SectionId;
@@ -87,13 +83,3 @@ impl WriteDebugInfo for ObjectProduct {
8783
.unwrap();
8884
}
8985
}
90-
91-
pub(crate) fn make_module(sess: &Session, isa: Box<dyn TargetIsa>, name: String) -> ObjectModule {
92-
let mut builder =
93-
ObjectBuilder::new(isa, name + ".o", cranelift_module::default_libcall_names()).unwrap();
94-
// Unlike cg_llvm, cg_clif defaults to disabling -Zfunction-sections. For cg_llvm binary size
95-
// is important, while cg_clif cares more about compilation times. Enabling -Zfunction-sections
96-
// can easily double the amount of time necessary to perform linking.
97-
builder.per_function_section(sess.opts.debugging_opts.function_sections.unwrap_or(false));
98-
ObjectModule::new(builder)
99-
}

src/debuginfo/unwind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use cranelift_object::ObjectProduct;
88
use gimli::write::{Address, CieId, EhFrame, FrameTable, Section};
99
use gimli::RunTimeEndian;
1010

11-
use crate::backend::WriteDebugInfo;
11+
use super::object::WriteDebugInfo;
1212

1313
pub(crate) struct UnwindContext {
1414
endian: RunTimeEndian,

src/driver/aot.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ use rustc_middle::middle::cstore::EncodedMetadata;
1111
use rustc_middle::mir::mono::{CodegenUnit, MonoItem};
1212
use rustc_session::cgu_reuse_tracker::CguReuse;
1313
use 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

1719
use 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+
2739
fn 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 =

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ mod abi;
4545
mod allocator;
4646
mod analyze;
4747
mod archive;
48-
mod backend;
4948
mod base;
5049
mod cast;
5150
mod codegen_i128;

0 commit comments

Comments
 (0)