Skip to content
/ rust Public
forked from rust-lang/rust

Commit eb898c5

Browse files
authored
Rollup merge of rust-lang#139113 - folkertdev:sanitizer-unstable-book-check-block, r=GuillaumeGomez
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.
2 parents fa313d7 + b00b6a8 commit eb898c5

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

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

+18-18
Original file line numberDiff line numberDiff line change
@@ -244,36 +244,36 @@ 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
#![feature(naked_functions)]
249249

250-
use std::arch::asm;
250+
use std::arch::naked_asm;
251251
use std::mem;
252252

253253
fn add_one(x: i32) -> i32 {
254254
x + 1
255255
}
256256

257+
# #[cfg(not(target_arch = "x86_64"))] pub extern "C" fn add_two(_: i32) {}
258+
257259
#[naked]
260+
# #[cfg(target_arch = "x86_64")]
258261
pub extern "C" fn add_two(x: i32) {
259262
// x + 2 preceded by a landing pad/nop block
260263
unsafe {
261-
asm!(
262-
"
263-
nop
264-
nop
265-
nop
266-
nop
267-
nop
268-
nop
269-
nop
270-
nop
271-
nop
272-
lea eax, [rdi+2]
273-
ret
274-
",
275-
options(noreturn)
276-
);
264+
naked_asm!(
265+
"nop",
266+
"nop",
267+
"nop",
268+
"nop",
269+
"nop",
270+
"nop",
271+
"nop",
272+
"nop",
273+
"nop",
274+
"lea eax, [rdi+2]",
275+
"ret",
276+
)
277277
}
278278
}
279279

0 commit comments

Comments
 (0)