-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-linkageArea: linking into static, shared libraries and binariesArea: linking into static, shared libraries and binariesA-metadataArea: Crate metadataArea: Crate metadataC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
Description
I tried this command:
$ echo "fn main() {}" | rustc -Zno-link -
I expected to see this happen: An .rlink
file is generated.
Instead, this happened:
thread 'rustc' panicked at 'cannot encode `DefIndex` with `rustc_serialize::json::Encoder`', /rustc/381b445ff5751f9f39ec672b623372dff09c276e/compiler/rustc_span/src/def_id.rs:135:9
stack backtrace:
0: rust_begin_unwind
at /rustc/381b445ff5751f9f39ec672b623372dff09c276e/library/std/src/panicking.rs:483
1: std::panicking::begin_panic_fmt
at /rustc/381b445ff5751f9f39ec672b623372dff09c276e/library/std/src/panicking.rs:437
2: <rustc_span::def_id::DefIndex as rustc_serialize::serialize::Encodable<E>>::encode
3: <rustc_serialize::json::Encoder as rustc_serialize::serialize::Encoder>::emit_struct
4: <rustc_serialize::json::Encoder as rustc_serialize::serialize::Encoder>::emit_struct
5: <rustc_serialize::json::Encoder as rustc_serialize::serialize::Encoder>::emit_seq
6: <rustc_serialize::json::Encoder as rustc_serialize::serialize::Encoder>::emit_map
7: <rustc_serialize::json::Encoder as rustc_serialize::serialize::Encoder>::emit_struct
8: <rustc_serialize::json::Encoder as rustc_serialize::serialize::Encoder>::emit_struct
9: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::link
10: rustc_interface::queries::Linker::link
11: rustc_span::with_source_map
12: rustc_interface::interface::create_compiler_and_run
13: scoped_tls::ScopedKey<T>::set
Meta
rustc --version --verbose
:
rustc 1.48.0-nightly (381b445ff 2020-09-29)
binary: rustc
commit-hash: 381b445ff5751f9f39ec672b623372dff09c276e
commit-date: 2020-09-29
host: x86_64-unknown-linux-gnu
release: 1.48.0-nightly
LLVM version: 11.0
Originally posted by @bjorn3 in #77795 (comment)
cc @0dvictor (original implementer of -Zno-link
Metadata
Metadata
Assignees
Labels
A-linkageArea: linking into static, shared libraries and binariesArea: linking into static, shared libraries and binariesA-metadataArea: Crate metadataArea: Crate metadataC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
0dvictor commentedon Oct 26, 2020
PR #73851 changed the encode/decode method of
DefId
to call the encode/decode method of its fieldpub index: DefIndex
; however,DefIndex
is only encodable in metadata. It panics if encoded anywhere else.When
no-link
was implemented, the encode/decode ofDefId
was purposely crafted to avoid calling the encode/decode method ofDefIndex
. The most straightforward fix is to implementEncodable
/Decodable
forDefIndex
to allow it be serialized outside of metadata.After that, may be now it is the time to re-think the way we store data in the
rlink
file.What do you think @bjorn3 ?
bjorn3 commentedon Oct 26, 2020
I think
DefId
should completely be avoided in the input of the linker function. One of the uses ifNativeLib
in it'sforeign_module
field. This field doesn't seem to be used by the linking code.0dvictor commentedon Oct 27, 2020
Good suggestion, let me look into it.
bjorn3 commentedon Dec 12, 2020
@0dvictor are you still working on this?
0dvictor commentedon Dec 15, 2020
Thank you for reminding and apologize for the delay. I did create a prototype but haven't got a chance polish it yet. I'll create the PR this week.
0dvictor commentedon Dec 19, 2020
Sorry again about the delay. I've created PR #80187, which fixes this issue.
Rollup merge of rust-lang#80187 - 0dvictor:nativelib, r=bjorn3
Rollup merge of rust-lang#80187 - 0dvictor:nativelib, r=bjorn3
Rollup merge of rust-lang#80187 - 0dvictor:nativelib, r=bjorn3
Rollup merge of rust-lang#80187 - 0dvictor:nativelib, r=bjorn3
Auto merge of rust-lang#80187 - 0dvictor:nativelib, r=bjorn3