Skip to content

Commit 3eaca41

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 a05cc5c + e5396e0 commit 3eaca41

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
@@ -832,7 +839,7 @@ fn link_args(cmd: &mut Linker,
832839
// object file, so we link that in here.
833840
if crate_type == config::CrateTypeDylib ||
834841
crate_type == config::CrateTypeProcMacro {
835-
cmd.add_object(&outputs.with_extension("metadata.o"));
842+
cmd.add_object(&outputs.with_extension(METADATA_OBJ_NAME));
836843
}
837844

838845
// 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
@@ -886,12 +886,12 @@ pub fn run_passes(sess: &Session,
886886
// Clean up unwanted temporary files.
887887

888888
// We create the following files by default:
889-
// - crate.#module-name#.bc
890-
// - crate.#module-name#.o
891-
// - crate.metadata.bc
892-
// - crate.metadata.o
893-
// - crate.o (linked from crate.##.o)
894-
// - crate.bc (copied from crate.##.bc)
889+
// - #crate#.#module-name#.bc
890+
// - #crate#.#module-name#.o
891+
// - #crate#.crate.metadata.bc
892+
// - #crate#.crate.metadata.o
893+
// - #crate#.o (linked from crate.##.o)
894+
// - #crate#.bc (copied from crate.##.bc)
895895
// We may create additional files if requested by the user (through
896896
// `-C save-temps` or `--emit=` flags).
897897

@@ -939,9 +939,9 @@ pub fn run_passes(sess: &Session,
939939
}
940940

941941
// We leave the following files around by default:
942-
// - crate.o
943-
// - crate.metadata.o
944-
// - crate.bc
942+
// - #crate#.o
943+
// - #crate#.crate.metadata.o
944+
// - #crate#.bc
945945
// These are used in linking steps and will be cleaned up afterward.
946946

947947
// 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
@@ -1151,7 +1151,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11511151
});
11521152

11531153
let metadata_module = ModuleTranslation {
1154-
name: "metadata".to_string(),
1154+
name: link::METADATA_MODULE_NAME.to_string(),
11551155
symbol_name_hash: 0, // we always rebuild metadata, at least for now
11561156
source: ModuleSource::Translated(ModuleLlvm {
11571157
llcx: shared_ccx.metadata_llcx(),

0 commit comments

Comments
 (0)