Skip to content

Commit 9a9fe17

Browse files
authored
Rollup merge of #39619 - michaelwoerister:rename-crate-metadata, r=alexcrichton
Choose different name for metadata obj-file to avoid clashes with user-chosen names. Fixes #39585 and probably #39508. Incremental compilation assigns different names to obj-files than regular compilation. If a crate is called "metadata" this can lead to a clash between the root module's obj-file and the obj-file containing crate-metadata. This PR assigns a name to the metadata obj-file that cannot clash with other obj-file because it contains a `.` which is not allowed in a Rust module identifier. r? @alexcrichton cc @nikomatsakis
2 parents 530aee8 + e5396e0 commit 9a9fe17

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

src/librustc_trans/back/link.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ use syntax::attr;
4848
use syntax::symbol::Symbol;
4949
use syntax_pos::Span;
5050

51+
/// The LLVM module name containing crate-metadata. This includes a `.` on
52+
/// purpose, so it cannot clash with the name of a user-defined module.
53+
pub const METADATA_MODULE_NAME: &'static str = "crate.metadata";
54+
/// The name of the crate-metadata object file the compiler generates. Must
55+
/// match up with `METADATA_MODULE_NAME`.
56+
pub const METADATA_OBJ_NAME: &'static str = "crate.metadata.o";
57+
5158
// RLIB LLVM-BYTECODE OBJECT LAYOUT
5259
// Version 1
5360
// Bytes Data
@@ -213,7 +220,7 @@ pub fn link_binary(sess: &Session,
213220
remove(sess, &obj);
214221
}
215222
}
216-
remove(sess, &outputs.with_extension("metadata.o"));
223+
remove(sess, &outputs.with_extension(METADATA_OBJ_NAME));
217224
}
218225

219226
out_filenames
@@ -833,7 +840,7 @@ fn link_args(cmd: &mut Linker,
833840
// object file, so we link that in here.
834841
if crate_type == config::CrateTypeDylib ||
835842
crate_type == config::CrateTypeProcMacro {
836-
cmd.add_object(&outputs.with_extension("metadata.o"));
843+
cmd.add_object(&outputs.with_extension(METADATA_OBJ_NAME));
837844
}
838845

839846
// Try to strip as much out of the generated object by removing unused

src/librustc_trans/back/write.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -870,12 +870,12 @@ pub fn run_passes(sess: &Session,
870870
// Clean up unwanted temporary files.
871871

872872
// We create the following files by default:
873-
// - crate.#module-name#.bc
874-
// - crate.#module-name#.o
875-
// - crate.metadata.bc
876-
// - crate.metadata.o
877-
// - crate.o (linked from crate.##.o)
878-
// - crate.bc (copied from crate.##.bc)
873+
// - #crate#.#module-name#.bc
874+
// - #crate#.#module-name#.o
875+
// - #crate#.crate.metadata.bc
876+
// - #crate#.crate.metadata.o
877+
// - #crate#.o (linked from crate.##.o)
878+
// - #crate#.bc (copied from crate.##.bc)
879879
// We may create additional files if requested by the user (through
880880
// `-C save-temps` or `--emit=` flags).
881881

@@ -923,9 +923,9 @@ pub fn run_passes(sess: &Session,
923923
}
924924

925925
// We leave the following files around by default:
926-
// - crate.o
927-
// - crate.metadata.o
928-
// - crate.bc
926+
// - #crate#.o
927+
// - #crate#.crate.metadata.o
928+
// - #crate#.bc
929929
// These are used in linking steps and will be cleaned up afterward.
930930

931931
// FIXME: time_llvm_passes support - does this use a global context or

src/librustc_trans/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11461146
});
11471147

11481148
let metadata_module = ModuleTranslation {
1149-
name: "metadata".to_string(),
1149+
name: link::METADATA_MODULE_NAME.to_string(),
11501150
symbol_name_hash: 0, // we always rebuild metadata, at least for now
11511151
source: ModuleSource::Translated(ModuleLlvm {
11521152
llcx: shared_ccx.metadata_llcx(),

0 commit comments

Comments
 (0)