Sync from rust a5560a6a90
This commit is contained in:
commit
8a2520c1dc
@ -13,7 +13,7 @@ pub(crate) fn codegen(
|
||||
module: &mut impl Module,
|
||||
unwind_context: &mut UnwindContext,
|
||||
) -> bool {
|
||||
let any_dynamic_crate = tcx.dependency_formats(LOCAL_CRATE).iter().any(|(_, list)| {
|
||||
let any_dynamic_crate = tcx.dependency_formats(()).iter().any(|(_, list)| {
|
||||
use rustc_middle::middle::dependency_format::Linkage;
|
||||
list.iter().any(|&linkage| linkage == Linkage::Dynamic)
|
||||
});
|
||||
|
@ -334,7 +334,9 @@ pub(crate) fn get_caller_location(&mut self, span: Span) -> CValue<'tcx> {
|
||||
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
|
||||
let caller = self.tcx.sess.source_map().lookup_char_pos(topmost.lo());
|
||||
let const_loc = self.tcx.const_caller_location((
|
||||
rustc_span::symbol::Symbol::intern(&caller.file.name.to_string()),
|
||||
rustc_span::symbol::Symbol::intern(
|
||||
&caller.file.name.prefer_remapped().to_string_lossy(),
|
||||
),
|
||||
caller.line as u32,
|
||||
caller.col_display as u32 + 1,
|
||||
));
|
||||
|
@ -66,7 +66,7 @@ fn line_program_add_file(
|
||||
) -> FileId {
|
||||
match &file.name {
|
||||
FileName::Real(path) => {
|
||||
let (dir_path, file_name) = split_path_dir_and_file(path.stable_name());
|
||||
let (dir_path, file_name) = split_path_dir_and_file(path.remapped_path_if_available());
|
||||
let dir_name = osstr_as_utf8_bytes(dir_path.as_os_str());
|
||||
let file_name = osstr_as_utf8_bytes(file_name);
|
||||
|
||||
@ -87,7 +87,7 @@ fn line_program_add_file(
|
||||
filename => {
|
||||
let dir_id = line_program.default_directory();
|
||||
let dummy_file_name = LineString::new(
|
||||
filename.to_string().into_bytes(),
|
||||
filename.prefer_remapped().to_string().into_bytes(),
|
||||
line_program.encoding(),
|
||||
line_strings,
|
||||
);
|
||||
|
@ -64,7 +64,7 @@ pub(crate) fn new(tcx: TyCtxt<'tcx>, isa: &dyn TargetIsa) -> Self {
|
||||
// FIXME: how to get version when building out of tree?
|
||||
// Normally this would use option_env!("CFG_VERSION").
|
||||
let producer = format!("cg_clif (rustc {})", "unknown version");
|
||||
let comp_dir = tcx.sess.working_dir.0.to_string_lossy().into_owned();
|
||||
let comp_dir = tcx.sess.working_dir.to_string_lossy(false).into_owned();
|
||||
let (name, file_info) = match tcx.sess.local_crate_source_file.clone() {
|
||||
Some(path) => {
|
||||
let name = path.to_string_lossy().into_owned();
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
|
||||
use rustc_codegen_ssa::back::linker::LinkerInfo;
|
||||
use rustc_codegen_ssa::{CodegenResults, CompiledModule, CrateInfo, ModuleKind};
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
@ -41,7 +42,7 @@ fn emit_module(
|
||||
|
||||
unwind_context.emit(&mut product);
|
||||
|
||||
let tmp_file = tcx.output_filenames(LOCAL_CRATE).temp_path(OutputType::Object, Some(&name));
|
||||
let tmp_file = tcx.output_filenames(()).temp_path(OutputType::Object, Some(&name));
|
||||
let obj = product.object.write().unwrap();
|
||||
if let Err(err) = std::fs::write(&tmp_file, obj) {
|
||||
tcx.sess.fatal(&format!("error writing object file: {}", err));
|
||||
@ -73,7 +74,7 @@ fn reuse_workproduct_for_cgu(
|
||||
let work_product = cgu.work_product(tcx);
|
||||
if let Some(saved_file) = &work_product.saved_file {
|
||||
let obj_out = tcx
|
||||
.output_filenames(LOCAL_CRATE)
|
||||
.output_filenames(())
|
||||
.temp_path(OutputType::Object, Some(&cgu.name().as_str()));
|
||||
object = Some(obj_out.clone());
|
||||
let source_file = rustc_incremental::in_incr_comp_dir(&incr_comp_session_dir, &saved_file);
|
||||
@ -125,9 +126,19 @@ fn module_codegen(
|
||||
MonoItem::Static(def_id) => crate::constant::codegen_static(tcx, &mut module, def_id),
|
||||
MonoItem::GlobalAsm(item_id) => {
|
||||
let item = cx.tcx.hir().item(item_id);
|
||||
if let rustc_hir::ItemKind::GlobalAsm(rustc_hir::GlobalAsm { asm }) = item.kind {
|
||||
cx.global_asm.push_str(&*asm.as_str());
|
||||
cx.global_asm.push_str("\n\n");
|
||||
if let rustc_hir::ItemKind::GlobalAsm(asm) = item.kind {
|
||||
if !asm.options.contains(InlineAsmOptions::ATT_SYNTAX) {
|
||||
cx.global_asm.push_str("\n.intel_syntax noprefix\n");
|
||||
} else {
|
||||
cx.global_asm.push_str("\n.att_syntax\n");
|
||||
}
|
||||
for piece in asm.template {
|
||||
match *piece {
|
||||
InlineAsmTemplatePiece::String(ref s) => cx.global_asm.push_str(s),
|
||||
InlineAsmTemplatePiece::Placeholder { .. } => todo!(),
|
||||
}
|
||||
}
|
||||
cx.global_asm.push_str("\n.att_syntax\n\n");
|
||||
} else {
|
||||
bug!("Expected GlobalAsm found {:?}", item);
|
||||
}
|
||||
@ -185,7 +196,7 @@ pub(crate) fn run_aot(
|
||||
let mut work_products = FxHashMap::default();
|
||||
|
||||
let cgus = if tcx.sess.opts.output_types.should_codegen() {
|
||||
tcx.collect_and_partition_mono_items(LOCAL_CRATE).1
|
||||
tcx.collect_and_partition_mono_items(()).1
|
||||
} else {
|
||||
// If only `--emit metadata` is used, we shouldn't perform any codegen.
|
||||
// Also `tcx.collect_and_partition_mono_items` may panic in that case.
|
||||
@ -271,7 +282,7 @@ pub(crate) fn run_aot(
|
||||
.to_string();
|
||||
|
||||
let tmp_file = tcx
|
||||
.output_filenames(LOCAL_CRATE)
|
||||
.output_filenames(())
|
||||
.temp_path(OutputType::Metadata, Some(&metadata_cgu_name));
|
||||
|
||||
let obj = crate::backend::with_object(tcx.sess, &metadata_cgu_name, |object| {
|
||||
@ -304,7 +315,7 @@ pub(crate) fn run_aot(
|
||||
metadata_module,
|
||||
metadata,
|
||||
windows_subsystem,
|
||||
linker_info: LinkerInfo::new(tcx),
|
||||
linker_info: LinkerInfo::new(tcx, crate::target_triple(tcx.sess).to_string()),
|
||||
crate_info: CrateInfo::new(tcx),
|
||||
},
|
||||
work_products,
|
||||
@ -348,7 +359,7 @@ fn codegen_global_asm(tcx: TyCtxt<'_>, cgu_name: &str, global_asm: &str) {
|
||||
.join("\n");
|
||||
|
||||
let output_object_file =
|
||||
tcx.output_filenames(LOCAL_CRATE).temp_path(OutputType::Object, Some(cgu_name));
|
||||
tcx.output_filenames(()).temp_path(OutputType::Object, Some(cgu_name));
|
||||
|
||||
// Assemble `global_asm`
|
||||
let global_asm_object_file = add_file_stem_postfix(output_object_file.clone(), ".asm");
|
||||
|
@ -66,7 +66,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
|
||||
matches!(backend_config.codegen_mode, CodegenMode::JitLazy),
|
||||
);
|
||||
|
||||
let (_, cgus) = tcx.collect_and_partition_mono_items(LOCAL_CRATE);
|
||||
let (_, cgus) = tcx.collect_and_partition_mono_items(());
|
||||
let mono_items = cgus
|
||||
.iter()
|
||||
.map(|cgu| cgu.items_in_deterministic_order(tcx).into_iter())
|
||||
@ -179,7 +179,7 @@ fn load_imported_symbols_for_jit(tcx: TyCtxt<'_>) -> Vec<(String, *const u8)> {
|
||||
let mut dylib_paths = Vec::new();
|
||||
|
||||
let crate_info = CrateInfo::new(tcx);
|
||||
let formats = tcx.dependency_formats(LOCAL_CRATE);
|
||||
let formats = tcx.dependency_formats(());
|
||||
let data = &formats
|
||||
.iter()
|
||||
.find(|(crate_type, _data)| *crate_type == rustc_session::config::CrateType::Executable)
|
||||
|
@ -165,7 +165,7 @@ fn init(&self, sess: &Session) {
|
||||
}
|
||||
|
||||
fn metadata_loader(&self) -> Box<dyn MetadataLoader + Sync> {
|
||||
Box::new(crate::metadata::CraneliftMetadataLoader)
|
||||
Box::new(rustc_codegen_ssa::back::metadata::DefaultMetadataLoader)
|
||||
}
|
||||
|
||||
fn provide(&self, _providers: &mut Providers) {}
|
||||
@ -218,13 +218,11 @@ fn link(
|
||||
) -> Result<(), ErrorReported> {
|
||||
use rustc_codegen_ssa::back::link::link_binary;
|
||||
|
||||
let target_cpu = crate::target_triple(sess).to_string();
|
||||
link_binary::<crate::archive::ArArchiveBuilder<'_>>(
|
||||
sess,
|
||||
&codegen_results,
|
||||
outputs,
|
||||
&codegen_results.crate_name.as_str(),
|
||||
&target_cpu,
|
||||
);
|
||||
|
||||
Ok(())
|
||||
|
@ -16,7 +16,7 @@ pub(crate) fn maybe_create_entry_wrapper(
|
||||
is_jit: bool,
|
||||
is_primary_cgu: bool,
|
||||
) {
|
||||
let (main_def_id, is_main_fn) = match tcx.entry_fn(LOCAL_CRATE) {
|
||||
let (main_def_id, is_main_fn) = match tcx.entry_fn(()) {
|
||||
Some((def_id, entry_ty)) => (
|
||||
def_id,
|
||||
match entry_ty {
|
||||
|
@ -1,73 +1,9 @@
|
||||
//! Reading and writing of the rustc metadata for rlibs and dylibs
|
||||
//! Writing of the rustc metadata for dylibs
|
||||
|
||||
use std::fs::File;
|
||||
use std::path::Path;
|
||||
|
||||
use rustc_codegen_ssa::METADATA_FILENAME;
|
||||
use rustc_data_structures::memmap::Mmap;
|
||||
use rustc_data_structures::owning_ref::OwningRef;
|
||||
use rustc_data_structures::rustc_erase_owner;
|
||||
use rustc_data_structures::sync::MetadataRef;
|
||||
use rustc_middle::middle::cstore::MetadataLoader;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_target::spec::Target;
|
||||
|
||||
use crate::backend::WriteMetadata;
|
||||
|
||||
/// The metadata loader used by cg_clif.
|
||||
///
|
||||
/// The metadata is stored in the same format as cg_llvm.
|
||||
///
|
||||
/// # Metadata location
|
||||
///
|
||||
/// <dl>
|
||||
/// <dt>rlib</dt>
|
||||
/// <dd>The metadata can be found in the `lib.rmeta` file inside of the ar archive.</dd>
|
||||
/// <dt>dylib</dt>
|
||||
/// <dd>The metadata can be found in the `.rustc` section of the shared library.</dd>
|
||||
/// </dl>
|
||||
pub(crate) struct CraneliftMetadataLoader;
|
||||
|
||||
fn load_metadata_with(
|
||||
path: &Path,
|
||||
f: impl for<'a> FnOnce(&'a [u8]) -> Result<&'a [u8], String>,
|
||||
) -> Result<MetadataRef, String> {
|
||||
let file = File::open(path).map_err(|e| format!("{:?}", e))?;
|
||||
let data = unsafe { Mmap::map(file) }.map_err(|e| format!("{:?}", e))?;
|
||||
let metadata = OwningRef::new(data).try_map(f)?;
|
||||
return Ok(rustc_erase_owner!(metadata.map_owner_box()));
|
||||
}
|
||||
|
||||
impl MetadataLoader for CraneliftMetadataLoader {
|
||||
fn get_rlib_metadata(&self, _target: &Target, path: &Path) -> Result<MetadataRef, String> {
|
||||
load_metadata_with(path, |data| {
|
||||
let archive = object::read::archive::ArchiveFile::parse(&*data)
|
||||
.map_err(|e| format!("{:?}", e))?;
|
||||
|
||||
for entry_result in archive.members() {
|
||||
let entry = entry_result.map_err(|e| format!("{:?}", e))?;
|
||||
if entry.name() == METADATA_FILENAME.as_bytes() {
|
||||
return Ok(entry.data());
|
||||
}
|
||||
}
|
||||
|
||||
Err("couldn't find metadata entry".to_string())
|
||||
})
|
||||
}
|
||||
|
||||
fn get_dylib_metadata(&self, _target: &Target, path: &Path) -> Result<MetadataRef, String> {
|
||||
use object::{Object, ObjectSection};
|
||||
|
||||
load_metadata_with(path, |data| {
|
||||
let file = object::File::parse(&data).map_err(|e| format!("parse: {:?}", e))?;
|
||||
file.section_by_name(".rustc")
|
||||
.ok_or("no .rustc section")?
|
||||
.data()
|
||||
.map_err(|e| format!("failed to read .rustc section: {:?}", e))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Adapted from https://github.com/rust-lang/rust/blob/da573206f87b5510de4b0ee1a9c044127e409bd3/src/librustc_codegen_llvm/base.rs#L47-L112
|
||||
pub(crate) fn write_metadata<O: WriteMetadata>(tcx: TyCtxt<'_>, object: &mut O) {
|
||||
use snap::write::FrameEncoder;
|
||||
|
@ -214,7 +214,7 @@ pub(crate) fn write_ir_file(
|
||||
return;
|
||||
}
|
||||
|
||||
let clif_output_dir = tcx.output_filenames(LOCAL_CRATE).with_extension("clif");
|
||||
let clif_output_dir = tcx.output_filenames(()).with_extension("clif");
|
||||
|
||||
match std::fs::create_dir(&clif_output_dir) {
|
||||
Ok(()) => {}
|
||||
|
Loading…
Reference in New Issue
Block a user