llvm::LLVMRustAddModuleFlag(llmod, avoid_plt, 1);
}
- // Set module flags to enable Windows Control Flow Guard (/guard:cf) metadata
- // only (`cfguard=1`) or metadata and checks (`cfguard=2`).
- match sess.opts.debugging_opts.control_flow_guard {
- CFGuard::Disabled => {}
- CFGuard::NoChecks => {
- llvm::LLVMRustAddModuleFlag(llmod, "cfguard\0".as_ptr() as *const _, 1)
+ // Control Flow Guard is currently only supported by the MSVC linker on Windows.
+ if sess.target.target.options.is_like_msvc {
+ match sess.opts.debugging_opts.control_flow_guard {
+ CFGuard::Disabled => {}
+ CFGuard::NoChecks => {
+ // Set `cfguard=1` module flag to emit metadata only.
+ llvm::LLVMRustAddModuleFlag(llmod, "cfguard\0".as_ptr() as *const _, 1)
+ }
+ CFGuard::Checks => {
+ // Set `cfguard=2` module flag to emit metadata and checks.
+ llvm::LLVMRustAddModuleFlag(llmod, "cfguard\0".as_ptr() as *const _, 2)
+ }
}
- CFGuard::Checks => llvm::LLVMRustAddModuleFlag(llmod, "cfguard\0".as_ptr() as *const _, 2),
}
llmod
self.cmd.arg("__llvm_profile_runtime");
}
- fn control_flow_guard(&mut self) {
- self.sess.warn("Windows Control Flow Guard is not supported by this linker.");
- }
+ fn control_flow_guard(&mut self) {}
fn debuginfo(&mut self, strip: Strip) {
match strip {
// noop, but maybe we need something like the gnu linker?
}
- fn control_flow_guard(&mut self) {
- self.sess.warn("Windows Control Flow Guard is not supported by this linker.");
- }
+ fn control_flow_guard(&mut self) {}
fn debuginfo(&mut self, _strip: Strip) {
// Preserve names or generate source maps depending on debug info
}
}
- fn control_flow_guard(&mut self) {
- self.sess.warn("Windows Control Flow Guard is not supported by this linker.");
- }
+ fn control_flow_guard(&mut self) {}
fn no_crt_objects(&mut self) {}
fn no_default_libraries(&mut self) {}
- fn control_flow_guard(&mut self) {
- self.sess.warn("Windows Control Flow Guard is not supported by this linker.");
- }
+ fn control_flow_guard(&mut self) {}
fn export_symbols(&mut self, _tmpdir: &Path, _crate_type: CrateType) {}
--- /dev/null
+// compile-flags: -Z control-flow-guard=checks
+// only-msvc
+
+#![crate_type = "lib"]
+
+// A basic test function.
+pub fn test() {
+}
+
+// Ensure the module flag cfguard=2 is present
+// CHECK: !"cfguard", i32 2
--- /dev/null
+// compile-flags: -Z control-flow-guard=no
+// only-msvc
+
+#![crate_type = "lib"]
+
+// A basic test function.
+pub fn test() {
+}
+
+// Ensure the module flag cfguard is not present
+// CHECK-NOT: !"cfguard"
--- /dev/null
+// compile-flags: -Z control-flow-guard=nochecks
+// only-msvc
+
+#![crate_type = "lib"]
+
+// A basic test function.
+pub fn test() {
+}
+
+// Ensure the module flag cfguard=1 is present
+// CHECK: !"cfguard", i32 1
--- /dev/null
+// compile-flags: -Z control-flow-guard
+// ignore-msvc
+
+#![crate_type = "lib"]
+
+// A basic test function.
+pub fn test() {
+}
+
+// Ensure the cfguard module flag is not added for non-MSVC targets.
+// CHECK-NOT: !"cfguard"
+++ /dev/null
-// compile-flags: -Z control-flow-guard=checks
-
-#![crate_type = "lib"]
-
-// A basic test function.
-pub fn test() {
-}
-
-// Ensure the module flag cfguard=2 is present
-// CHECK: !"cfguard", i32 2
+++ /dev/null
-// compile-flags: -Z control-flow-guard=no
-
-#![crate_type = "lib"]
-
-// A basic test function.
-pub fn test() {
-}
-
-// Ensure the module flag cfguard is not present
-// CHECK-NOT: !"cfguard"
+++ /dev/null
-// compile-flags: -Z control-flow-guard=nochecks
-
-#![crate_type = "lib"]
-
-// A basic test function.
-pub fn test() {
-}
-
-// Ensure the module flag cfguard=1 is present
-// CHECK: !"cfguard", i32 1
--- /dev/null
+// run-pass
+// compile-flags: -Z control-flow-guard
+
+pub fn main() {
+ println!("hello, world");
+}