Skip to content

Commit 0fec5ab

Browse files
authored
Rollup merge of #66235 - eddyb:coff-syrup, r=nagisa
rustc_metadata: don't let LLVM confuse rmeta blobs for COFF object files. This has likely been a silent issue since 1.10 but only caused trouble recently (see #65536 (comment)), when recent changes to the `rmeta` schema introduced more opportunities for COFF parse errors. To prevent any undesired interactions with old compilers, I've renamed the file inside `rlib`s from `rust.metadata.bin` to `lib.rmeta` (not strongly attached to it, suggestions welcome). Fixes #65536. <hr/> Before: ``` $ llvm-objdump -all-headers build/*/stage1-std/*/release/deps/libcore-*.rmeta build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libcore-6b9e8b5a59b79a1d.rmeta: file format COFF-<unknown arch> architecture: unknown start address: 0x00000000 Sections: Idx Name Size VMA Type SYMBOL TABLE: ``` After: ``` $ llvm-objdump -all-headers build/*/stage1-std/*/release/deps/libcore-*.rmeta llvm-objdump: error: 'build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libcore-6b9e8b5a59b79a1d.rmeta': The file was not recognized as a valid object file ```
2 parents 9db3fdd + 0da85d6 commit 0fec5ab

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)