rustc silently ignores invalid -C target-feature names
Compiling a simple Hello, World program:
$ rustc -V
rustc 1.20.0 (f3d6973f4 2017-08-27)
# Note the trailing "zzzz"
$ RUSTFLAGS=-Ctarget-feature=+crt-staticzzzz cargo build -v
Compiling rust-test v0.1.0 (rust-test)
Running `rustc --crate-name rust_test src/main.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=aafe1708c049ad76 -C extra-filename=-aafe1708c049ad76 --out-dir rust-test/target/debug/deps -L dependency=rust-test/target/debug/deps '-Ctarget-feature=+crt-staticzzzz'`
Finished dev [unoptimized + debuginfo] target(s) in 0.25 secs
Should RUSTFLAGS=-Ctarget-feature=+crt-staticzzzz be silently accepted?
If I pass RUSTFLAGS=-Ctarget-feature=+batman, a warning is printed, as expected.
'+batman' is not a recognized feature for this target (ignoring feature)
Why is trailing misspelling silently allowed?
This is happening inside LLVM and plausibly should be filed with that project.
Zack M. Davis at 2017-10-02 00:49:09
crt-staticis not passed to LLVM (and shouldn't be). It seems as if rustc consumes not justcrt-staticbut also other target features that have it as a prefix? This filtering looks suspicious:https://github.com/rust-lang/rust/blob/ded38dbfc258f8e253ab61d1bca08b21efa2bf3d/src/librustc_trans/back/write.rs#L119-L121
Hanna Kruppe at 2017-10-02 01:01:25
Also rustc:
- doesn't canonicalize the feature list like clang does - there may be duplicates, same features with both
+and-. I tried to find places in LLVM where this could break things, but found a couple at best. Memory sanitizer perhaps? https://github.com/rust-lang/llvm-project/blob/rustc/9.0-2019-12-19/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp#L3738. The main thing (subtarget creation) is done correctly. There's at least one such place in rustc ("+atomics"check). - accepts features without
+or-. I have no idea why the assert inMCSubtargetInfo.cpp/ApplyFeatureFlagdoesn't fire on this.
Vadim Petrochenkov at 2020-05-10 20:26:56
- doesn't canonicalize the feature list like clang does - there may be duplicates, same features with both