-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[experiment] Add -Z no-link
flag
#67195
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ use rustc_codegen_ssa::CompiledModule; | |
use rustc_errors::{FatalError, Handler}; | ||
use std::any::Any; | ||
use std::ffi::CStr; | ||
use std::fs; | ||
use std::sync::Arc; | ||
use syntax::expand::allocator::AllocatorKind; | ||
|
||
|
@@ -44,6 +45,7 @@ use rustc::ty::{self, TyCtxt}; | |
use rustc::util::common::ErrorReported; | ||
use rustc_codegen_ssa::ModuleCodegen; | ||
use rustc_codegen_utils::codegen_backend::CodegenBackend; | ||
use rustc_serialize::json; | ||
|
||
mod back { | ||
pub mod archive; | ||
|
@@ -298,6 +300,18 @@ impl CodegenBackend for LlvmCodegenBackend { | |
return Ok(()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it have been called for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current condition says return if neither exe, nor metadata is emitted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just realized that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good suggestion. In fact, I think it is a good refactoring even without this |
||
} | ||
|
||
if sess.opts.debugging_opts.no_link { | ||
// FIXME: use a binary format to encode the `.rlink` file | ||
let rlink_data = json::encode(&codegen_results).map_err(|err| { | ||
sess.fatal(&format!("failed to encode rlink: {}", err)); | ||
})?; | ||
let rlink_file = outputs.with_extension("rlink"); | ||
fs::write(&rlink_file, rlink_data).map_err(|err| { | ||
sess.fatal(&format!("failed to write file {}: {}", rlink_file.display(), err)); | ||
})?; | ||
return Ok(()); | ||
} | ||
|
||
// Run the linker on any artifacts that resulted from the LLVM run. | ||
// This should produce either a finished executable or library. | ||
sess.time("link_crate", || { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
use rustc_data_structures::AtomicRef; | ||
use rustc_index::vec::Idx; | ||
use rustc_serialize::{Decoder, Encoder}; | ||
use std::fmt; | ||
use std::u32; | ||
use std::{u32, u64}; | ||
|
||
rustc_index::newtype_index! { | ||
pub struct CrateId { | ||
|
@@ -86,8 +87,18 @@ impl fmt::Display for CrateNum { | |
} | ||
} | ||
|
||
impl rustc_serialize::UseSpecializedEncodable for CrateNum {} | ||
impl rustc_serialize::UseSpecializedDecodable for CrateNum {} | ||
/// As a local identifier, a `CrateNum` is only meaningful within its context, e.g. within a tcx. | ||
/// Therefore, make sure to include the context when encode a `CrateNum`. | ||
impl rustc_serialize::UseSpecializedEncodable for CrateNum { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we decided to stick with this approach (#67516 (comment)), we may want to add a comment (here or on |
||
fn default_encode<E: Encoder>(&self, e: &mut E) -> Result<(), E::Error> { | ||
e.emit_u32(self.as_u32()) | ||
} | ||
} | ||
impl rustc_serialize::UseSpecializedDecodable for CrateNum { | ||
fn default_decode<D: Decoder>(d: &mut D) -> Result<CrateNum, D::Error> { | ||
Ok(CrateNum::from_u32(d.read_u32()?)) | ||
} | ||
} | ||
|
||
rustc_index::newtype_index! { | ||
/// A DefIndex is an index into the hir-map for a crate, identifying a | ||
|
@@ -135,8 +146,21 @@ impl DefId { | |
} | ||
} | ||
|
||
impl rustc_serialize::UseSpecializedEncodable for DefId {} | ||
impl rustc_serialize::UseSpecializedDecodable for DefId {} | ||
impl rustc_serialize::UseSpecializedEncodable for DefId { | ||
fn default_encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> { | ||
let krate = u64::from(self.krate.as_u32()); | ||
let index = u64::from(self.index.as_u32()); | ||
s.emit_u64((krate << 32) | index) | ||
} | ||
} | ||
impl rustc_serialize::UseSpecializedDecodable for DefId { | ||
fn default_decode<D: Decoder>(d: &mut D) -> Result<DefId, D::Error> { | ||
let def_id = d.read_u64()?; | ||
let krate = CrateNum::from_u32((def_id >> 32) as u32); | ||
let index = DefIndex::from_u32((def_id & 0xffffffff) as u32); | ||
Ok(DefId { krate, index }) | ||
} | ||
} | ||
|
||
pub fn default_def_id_debug(def_id: DefId, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
f.debug_struct("DefId").field("krate", &def_id.krate).field("index", &def_id.index).finish() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to save this in a binary file rather than escaped binary in a json string.
That said, I'm okay with doing this later, especially since this is an experimental feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally agreed, a binary file is definitely the proper way. I chose JSON in this PR purely because I don't want the file format details hold the feature, especially the proposed approach has not been reviewed yet.