diff options
| author | bjorn3 <bjorn3@users.noreply.github.com> | 2021-03-28 22:14:09 +0200 |
|---|---|---|
| committer | bjorn3 <bjorn3@users.noreply.github.com> | 2021-05-02 18:00:20 +0200 |
| commit | 808090eb073d8b2d56479045b6ef0fe67872a077 (patch) | |
| tree | 7d64ab8200c8bef48d5543924f8e3b9b3691361a /compiler/rustc_codegen_ssa/src/back | |
| parent | 673c1b6e496432e68bca148fcfdae647ad21befb (diff) | |
| download | rust-808090eb073d8b2d56479045b6ef0fe67872a077.tar.gz rust-808090eb073d8b2d56479045b6ef0fe67872a077.zip | |
Pass target_cpu to LinkerInfo::new instead of link_binary
This is one step towards separating the linking code from codegen backends
Diffstat (limited to 'compiler/rustc_codegen_ssa/src/back')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/link.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/linker.rs | 43 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/write.rs | 3 |
3 files changed, 20 insertions, 33 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 686ebc13ea3..857088fe566 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -50,7 +50,6 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>( codegen_results: &CodegenResults, outputs: &OutputFilenames, crate_name: &str, - target_cpu: &str, ) { let _timer = sess.timer("link_binary"); let output_metadata = sess.opts.output_types.contains_key(&OutputType::Metadata); @@ -100,7 +99,6 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>( &out_filename, codegen_results, path.as_ref(), - target_cpu, ); } } @@ -531,7 +529,6 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>( out_filename: &Path, codegen_results: &CodegenResults, tmpdir: &Path, - target_cpu: &str, ) { info!("preparing {:?} to {:?}", crate_type, out_filename); let (linker_path, flavor) = linker_and_flavor(sess); @@ -543,7 +540,6 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>( tmpdir, out_filename, codegen_results, - target_cpu, ); linker::disable_localization(&mut cmd); @@ -1617,14 +1613,13 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>( tmpdir: &Path, out_filename: &Path, codegen_results: &CodegenResults, - target_cpu: &str, ) -> Command { let crt_objects_fallback = crt_objects_fallback(sess, crate_type); let base_cmd = get_linker(sess, path, flavor, crt_objects_fallback); // FIXME: Move `/LIBPATH` addition for uwp targets from the linker construction // to the linker args construction. assert!(base_cmd.get_args().is_empty() || sess.target.vendor == "uwp"); - let cmd = &mut *codegen_results.linker_info.to_linker(base_cmd, &sess, flavor, target_cpu); + let cmd = &mut *codegen_results.linker_info.to_linker(base_cmd, &sess, flavor); let link_output_kind = link_output_kind(sess, crate_type); // NO-OPT-OUT, OBJECT-FILES-MAYBE, CUSTOMIZATION-POINT diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index e19274e579b..4d16ae3b012 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -37,12 +37,14 @@ pub fn disable_localization(linker: &mut Command) { /// need out of the shared crate context before we get rid of it. #[derive(Encodable, Decodable)] pub struct LinkerInfo { + target_cpu: String, exports: FxHashMap<CrateType, Vec<String>>, } impl LinkerInfo { - pub fn new(tcx: TyCtxt<'_>) -> LinkerInfo { + pub fn new(tcx: TyCtxt<'_>, target_cpu: String) -> LinkerInfo { LinkerInfo { + target_cpu, exports: tcx .sess .crate_types() @@ -57,38 +59,31 @@ impl LinkerInfo { cmd: Command, sess: &'a Session, flavor: LinkerFlavor, - target_cpu: &'a str, ) -> Box<dyn Linker + 'a> { match flavor { LinkerFlavor::Lld(LldFlavor::Link) | LinkerFlavor::Msvc => { Box::new(MsvcLinker { cmd, sess, info: self }) as Box<dyn Linker> } LinkerFlavor::Em => Box::new(EmLinker { cmd, sess, info: self }) as Box<dyn Linker>, - LinkerFlavor::Gcc => Box::new(GccLinker { - cmd, - sess, - info: self, - hinted_static: false, - is_ld: false, - target_cpu, - }) as Box<dyn Linker>, + LinkerFlavor::Gcc => { + Box::new(GccLinker { cmd, sess, info: self, hinted_static: false, is_ld: false }) + as Box<dyn Linker> + } LinkerFlavor::Lld(LldFlavor::Ld) | LinkerFlavor::Lld(LldFlavor::Ld64) - | LinkerFlavor::Ld => Box::new(GccLinker { - cmd, - sess, - info: self, - hinted_static: false, - is_ld: true, - target_cpu, - }) as Box<dyn Linker>, + | LinkerFlavor::Ld => { + Box::new(GccLinker { cmd, sess, info: self, hinted_static: false, is_ld: true }) + as Box<dyn Linker> + } LinkerFlavor::Lld(LldFlavor::Wasm) => { Box::new(WasmLd::new(cmd, sess, self)) as Box<dyn Linker> } - LinkerFlavor::PtxLinker => Box::new(PtxLinker { cmd, sess }) as Box<dyn Linker>, + LinkerFlavor::PtxLinker => { + Box::new(PtxLinker { cmd, sess, info: self }) as Box<dyn Linker> + } } } } @@ -156,7 +151,6 @@ pub struct GccLinker<'a> { hinted_static: bool, // Keeps track of the current hinting mode. // Link as ld is_ld: bool, - target_cpu: &'a str, } impl<'a> GccLinker<'a> { @@ -228,8 +222,7 @@ impl<'a> GccLinker<'a> { }; self.linker_arg(&format!("-plugin-opt={}", opt_level)); - let target_cpu = self.target_cpu; - self.linker_arg(&format!("-plugin-opt=mcpu={}", target_cpu)); + self.linker_arg(&format!("-plugin-opt=mcpu={}", self.info.target_cpu)); } fn build_dylib(&mut self, out_filename: &Path) { @@ -1276,6 +1269,7 @@ fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<String> { pub struct PtxLinker<'a> { cmd: Command, sess: &'a Session, + info: &'a LinkerInfo, } impl<'a> Linker for PtxLinker<'a> { @@ -1321,10 +1315,7 @@ impl<'a> Linker for PtxLinker<'a> { fn finalize(&mut self) { // Provide the linker with fallback to internal `target-cpu`. - self.cmd.arg("--fallback-arch").arg(match self.sess.opts.cg.target_cpu { - Some(ref s) => s, - None => &self.sess.target.cpu, - }); + self.cmd.arg("--fallback-arch").arg(&self.info.target_cpu); } fn link_dylib(&mut self, _lib: Symbol) { diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index 7a8d8fb1304..cc9c6c2c2d6 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -426,6 +426,7 @@ fn need_pre_lto_bitcode_for_incr_comp(sess: &Session) -> bool { pub fn start_async_codegen<B: ExtraBackendMethods>( backend: B, tcx: TyCtxt<'_>, + target_cpu: String, metadata: EncodedMetadata, total_cgus: usize, ) -> OngoingCodegen<B> { @@ -448,7 +449,7 @@ pub fn start_async_codegen<B: ExtraBackendMethods>( subsystem.to_string() }); - let linker_info = LinkerInfo::new(tcx); + let linker_info = LinkerInfo::new(tcx, target_cpu); let crate_info = CrateInfo::new(tcx); let regular_config = |
