Skip to content

Commit 5d83e7f

Browse files
Rollup merge of rust-lang#139113 - folkertdev:sanitizer-unstable-book-check-block, r=rcvalle
unstable book: in a sanitizer example, check the code Use some `#` directives to make sure the code checks on x86_64, and does not produce errors on other platforms. This example still used an older version of `#[naked]`, and because the snippet was ignored that was missed before. I'm not sure when this gets built on CI exactly, so it might be worthwhile to try and build it for a non-x86_64 architecture to make sure that works. I'm not sure how to verify locally that e.g. on aarch64 this code works without errors/warnings. try-job: aarch64-apple
2 parents 94722ca + 4524d9d commit 5d83e7f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ 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
248248
use std::arch::naked_asm;
249249
use std::mem;
250250

@@ -253,6 +253,7 @@ fn add_one(x: i32) -> i32 {
253253
}
254254

255255
#[unsafe(naked)]
256+
# #[cfg(target_arch = "x86_64")]
256257
pub extern "C" fn add_two(x: i32) {
257258
// x + 2 preceded by a landing pad/nop block
258259
naked_asm!(
@@ -276,6 +277,7 @@ fn do_twice(f: fn(i32) -> i32, arg: i32) -> i32 {
276277
f(arg) + f(arg)
277278
}
278279

280+
# #[cfg(target_arch = "x86_64")]
279281
fn main() {
280282
let answer = do_twice(add_one, 5);
281283

@@ -292,6 +294,7 @@ fn main() {
292294

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

0 commit comments

Comments
 (0)