Skip to content

Commit 731f1cd

Browse files
committed
unstable book: in a sanitizer example, check the code
this uses some # directives to make sure the code works on x86_64, and does not produce errors on other platforms
1 parent 6eef33b commit 731f1cd

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/doc/unstable-book/src/compiler-flags/sanitizer.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,9 @@ See the [Clang ControlFlowIntegrity documentation][clang-cfi] for more details.
244244
245245
## Example 1: Redirecting control flow using an indirect branch/call to an invalid destination
246246
247-
```rust,ignore (making doc tests pass cross-platform is hard)
247+
```rust
248+
#![feature(naked_functions)]
249+
248250
use std::arch::naked_asm;
249251
use std::mem;
250252

@@ -253,6 +255,7 @@ fn add_one(x: i32) -> i32 {
253255
}
254256

255257
#[unsafe(naked)]
258+
# #[cfg(target_arch = "x86_64")]
256259
pub extern "C" fn add_two(x: i32) {
257260
// x + 2 preceded by a landing pad/nop block
258261
naked_asm!(
@@ -276,6 +279,7 @@ fn do_twice(f: fn(i32) -> i32, arg: i32) -> i32 {
276279
f(arg) + f(arg)
277280
}
278281

282+
# #[cfg(target_arch = "x86_64")]
279283
fn main() {
280284
let answer = do_twice(add_one, 5);
281285

@@ -292,6 +296,7 @@ fn main() {
292296

293297
println!("The next answer is: {}", next_answer);
294298
}
299+
# #[cfg(not(target_arch = "x86_64"))] fn main() {}
295300
```
296301
Fig. 1. Redirecting control flow using an indirect branch/call to an invalid
297302
destination (i.e., within the body of the function).

0 commit comments

Comments
 (0)