Skip to content

-Zno-link is broken #77857

@bjorn3

Description

@bjorn3
Member

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

Activity

added
requires-nightlyThis issue requires a nightly compiler in some way.
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Oct 12, 2020
added
A-linkageArea: linking into static, shared libraries and binaries
A-metadataArea: Crate metadata
on Oct 12, 2020
0dvictor

0dvictor commented on Oct 26, 2020

@0dvictor
Contributor

PR #73851 changed the encode/decode method of DefId to call the encode/decode method of its field pub index: DefIndex; however, DefIndex is only encodable in metadata. It panics if encoded anywhere else.

When no-link was implemented, the encode/decode of DefId was purposely crafted to avoid calling the encode/decode method of DefIndex. The most straightforward fix is to implement Encodable/Decodable for DefIndex 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

bjorn3 commented on Oct 26, 2020

@bjorn3
MemberAuthor

I think DefId should completely be avoided in the input of the linker function. One of the uses if NativeLib in it's foreign_module field. This field doesn't seem to be used by the linking code.

0dvictor

0dvictor commented on Oct 27, 2020

@0dvictor
Contributor

Good suggestion, let me look into it.

bjorn3

bjorn3 commented on Dec 12, 2020

@bjorn3
MemberAuthor

@0dvictor are you still working on this?

0dvictor

0dvictor commented on Dec 15, 2020

@0dvictor
Contributor

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

0dvictor commented on Dec 19, 2020

@0dvictor
Contributor

Sorry again about the delay. I've created PR #80187, which fixes this issue.

added 4 commits that reference this issue on Dec 23, 2020
5bf0ba9
22d4da8
11939c8
d11537d
added a commit that references this issue on Dec 25, 2020
198ec34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesA-metadataArea: Crate metadataC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @jonas-schievink@0dvictor@bjorn3@camelid

      Issue actions

        -Zno-link is broken · Issue #77857 · rust-lang/rust