-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Description
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?