Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc_metadata: don't let LLVM confuse rmeta blobs for COFF object files. #66235

Merged
merged 1 commit into from
Nov 10, 2019

Conversation

eddyb
Copy link
Member

@eddyb eddyb commented Nov 9, 2019

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 rlibs from rust.metadata.bin to lib.rmeta (not strongly attached to it, suggestions welcome).

Fixes #65536.


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

@rust-highfive
Copy link
Collaborator

r? @varkor

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 9, 2019
@eddyb
Copy link
Member Author

eddyb commented Nov 9, 2019

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Nov 9, 2019

⌛ Trying commit 0da85d6 with merge b3b0b7a...

bors added a commit that referenced this pull request Nov 9, 2019
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
```
@nagisa
Copy link
Member

nagisa commented Nov 9, 2019

r=me

@nagisa nagisa assigned nagisa and unassigned varkor Nov 9, 2019
@bors
Copy link
Contributor

bors commented Nov 9, 2019

☀️ Try build successful - checks-azure
Build commit: b3b0b7a (b3b0b7a03e614c2d2dd1f5cfff4d2bae6d197360)

@rust-timer
Copy link
Collaborator

Queued b3b0b7a with parent 9e34664, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit b3b0b7a, comparison URL.

@eddyb
Copy link
Member Author

eddyb commented Nov 9, 2019

Alright, nothing too interesting going on there, I guess LLVM wasn't wasting that much time on parsing rmeta as COFF, after all.

@bors r=nagisa

@bors
Copy link
Contributor

bors commented Nov 9, 2019

📌 Commit 0da85d6 has been approved by nagisa

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 9, 2019
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Nov 10, 2019
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 rust-lang#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 rust-lang#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
```
bors added a commit that referenced this pull request Nov 10, 2019
Rollup of 7 pull requests

Successful merges:

 - #65719 (Refactor sync::Once)
 - #65831 (Don't cast directly from &[T; N] to *const T)
 - #66048 (Correct error in documentation for Ipv4Addr method)
 - #66058 (Correct deprecated `is_global` IPv6 documentation)
 - #66216 ([mir-opt] Handle return place in ConstProp and improve SimplifyLocals pass)
 - #66217 (invalid_value lint: use diagnostic items)
 - #66235 (rustc_metadata: don't let LLVM confuse rmeta blobs for COFF object files.)

Failed merges:

r? @ghost
@bors bors merged commit 0da85d6 into rust-lang:master Nov 10, 2019
@eddyb eddyb deleted the coff-syrup branch November 10, 2019 07:42
aheejin added a commit to aheejin/emscripten that referenced this pull request Oct 2, 2020
This test was added in emscripten-core#10300 to check if we can handle non-objects in
archives, especially rust metadata files that start with two leading
zeroes. LLVM's file magic identifier thinks files with two leading
zeroes are COFF files. But Rust metadata files used to start with two
leading zeroes too, resulting in an error in LLVM tools. So emscripten-core#10300
bypassed use of `llvm-nm` to avoid that.

We were still using `llvm-ranlib`, which also ran the LLVM magic
identifier when trying to create a symbol table for an object, but
`llvm-ranlib` so far has ignored those errors. But recently
llvm/llvm-project@a20168d
made them explicit errors, so we couldn't run `llvm-ranlib` anymore with
archives containing objects that start with two leading zeroes.

But this is not relevant anymore because Rust fixed their object file
format in rust-lang/rust#66235, so their files are not mistaken by LLVM
for COFF files anymore. So this PR fixes this test to not include a
binary with two leading zeros, while still testing archival of
non-object files.
aheejin added a commit to emscripten-core/emscripten that referenced this pull request Oct 2, 2020
This test was added in #10300 to check if we can handle non-objects in
archives, especially rust metadata files that start with two leading
zeroes. LLVM's file magic identifier thinks files with two leading
zeroes are COFF files. But Rust metadata files used to start with two
leading zeroes too, resulting in an error in LLVM tools. So #10300
bypassed use of `llvm-nm` to avoid that.

We were still using `llvm-ranlib`, which also ran the LLVM magic
identifier when trying to create a symbol table for an object, but
`llvm-ranlib` so far has ignored those errors. But recently
llvm/llvm-project@a20168d
made them explicit errors, so we couldn't run `llvm-ranlib` anymore with
archives containing objects that start with two leading zeroes.

But this is not relevant anymore because Rust fixed their object file
format in rust-lang/rust#66235, so their files are not mistaken by LLVM
for COFF files anymore. So this PR fixes this test to not include a
binary with two leading zeros, while still testing archival of
non-object files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

failed to build archive invalid data encountered
6 participants