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

Add support for Control Flow Guard on Windows. #68180

Merged
merged 1 commit into from
Feb 1, 2020

Conversation

ajpaverd
Copy link
Contributor

LLVM now supports Windows Control Flow Guard (CFG): llvm/llvm-project@d157a9b
This patch adds support for rustc to emit the required LLVM module flags to enable CFG metadata (cfguard=1) or metadata and checks (cfguard=2). The LLVM module flags are ignored on unsupported targets and operating systems.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @matthewjasper (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 13, 2020
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-7 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2020-01-13T13:47:29.6080386Z ##[command]git remote add origin https://github.com/rust-lang/rust
2020-01-13T13:47:29.6091988Z ##[command]git config gc.auto 0
2020-01-13T13:47:29.6095286Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2020-01-13T13:47:29.6097530Z ##[command]git config --get-all http.proxy
2020-01-13T13:47:29.6100476Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/68180/merge:refs/remotes/pull/68180/merge

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

src/librustc_codegen_ssa/back/linker.rs Outdated Show resolved Hide resolved
src/librustc_session/options.rs Outdated Show resolved Hide resolved
src/librustc_session/options.rs Outdated Show resolved Hide resolved
@rust-highfive
Copy link
Collaborator

The job mingw-check of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2020-01-13T15:57:32.7350355Z ##[command]git remote add origin https://github.com/rust-lang/rust
2020-01-13T15:57:32.7360960Z ##[command]git config gc.auto 0
2020-01-13T15:57:32.7363750Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2020-01-13T15:57:32.7365883Z ##[command]git config --get-all http.proxy
2020-01-13T15:57:32.7368451Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/68180/merge:refs/remotes/pull/68180/merge
---
2020-01-13T16:04:39.8690992Z     Checking rustc_resolve v0.0.0 (/checkout/src/librustc_resolve)
2020-01-13T16:04:42.7249528Z     Checking rustc_privacy v0.0.0 (/checkout/src/librustc_privacy)
2020-01-13T16:04:43.1766749Z     Checking rustc_plugin_impl v0.0.0 (/checkout/src/librustc_plugin_impl)
2020-01-13T16:04:43.3331896Z     Checking rustc_codegen_ssa v0.0.0 (/checkout/src/librustc_codegen_ssa)
2020-01-13T16:04:44.1411270Z error[E0609]: no field `control_flow_guard` on type `rustc::rustc_session::config::CodegenOptions`
2020-01-13T16:04:44.1412373Z     --> src/librustc_codegen_ssa/back/link.rs:1297:21
2020-01-13T16:04:44.1412850Z      |
2020-01-13T16:04:44.1413429Z 1297 |     if sess.opts.cg.control_flow_guard.is_some() {
2020-01-13T16:04:44.1414388Z      |
2020-01-13T16:04:44.1414388Z      |
2020-01-13T16:04:44.1415118Z      = note: available fields are: `ar`, `linker`, `link_arg`, `link_args`, `link_dead_code` ... and 34 others
2020-01-13T16:04:50.3124930Z error: aborting due to previous error
2020-01-13T16:04:50.3128561Z 
2020-01-13T16:04:50.3136682Z For more information about this error, try `rustc --explain E0609`.
2020-01-13T16:04:50.3211485Z error: could not compile `rustc_codegen_ssa`.
2020-01-13T16:04:50.3211485Z error: could not compile `rustc_codegen_ssa`.
2020-01-13T16:04:50.3240390Z warning: build failed, waiting for other jobs to finish...
2020-01-13T16:05:06.2488826Z error: build failed
2020-01-13T16:05:06.2509124Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "check" "-Zconfig-profile" "--target" "x86_64-unknown-linux-gnu" "-Zbinary-dep-depinfo" "-j" "2" "--release" "--color" "always" "--features" " llvm" "--manifest-path" "/checkout/src/rustc/Cargo.toml" "--message-format" "json-render-diagnostics"
2020-01-13T16:05:06.2522441Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap check
2020-01-13T16:05:06.2523120Z Build completed unsuccessfully in 0:05:21
2020-01-13T16:05:06.2574211Z == clock drift check ==
2020-01-13T16:05:06.2587231Z   local time: Mon Jan 13 16:05:06 UTC 2020
2020-01-13T16:05:06.2587231Z   local time: Mon Jan 13 16:05:06 UTC 2020
2020-01-13T16:05:06.5233919Z   network time: Mon, 13 Jan 2020 16:05:06 GMT
2020-01-13T16:05:06.5238393Z == end clock drift check ==
2020-01-13T16:05:06.8740093Z 
2020-01-13T16:05:06.8834248Z ##[error]Bash exited with code '1'.
2020-01-13T16:05:06.8878701Z ##[section]Starting: Checkout
2020-01-13T16:05:06.8880294Z ==============================================================================
2020-01-13T16:05:06.8880342Z Task         : Get sources
2020-01-13T16:05:06.8880397Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

Copy link
Member

@bjorn3 bjorn3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove yet from not yet supported.

src/librustc_codegen_ssa/back/linker.rs Outdated Show resolved Hide resolved
src/librustc_codegen_ssa/back/linker.rs Outdated Show resolved Hide resolved
src/librustc_codegen_ssa/back/linker.rs Outdated Show resolved Hide resolved
src/librustc_session/config.rs Outdated Show resolved Hide resolved
@matthewjasper
Copy link
Contributor

r? @nagisa

@bors
Copy link
Contributor

bors commented Jan 23, 2020

☔ The latest upstream changes (presumably #68474) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Member

@nagisa nagisa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me sans some cosmetic nits.

#[derive(Clone, Hash, Debug)]
pub enum CFGuard {
/// Emit Control Flow Guard metadata but no checks.
Nochecks,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename this variant to MetadataOnly or something else along the lines. Nochecks seems to imply CFG is disabled entirely, which it isn’t.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nochecks variant was intended to match the corresponding -cfguard,nochecks option in Clang (https://reviews.llvm.org/rL339420). Should we keep this terminology for consistency?

The intention is really to convey that this is "Control Flow Guard without any run-time checks". Is there somewhere in the documentation I could explain this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you can keep it in that case. Just s/Nochecks/NoChecks/. There are a couple of places for this documentation to go, including in the manpages and the unstable book.

src/librustc_session/options.rs Outdated Show resolved Hide resolved
src/librustc_session/options.rs Outdated Show resolved Hide resolved
src/librustc_session/options.rs Outdated Show resolved Hide resolved
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-7 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2020-01-27T15:18:03.4052000Z ========================== Starting Command Output ===========================
2020-01-27T15:18:03.4054599Z [command]/bin/bash --noprofile --norc /home/vsts/work/_temp/900a3905-9dfa-4ff9-88bf-554e55e5563c.sh
2020-01-27T15:18:03.4054761Z 
2020-01-27T15:18:03.4058061Z ##[section]Finishing: Disable git automatic line ending conversion
2020-01-27T15:18:03.4063731Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/68180/merge to s
2020-01-27T15:18:03.4065317Z Task         : Get sources
2020-01-27T15:18:03.4065353Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-01-27T15:18:03.4065431Z Version      : 1.0.0
2020-01-27T15:18:03.4065466Z Author       : Microsoft
---
2020-01-27T15:18:04.1845464Z ##[command]git remote add origin https://github.com/rust-lang/rust
2020-01-27T15:18:04.1939013Z ##[command]git config gc.auto 0
2020-01-27T15:18:04.1997939Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2020-01-27T15:18:04.2054176Z ##[command]git config --get-all http.proxy
2020-01-27T15:18:04.2190961Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/68180/merge:refs/remotes/pull/68180/merge

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@nagisa
Copy link
Member

nagisa commented Jan 28, 2020

@bors r+

Thanks!

@bors
Copy link
Contributor

bors commented Jan 28, 2020

📌 Commit 3b91aad265e977a59d3efa20bb31b213520fdd03 has been approved by nagisa

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 28, 2020
@ajpaverd
Copy link
Contributor Author

@bors r+

Thanks!

Thanks @nagisa! Quick question: should I squash the commits in this PR and rebase onto master to avoid including the merge commit?

@bors
Copy link
Contributor

bors commented Jan 28, 2020

@ajpaverd: 🔑 Insufficient privileges: Not in reviewers

@nagisa
Copy link
Member

nagisa commented Jan 28, 2020

Sure, please do squash.

This patch enables rustc to emit the required LLVM module flags to enable Control Flow Guard metadata (cfguard=1) or metadata and checks (cfguard=2). The LLVM module flags are ignored on unsupported targets and operating systems.
@bors
Copy link
Contributor

bors commented Jan 28, 2020

⌛ Testing commit 3b91aad265e977a59d3efa20bb31b213520fdd03 with merge 176b807bde66b7a680917edbe4a731cff8c1f68b...

@ajpaverd
Copy link
Contributor Author

Sure, please do squash.

Did my squash+rebase inadvertently interrupt bors' testing and merging?

@bjorn3
Copy link
Member

bjorn3 commented Jan 30, 2020

Did my squash+rebase inadvertently interrupt bors' testing and merging?

Yes, any push will prevent a PR from being merged before someone approves it again.

@nagisa
Copy link
Member

nagisa commented Jan 30, 2020

@bors r+ Sorry didn’t notice the squash. Thanks for doing it.

@bors
Copy link
Contributor

bors commented Jan 30, 2020

📌 Commit c0744e1 has been approved by nagisa

bors added a commit that referenced this pull request Jan 30, 2020
Add support for Control Flow Guard on Windows.

LLVM now supports Windows Control Flow Guard (CFG): llvm/llvm-project@d157a9b
This patch adds support for rustc to emit the required LLVM module flags to enable CFG metadata (cfguard=1) or metadata and checks (cfguard=2). The LLVM module flags are ignored on unsupported targets and operating systems.
@bors
Copy link
Contributor

bors commented Jan 30, 2020

⌛ Testing commit c0744e1 with merge 4924b66...

@bors
Copy link
Contributor

bors commented Jan 30, 2020

💥 Test timed out

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 30, 2020
@ajpaverd
Copy link
Contributor Author

ajpaverd commented Feb 1, 2020

Is there a way to figure out what caused the bors tests to time out (the logs just seem to say the operation was cancelled)?

@nagisa
Copy link
Member

nagisa commented Feb 1, 2020

Looks like it may have been cancelled manually (https://dev.azure.com/rust-lang/rust/_build/results?buildId=19568&view=results) probably to give way to something more important. Lets just retry for now. Thanks for bringing it to my attention.

@bors r+

@bors
Copy link
Contributor

bors commented Feb 1, 2020

💡 This pull request was already approved, no need to approve it again.

@bors
Copy link
Contributor

bors commented Feb 1, 2020

📌 Commit c0744e1 has been approved by nagisa

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 1, 2020
@bors
Copy link
Contributor

bors commented Feb 1, 2020

⌛ Testing commit c0744e1 with merge 64184a3...

bors added a commit that referenced this pull request Feb 1, 2020
Add support for Control Flow Guard on Windows.

LLVM now supports Windows Control Flow Guard (CFG): llvm/llvm-project@d157a9b
This patch adds support for rustc to emit the required LLVM module flags to enable CFG metadata (cfguard=1) or metadata and checks (cfguard=2). The LLVM module flags are ignored on unsupported targets and operating systems.
@bors
Copy link
Contributor

bors commented Feb 1, 2020

☀️ Test successful - checks-azure
Approved by: nagisa
Pushing 64184a3 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Feb 1, 2020
@bors bors merged commit c0744e1 into rust-lang:master Feb 1, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Feb 11, 2020
…Simulacrum

Enable Control Flow Guard in rustbuild

Now that Rust supports Control Flow Guard (rust-lang#68180), add a config.toml option to build the standard library with CFG enabled.

r? @nagisa
@yvt yvt mentioned this pull request Feb 22, 2020
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants