GlobalKind,
};
use rustc_middle::dep_graph;
-use rustc_middle::middle::exported_symbols;
use rustc_middle::ty::TyCtxt;
use rustc_middle::mir::mono::Linkage;
use rustc_codegen_ssa::{ModuleCodegen, ModuleKind};
use rustc_codegen_ssa::base::maybe_create_entry_wrapper;
use rustc_codegen_ssa::mono_item::MonoItemExt;
use rustc_codegen_ssa::traits::DebugInfoMethods;
-use rustc_metadata::EncodedMetadata;
use rustc_session::config::DebugInfo;
use rustc_span::Symbol;
(module, cost)
}
-
-pub fn write_compressed_metadata<'tcx>(tcx: TyCtxt<'tcx>, metadata: &EncodedMetadata, gcc_module: &mut GccContext) {
- use snap::write::FrameEncoder;
- use std::io::Write;
-
- // Historical note:
- //
- // When using link.exe it was seen that the section name `.note.rustc`
- // was getting shortened to `.note.ru`, and according to the PE and COFF
- // specification:
- //
- // > Executable images do not use a string table and do not support
- // > section names longer than 8 characters
- //
- // https://docs.microsoft.com/en-us/windows/win32/debug/pe-format
- //
- // As a result, we choose a slightly shorter name! As to why
- // `.note.rustc` works on MinGW, see
- // https://github.com/llvm/llvm-project/blob/llvmorg-12.0.0/lld/COFF/Writer.cpp#L1190-L1197
- let section_name = if tcx.sess.target.is_like_osx { "__DATA,.rustc" } else { ".rustc" };
-
- let context = &gcc_module.context;
- let mut compressed = rustc_metadata::METADATA_HEADER.to_vec();
- FrameEncoder::new(&mut compressed).write_all(&metadata.raw_data()).unwrap();
-
- let name = exported_symbols::metadata_symbol_name(tcx);
- let typ = context.new_array_type(None, context.new_type::<u8>(), compressed.len() as i32);
- let global = context.new_global(None, GlobalKind::Exported, typ, name);
- global.global_set_initializer(&compressed);
- global.set_link_section(section_name);
-
- // Also generate a .section directive to force no
- // flags, at least for ELF outputs, so that the
- // metadata doesn't get loaded into memory.
- let directive = format!(".section {}", section_name);
- context.add_top_level_asm(None, &directive);
-}
extern crate rustc_span;
extern crate rustc_symbol_mangling;
extern crate rustc_target;
-extern crate snap;
// This prevents duplicating functions and statics that are already part of the host rustc process.
#[allow(unused_extern_crates)]
}
}
- fn write_compressed_metadata<'tcx>(&self, tcx: TyCtxt<'tcx>, metadata: &EncodedMetadata, gcc_module: &mut Self::Module) {
- base::write_compressed_metadata(tcx, metadata, gcc_module)
- }
-
fn codegen_allocator<'tcx>(&self, tcx: TyCtxt<'tcx>, mods: &mut Self::Module, module_name: &str, kind: AllocatorKind, has_alloc_error_handler: bool) {
unsafe { allocator::codegen(tcx, mods, module_name, kind, has_alloc_error_handler) }
}