Skip to content

Commit

Permalink
Don't silently ignore invalid data in target spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Jethro Beekman committed Jul 13, 2018
1 parent e5f6498 commit 488472d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
26 changes: 15 additions & 11 deletions src/librustc_target/spec/mod.rs
Expand Up @@ -861,23 +861,27 @@ impl Target {
} );
($key_name:ident, link_args) => ( {
let name = (stringify!($key_name)).replace("_", "-");
if let Some(obj) = obj.find(&name[..]).and_then(|o| o.as_object()) {
if let Some(val) = obj.find(&name[..]) {
let obj = val.as_object().ok_or_else(|| format!("{}: expected a \
JSON object with fields per linker-flavor.", name))?;
let mut args = LinkArgs::new();
for (k, v) in obj {
let k = LinkerFlavor::from_str(&k).ok_or_else(|| {
let flavor = LinkerFlavor::from_str(&k).ok_or_else(|| {
format!("{}: '{}' is not a valid value for linker-flavor. \
Use 'em', 'gcc', 'ld' or 'msvc'", name, k)
})?;

let v = v.as_array().map(|a| {
a
.iter()
.filter_map(|o| o.as_string())
.map(|s| s.to_owned())
.collect::<Vec<_>>()
}).unwrap_or(vec![]);

args.insert(k, v);
let v = v.as_array().ok_or_else(||
format!("{}.{}: expected a JSON array", name, k)
)?.iter().enumerate()
.map(|(i,s)| {
let s = s.as_string().ok_or_else(||
format!("{}.{}[{}]: expected a JSON string", name, k, i))?;
Ok(s.to_owned())
})
.collect::<Result<Vec<_>, String>>()?;

args.insert(flavor, v);
}
base.options.$key_name = args;
}
Expand Down
@@ -1,5 +1,5 @@
{
"pre-link-args": ["-m64"],
"pre-link-args": {"gcc": ["-m64"]},
"data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
"linker-flavor": "gcc",
"llvm-target": "x86_64-unknown-linux-gnu",
Expand Down

0 comments on commit 488472d

Please sign in to comment.