Skip to content

Commit f4701cd

Browse files
committed
Do not allow JSON targets to set is-builtin: true
1 parent 6440785 commit f4701cd

File tree

5 files changed

+19
-1
lines changed

5 files changed

+19
-1
lines changed

compiler/rustc_target/src/spec/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2010,6 +2010,10 @@ impl Target {
20102010
key!(supported_sanitizers, SanitizerSet)?;
20112011
key!(default_adjusted_cabi, Option<Abi>)?;
20122012

2013+
if base.is_builtin {
2014+
// This can cause unfortunate ICEs later down the line.
2015+
return Err(format!("may not set is_builtin for targets not built-in"));
2016+
}
20132017
// Each field should have been read using `Json::remove_key` so any keys remaining are unused.
20142018
let remaining_keys = obj.as_object().ok_or("Expected JSON object for target")?.keys();
20152019
Ok((

src/test/run-make-fulldeps/rustdoc-target-spec-json-path/target.json

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"executables": true,
99
"has-elf-tls": true,
1010
"has-rpath": true,
11-
"is-builtin": true,
1211
"linker-is-gnu": true,
1312
"llvm-target": "x86_64-unknown-linux-gnu",
1413
"max-atomic-width": 64,

src/test/run-make-fulldeps/target-specs/Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ all:
77
RUST_TARGET_PATH=. $(RUSTC) foo.rs --target=my-awesome-platform --crate-type=lib --emit=asm
88
RUST_TARGET_PATH=. $(RUSTC) foo.rs --target=my-x86_64-unknown-linux-gnu-platform --crate-type=lib --emit=asm
99
$(RUSTC) -Z unstable-options --target=my-awesome-platform.json --print target-spec-json > $(TMPDIR)/test-platform.json && $(RUSTC) -Z unstable-options --target=$(TMPDIR)/test-platform.json --print target-spec-json | diff -q $(TMPDIR)/test-platform.json -
10+
$(RUSTC) foo.rs --target=definitely-not-builtin-target 2>&1 | $(CGREP) 'may not set is_builtin'
11+
$(RUSTC) foo.rs --target=mismatching-data-layout
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"arch": "x86_64",
3+
"is-builtin": true,
4+
"data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
5+
"llvm-target": "x86_64-unknown-unknown-gnu",
6+
"target-pointer-width": "64"
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"arch": "x86_64",
3+
"data-layout": "e-m:e-i64:16:32:64",
4+
"llvm-target": "x86_64-unknown-unknown-gnu",
5+
"target-pointer-width": "64"
6+
}

0 commit comments

Comments
 (0)