Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 323a747

Browse files
committed
Move LinkerInfo into CrateInfo
1 parent 9a27044 commit 323a747

File tree

7 files changed

+12
-16
lines changed

7 files changed

+12
-16
lines changed

compiler/rustc_codegen_cranelift/src/driver/aot.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
use std::path::PathBuf;
55

66
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
7-
use rustc_codegen_ssa::back::linker::LinkerInfo;
87
use rustc_codegen_ssa::{CodegenResults, CompiledModule, CrateInfo, ModuleKind};
98
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
109
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
@@ -296,8 +295,7 @@ pub(crate) fn run_aot(
296295
allocator_module,
297296
metadata_module,
298297
metadata,
299-
linker_info: LinkerInfo::new(tcx, crate::target_triple(tcx.sess).to_string()),
300-
crate_info: CrateInfo::new(tcx),
298+
crate_info: CrateInfo::new(tcx, crate::target_triple(tcx.sess).to_string()),
301299
},
302300
work_products,
303301
))

compiler/rustc_codegen_cranelift/src/driver/jit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ fn load_imported_symbols_for_jit(tcx: TyCtxt<'_>) -> Vec<(String, *const u8)> {
178178

179179
let mut dylib_paths = Vec::new();
180180

181-
let crate_info = CrateInfo::new(tcx);
181+
let crate_info = CrateInfo::new(tcx, "dummy_target_cpu".to_string());
182182
let formats = tcx.dependency_formats(());
183183
let data = &formats
184184
.iter()

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,7 +1804,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
18041804
// FIXME: Move `/LIBPATH` addition for uwp targets from the linker construction
18051805
// to the linker args construction.
18061806
assert!(base_cmd.get_args().is_empty() || sess.target.vendor == "uwp");
1807-
let cmd = &mut *codegen_results.linker_info.to_linker(base_cmd, &sess, flavor);
1807+
let cmd = &mut *codegen_results.crate_info.linker_info.to_linker(base_cmd, &sess, flavor);
18081808
let link_output_kind = link_output_kind(sess, crate_type);
18091809

18101810
// ------------ Early order-dependent options ------------
@@ -1986,10 +1986,10 @@ fn add_order_independent_options(
19861986
if flavor == LinkerFlavor::PtxLinker {
19871987
// Provide the linker with fallback to internal `target-cpu`.
19881988
cmd.arg("--fallback-arch");
1989-
cmd.arg(&codegen_results.linker_info.target_cpu);
1989+
cmd.arg(&codegen_results.crate_info.linker_info.target_cpu);
19901990
} else if flavor == LinkerFlavor::BpfLinker {
19911991
cmd.arg("--cpu");
1992-
cmd.arg(&codegen_results.linker_info.target_cpu);
1992+
cmd.arg(&codegen_results.crate_info.linker_info.target_cpu);
19931993
cmd.arg("--cpu-features");
19941994
cmd.arg(match &sess.opts.cg.target_feature {
19951995
feat if !feat.is_empty() => feat,

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn disable_localization(linker: &mut Command) {
3535

3636
/// For all the linkers we support, and information they might
3737
/// need out of the shared crate context before we get rid of it.
38-
#[derive(Encodable, Decodable)]
38+
#[derive(Debug, Encodable, Decodable)]
3939
pub struct LinkerInfo {
4040
pub(super) target_cpu: String,
4141
exports: FxHashMap<CrateType, Vec<String>>,

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use super::link::{self, ensure_removed};
2-
use super::linker::LinkerInfo;
32
use super::lto::{self, SerializedModule};
43
use super::symbol_export::symbol_name_for_instance_in_crate;
54

@@ -430,8 +429,7 @@ pub fn start_async_codegen<B: ExtraBackendMethods>(
430429
let no_builtins = tcx.sess.contains_name(crate_attrs, sym::no_builtins);
431430
let is_compiler_builtins = tcx.sess.contains_name(crate_attrs, sym::compiler_builtins);
432431

433-
let linker_info = LinkerInfo::new(tcx, target_cpu);
434-
let crate_info = CrateInfo::new(tcx);
432+
let crate_info = CrateInfo::new(tcx, target_cpu);
435433

436434
let regular_config =
437435
ModuleConfig::new(ModuleKind::Regular, sess, no_builtins, is_compiler_builtins);
@@ -461,7 +459,6 @@ pub fn start_async_codegen<B: ExtraBackendMethods>(
461459
OngoingCodegen {
462460
backend,
463461
metadata,
464-
linker_info,
465462
crate_info,
466463

467464
coordinator_send,
@@ -1799,7 +1796,6 @@ impl SharedEmitterMain {
17991796
pub struct OngoingCodegen<B: ExtraBackendMethods> {
18001797
pub backend: B,
18011798
pub metadata: EncodedMetadata,
1802-
pub linker_info: LinkerInfo,
18031799
pub crate_info: CrateInfo,
18041800
pub coordinator_send: Sender<Box<dyn Any + Send>>,
18051801
pub codegen_worker_receive: Receiver<Message<B>>,
@@ -1842,7 +1838,6 @@ impl<B: ExtraBackendMethods> OngoingCodegen<B> {
18421838
(
18431839
CodegenResults {
18441840
metadata: self.metadata,
1845-
linker_info: self.linker_info,
18461841
crate_info: self.crate_info,
18471842

18481843
modules: compiled_modules.modules,

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::back::linker::LinkerInfo;
12
use crate::back::write::{
23
compute_per_cgu_lto_type, start_async_codegen, submit_codegened_module_to_llvm,
34
submit_post_lto_module_to_llvm, submit_pre_lto_module_to_llvm, ComputedLtoType, OngoingCodegen,
@@ -754,7 +755,8 @@ impl<B: ExtraBackendMethods> Drop for AbortCodegenOnDrop<B> {
754755
}
755756

756757
impl CrateInfo {
757-
pub fn new(tcx: TyCtxt<'_>) -> CrateInfo {
758+
pub fn new(tcx: TyCtxt<'_>, target_cpu: String) -> CrateInfo {
759+
let linker_info = LinkerInfo::new(tcx, target_cpu);
758760
let local_crate_name = tcx.crate_name(LOCAL_CRATE);
759761
let crate_attrs = tcx.hir().attrs(rustc_hir::CRATE_HIR_ID);
760762
let subsystem = tcx.sess.first_attr_value_str_by_name(crate_attrs, sym::windows_subsystem);
@@ -770,6 +772,7 @@ impl CrateInfo {
770772
});
771773

772774
let mut info = CrateInfo {
775+
linker_info,
773776
local_crate_name,
774777
panic_runtime: None,
775778
compiler_builtins: None,

compiler/rustc_codegen_ssa/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ impl From<&cstore::NativeLib> for NativeLib {
135135
/// and the corresponding properties without referencing information outside of a `CrateInfo`.
136136
#[derive(Debug, Encodable, Decodable)]
137137
pub struct CrateInfo {
138+
pub linker_info: back::linker::LinkerInfo,
138139
pub local_crate_name: Symbol,
139140
pub panic_runtime: Option<CrateNum>,
140141
pub compiler_builtins: Option<CrateNum>,
@@ -157,7 +158,6 @@ pub struct CodegenResults {
157158
pub allocator_module: Option<CompiledModule>,
158159
pub metadata_module: Option<CompiledModule>,
159160
pub metadata: rustc_middle::middle::cstore::EncodedMetadata,
160-
pub linker_info: back::linker::LinkerInfo,
161161
pub crate_info: CrateInfo,
162162
}
163163

0 commit comments

Comments
 (0)