Skip to content

Impossible to specify link-args for lld in json target specification #58527

Open
@ids1024

Description

@ids1024

Rustc target spec json files can specify link-args and pre-link-args. For instance, here is part of the output of rustc -Z unstable-options --print target-spec-json --target i686-unknown-linux-gnu:

  "pre-link-args": {
    "gcc": [
      "-Wl,--as-needed",
      "-Wl,-z,noexecstack",
      "-m32"
    ]
  },

As far as I can tell, for annoying reasons about how it's implemented, it isn't possible to set this with lld instead of gcc.

In librustc_target/spec/mod.rs:

#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash,
         RustcEncodable, RustcDecodable)]
pub enum LinkerFlavor {
    Em,
    Gcc,
    Ld,
    Msvc,
    Lld(LldFlavor),
    PtxLinker,
}

This is serialized and de-serialized with rustc-serialize. Unlike the other variants, Lld contains a field. Looking at how the json serialization/de-serialization is implemented, it looks like this is would be represented as {"variant": "lld", "fields": [...]"}.

The issue is that this can't appear in the target spec in place of "gcc" from the example above, since json doesn't allow an object to be the key of an object.

Is my analysis right, and this is currently impossible to do in a json target spec, or am I missing something?

Solution

I think the best solution in the short term is to implement Decodable and Encodable manually for the enum. I presume changing the representation of this wouldn't break anything in practice, and even if it did it's an implementation detail that doesn't provide stability guarantees?

In the long term, I'm not sure what the plans for rustc-serialize are. It describes itself as "deprecated". Is it ideally intended to be replaced with serde at some point, which just hasn't been done since it's a lot of work?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-target-specsArea: Compile-target specificationsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions