diff --git a/src/doc/unstable-book/src/compiler-flags/sanitizer.md b/src/doc/unstable-book/src/compiler-flags/sanitizer.md index 2f9d4d22e5a85..5b8ba78721e19 100644 --- a/src/doc/unstable-book/src/compiler-flags/sanitizer.md +++ b/src/doc/unstable-book/src/compiler-flags/sanitizer.md @@ -244,7 +244,9 @@ See the [Clang ControlFlowIntegrity documentation][clang-cfi] for more details. ## Example 1: Redirecting control flow using an indirect branch/call to an invalid destination -```rust,ignore (making doc tests pass cross-platform is hard) +```rust +#![feature(naked_functions)] + use std::arch::naked_asm; use std::mem; @@ -253,6 +255,7 @@ fn add_one(x: i32) -> i32 { } #[unsafe(naked)] +# #[cfg(target_arch = "x86_64")] pub extern "C" fn add_two(x: i32) { // x + 2 preceded by a landing pad/nop block naked_asm!( @@ -276,6 +279,7 @@ fn do_twice(f: fn(i32) -> i32, arg: i32) -> i32 { f(arg) + f(arg) } +# #[cfg(target_arch = "x86_64")] fn main() { let answer = do_twice(add_one, 5); @@ -292,6 +296,7 @@ fn main() { println!("The next answer is: {}", next_answer); } +# #[cfg(not(target_arch = "x86_64"))] fn main() {} ``` Fig. 1. Redirecting control flow using an indirect branch/call to an invalid destination (i.e., within the body of the function).