Skip to content

Commit 0da85d6

Browse files
committed
rustc_metadata: don't let LLVM confuse rmeta blobs for COFF object files.
1 parent 9e34664 commit 0da85d6

File tree

3 files changed

+7
-9
lines changed
  • src
    • librustc_codegen_ssa
    • librustc_metadata/rmeta
    • test/run-make-fulldeps/invalid-library

3 files changed

+7
-9
lines changed

src/librustc_codegen_ssa/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ pub struct ModuleCodegen<M> {
5959
pub kind: ModuleKind,
6060
}
6161

62-
pub const METADATA_FILENAME: &str = "rust.metadata.bin";
62+
// FIXME(eddyb) maybe include the crate name in this?
63+
pub const METADATA_FILENAME: &str = "lib.rmeta";
6364
pub const RLIB_BYTECODE_EXTENSION: &str = "bc.z";
6465

6566

src/librustc_metadata/rmeta/mod.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,15 @@ crate fn rustc_version() -> String {
3737
/// Metadata encoding version.
3838
/// N.B., increment this if you change the format of metadata such that
3939
/// the rustc version can't be found to compare with `rustc_version()`.
40-
const METADATA_VERSION: u8 = 4;
40+
const METADATA_VERSION: u8 = 5;
4141

4242
/// Metadata header which includes `METADATA_VERSION`.
43-
/// To get older versions of rustc to ignore this metadata,
44-
/// there are 4 zero bytes at the start, which are treated
45-
/// as a length of 0 by old compilers.
4643
///
4744
/// This header is followed by the position of the `CrateRoot`,
4845
/// which is encoded as a 32-bit big-endian unsigned integer,
4946
/// and further followed by the rustc version string.
50-
crate const METADATA_HEADER: &[u8; 12] =
51-
&[0, 0, 0, 0, b'r', b'u', b's', b't', 0, 0, 0, METADATA_VERSION];
47+
crate const METADATA_HEADER: &[u8; 8] =
48+
&[b'r', b'u', b's', b't', 0, 0, 0, METADATA_VERSION];
5249

5350
/// Additional metadata for a `Lazy<T>` where `T` may not be `Sized`,
5451
/// e.g. for `Lazy<[T]>`, this is the length (count of `T` values).
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-include ../tools.mk
22

33
all:
4-
touch $(TMPDIR)/rust.metadata.bin
5-
$(AR) crus $(TMPDIR)/libfoo-ffffffff-1.0.rlib $(TMPDIR)/rust.metadata.bin
4+
touch $(TMPDIR)/lib.rmeta
5+
$(AR) crus $(TMPDIR)/libfoo-ffffffff-1.0.rlib $(TMPDIR)/lib.rmeta
66
$(RUSTC) foo.rs 2>&1 | $(CGREP) "can't find crate for"

0 commit comments

Comments
 (0)