Skip to content

Commit 8a2520c

Browse files
committed
Sync from rust a5560a6
2 parents beab751 + 3c53005 commit 8a2520c

File tree

10 files changed

+33
-86
lines changed

10 files changed

+33
-86
lines changed

src/allocator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub(crate) fn codegen(
1313
module: &mut impl Module,
1414
unwind_context: &mut UnwindContext,
1515
) -> bool {
16-
let any_dynamic_crate = tcx.dependency_formats(LOCAL_CRATE).iter().any(|(_, list)| {
16+
let any_dynamic_crate = tcx.dependency_formats(()).iter().any(|(_, list)| {
1717
use rustc_middle::middle::dependency_format::Linkage;
1818
list.iter().any(|&linkage| linkage == Linkage::Dynamic)
1919
});

src/common.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,9 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
334334
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
335335
let caller = self.tcx.sess.source_map().lookup_char_pos(topmost.lo());
336336
let const_loc = self.tcx.const_caller_location((
337-
rustc_span::symbol::Symbol::intern(&caller.file.name.to_string()),
337+
rustc_span::symbol::Symbol::intern(
338+
&caller.file.name.prefer_remapped().to_string_lossy(),
339+
),
338340
caller.line as u32,
339341
caller.col_display as u32 + 1,
340342
));

src/debuginfo/line_info.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn line_program_add_file(
6666
) -> FileId {
6767
match &file.name {
6868
FileName::Real(path) => {
69-
let (dir_path, file_name) = split_path_dir_and_file(path.stable_name());
69+
let (dir_path, file_name) = split_path_dir_and_file(path.remapped_path_if_available());
7070
let dir_name = osstr_as_utf8_bytes(dir_path.as_os_str());
7171
let file_name = osstr_as_utf8_bytes(file_name);
7272

@@ -87,7 +87,7 @@ fn line_program_add_file(
8787
filename => {
8888
let dir_id = line_program.default_directory();
8989
let dummy_file_name = LineString::new(
90-
filename.to_string().into_bytes(),
90+
filename.prefer_remapped().to_string().into_bytes(),
9191
line_program.encoding(),
9292
line_strings,
9393
);

src/debuginfo/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<'tcx> DebugContext<'tcx> {
6464
// FIXME: how to get version when building out of tree?
6565
// Normally this would use option_env!("CFG_VERSION").
6666
let producer = format!("cg_clif (rustc {})", "unknown version");
67-
let comp_dir = tcx.sess.working_dir.0.to_string_lossy().into_owned();
67+
let comp_dir = tcx.sess.working_dir.to_string_lossy(false).into_owned();
6868
let (name, file_info) = match tcx.sess.local_crate_source_file.clone() {
6969
Some(path) => {
7070
let name = path.to_string_lossy().into_owned();

src/driver/aot.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
use std::path::PathBuf;
55

6+
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
67
use rustc_codegen_ssa::back::linker::LinkerInfo;
78
use rustc_codegen_ssa::{CodegenResults, CompiledModule, CrateInfo, ModuleKind};
89
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -41,7 +42,7 @@ fn emit_module(
4142

4243
unwind_context.emit(&mut product);
4344

44-
let tmp_file = tcx.output_filenames(LOCAL_CRATE).temp_path(OutputType::Object, Some(&name));
45+
let tmp_file = tcx.output_filenames(()).temp_path(OutputType::Object, Some(&name));
4546
let obj = product.object.write().unwrap();
4647
if let Err(err) = std::fs::write(&tmp_file, obj) {
4748
tcx.sess.fatal(&format!("error writing object file: {}", err));
@@ -73,7 +74,7 @@ fn reuse_workproduct_for_cgu(
7374
let work_product = cgu.work_product(tcx);
7475
if let Some(saved_file) = &work_product.saved_file {
7576
let obj_out = tcx
76-
.output_filenames(LOCAL_CRATE)
77+
.output_filenames(())
7778
.temp_path(OutputType::Object, Some(&cgu.name().as_str()));
7879
object = Some(obj_out.clone());
7980
let source_file = rustc_incremental::in_incr_comp_dir(&incr_comp_session_dir, &saved_file);
@@ -125,9 +126,19 @@ fn module_codegen(
125126
MonoItem::Static(def_id) => crate::constant::codegen_static(tcx, &mut module, def_id),
126127
MonoItem::GlobalAsm(item_id) => {
127128
let item = cx.tcx.hir().item(item_id);
128-
if let rustc_hir::ItemKind::GlobalAsm(rustc_hir::GlobalAsm { asm }) = item.kind {
129-
cx.global_asm.push_str(&*asm.as_str());
130-
cx.global_asm.push_str("\n\n");
129+
if let rustc_hir::ItemKind::GlobalAsm(asm) = item.kind {
130+
if !asm.options.contains(InlineAsmOptions::ATT_SYNTAX) {
131+
cx.global_asm.push_str("\n.intel_syntax noprefix\n");
132+
} else {
133+
cx.global_asm.push_str("\n.att_syntax\n");
134+
}
135+
for piece in asm.template {
136+
match *piece {
137+
InlineAsmTemplatePiece::String(ref s) => cx.global_asm.push_str(s),
138+
InlineAsmTemplatePiece::Placeholder { .. } => todo!(),
139+
}
140+
}
141+
cx.global_asm.push_str("\n.att_syntax\n\n");
131142
} else {
132143
bug!("Expected GlobalAsm found {:?}", item);
133144
}
@@ -185,7 +196,7 @@ pub(crate) fn run_aot(
185196
let mut work_products = FxHashMap::default();
186197

187198
let cgus = if tcx.sess.opts.output_types.should_codegen() {
188-
tcx.collect_and_partition_mono_items(LOCAL_CRATE).1
199+
tcx.collect_and_partition_mono_items(()).1
189200
} else {
190201
// If only `--emit metadata` is used, we shouldn't perform any codegen.
191202
// Also `tcx.collect_and_partition_mono_items` may panic in that case.
@@ -271,7 +282,7 @@ pub(crate) fn run_aot(
271282
.to_string();
272283

273284
let tmp_file = tcx
274-
.output_filenames(LOCAL_CRATE)
285+
.output_filenames(())
275286
.temp_path(OutputType::Metadata, Some(&metadata_cgu_name));
276287

277288
let obj = crate::backend::with_object(tcx.sess, &metadata_cgu_name, |object| {
@@ -304,7 +315,7 @@ pub(crate) fn run_aot(
304315
metadata_module,
305316
metadata,
306317
windows_subsystem,
307-
linker_info: LinkerInfo::new(tcx),
318+
linker_info: LinkerInfo::new(tcx, crate::target_triple(tcx.sess).to_string()),
308319
crate_info: CrateInfo::new(tcx),
309320
},
310321
work_products,
@@ -348,7 +359,7 @@ fn codegen_global_asm(tcx: TyCtxt<'_>, cgu_name: &str, global_asm: &str) {
348359
.join("\n");
349360

350361
let output_object_file =
351-
tcx.output_filenames(LOCAL_CRATE).temp_path(OutputType::Object, Some(cgu_name));
362+
tcx.output_filenames(()).temp_path(OutputType::Object, Some(cgu_name));
352363

353364
// Assemble `global_asm`
354365
let global_asm_object_file = add_file_stem_postfix(output_object_file.clone(), ".asm");

src/driver/jit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
6666
matches!(backend_config.codegen_mode, CodegenMode::JitLazy),
6767
);
6868

69-
let (_, cgus) = tcx.collect_and_partition_mono_items(LOCAL_CRATE);
69+
let (_, cgus) = tcx.collect_and_partition_mono_items(());
7070
let mono_items = cgus
7171
.iter()
7272
.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)> {
179179
let mut dylib_paths = Vec::new();
180180

181181
let crate_info = CrateInfo::new(tcx);
182-
let formats = tcx.dependency_formats(LOCAL_CRATE);
182+
let formats = tcx.dependency_formats(());
183183
let data = &formats
184184
.iter()
185185
.find(|(crate_type, _data)| *crate_type == rustc_session::config::CrateType::Executable)

src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
165165
}
166166

167167
fn metadata_loader(&self) -> Box<dyn MetadataLoader + Sync> {
168-
Box::new(crate::metadata::CraneliftMetadataLoader)
168+
Box::new(rustc_codegen_ssa::back::metadata::DefaultMetadataLoader)
169169
}
170170

171171
fn provide(&self, _providers: &mut Providers) {}
@@ -218,13 +218,11 @@ impl CodegenBackend for CraneliftCodegenBackend {
218218
) -> Result<(), ErrorReported> {
219219
use rustc_codegen_ssa::back::link::link_binary;
220220

221-
let target_cpu = crate::target_triple(sess).to_string();
222221
link_binary::<crate::archive::ArArchiveBuilder<'_>>(
223222
sess,
224223
&codegen_results,
225224
outputs,
226225
&codegen_results.crate_name.as_str(),
227-
&target_cpu,
228226
);
229227

230228
Ok(())

src/main_shim.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub(crate) fn maybe_create_entry_wrapper(
1616
is_jit: bool,
1717
is_primary_cgu: bool,
1818
) {
19-
let (main_def_id, is_main_fn) = match tcx.entry_fn(LOCAL_CRATE) {
19+
let (main_def_id, is_main_fn) = match tcx.entry_fn(()) {
2020
Some((def_id, entry_ty)) => (
2121
def_id,
2222
match entry_ty {

src/metadata.rs

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,9 @@
1-
//! Reading and writing of the rustc metadata for rlibs and dylibs
1+
//! Writing of the rustc metadata for dylibs
22
3-
use std::fs::File;
4-
use std::path::Path;
5-
6-
use rustc_codegen_ssa::METADATA_FILENAME;
7-
use rustc_data_structures::memmap::Mmap;
8-
use rustc_data_structures::owning_ref::OwningRef;
9-
use rustc_data_structures::rustc_erase_owner;
10-
use rustc_data_structures::sync::MetadataRef;
11-
use rustc_middle::middle::cstore::MetadataLoader;
123
use rustc_middle::ty::TyCtxt;
13-
use rustc_target::spec::Target;
144

155
use crate::backend::WriteMetadata;
166

17-
/// The metadata loader used by cg_clif.
18-
///
19-
/// The metadata is stored in the same format as cg_llvm.
20-
///
21-
/// # Metadata location
22-
///
23-
/// <dl>
24-
/// <dt>rlib</dt>
25-
/// <dd>The metadata can be found in the `lib.rmeta` file inside of the ar archive.</dd>
26-
/// <dt>dylib</dt>
27-
/// <dd>The metadata can be found in the `.rustc` section of the shared library.</dd>
28-
/// </dl>
29-
pub(crate) struct CraneliftMetadataLoader;
30-
31-
fn load_metadata_with(
32-
path: &Path,
33-
f: impl for<'a> FnOnce(&'a [u8]) -> Result<&'a [u8], String>,
34-
) -> Result<MetadataRef, String> {
35-
let file = File::open(path).map_err(|e| format!("{:?}", e))?;
36-
let data = unsafe { Mmap::map(file) }.map_err(|e| format!("{:?}", e))?;
37-
let metadata = OwningRef::new(data).try_map(f)?;
38-
return Ok(rustc_erase_owner!(metadata.map_owner_box()));
39-
}
40-
41-
impl MetadataLoader for CraneliftMetadataLoader {
42-
fn get_rlib_metadata(&self, _target: &Target, path: &Path) -> Result<MetadataRef, String> {
43-
load_metadata_with(path, |data| {
44-
let archive = object::read::archive::ArchiveFile::parse(&*data)
45-
.map_err(|e| format!("{:?}", e))?;
46-
47-
for entry_result in archive.members() {
48-
let entry = entry_result.map_err(|e| format!("{:?}", e))?;
49-
if entry.name() == METADATA_FILENAME.as_bytes() {
50-
return Ok(entry.data());
51-
}
52-
}
53-
54-
Err("couldn't find metadata entry".to_string())
55-
})
56-
}
57-
58-
fn get_dylib_metadata(&self, _target: &Target, path: &Path) -> Result<MetadataRef, String> {
59-
use object::{Object, ObjectSection};
60-
61-
load_metadata_with(path, |data| {
62-
let file = object::File::parse(&data).map_err(|e| format!("parse: {:?}", e))?;
63-
file.section_by_name(".rustc")
64-
.ok_or("no .rustc section")?
65-
.data()
66-
.map_err(|e| format!("failed to read .rustc section: {:?}", e))
67-
})
68-
}
69-
}
70-
717
// Adapted from https://github.com/rust-lang/rust/blob/da573206f87b5510de4b0ee1a9c044127e409bd3/src/librustc_codegen_llvm/base.rs#L47-L112
728
pub(crate) fn write_metadata<O: WriteMetadata>(tcx: TyCtxt<'_>, object: &mut O) {
739
use snap::write::FrameEncoder;

src/pretty_clif.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ pub(crate) fn write_ir_file(
214214
return;
215215
}
216216

217-
let clif_output_dir = tcx.output_filenames(LOCAL_CRATE).with_extension("clif");
217+
let clif_output_dir = tcx.output_filenames(()).with_extension("clif");
218218

219219
match std::fs::create_dir(&clif_output_dir) {
220220
Ok(()) => {}

0 commit comments

Comments
 (0)