File tree 1 file changed +18
-18
lines changed
src/doc/unstable-book/src/compiler-flags
1 file changed +18
-18
lines changed Original file line number Diff line number Diff line change @@ -244,43 +244,42 @@ See the [Clang ControlFlowIntegrity documentation][clang-cfi] for more details.
244
244
245
245
# # Example 1: Redirecting control flow using an indirect branch/call to an invalid destination
246
246
247
- ` ` ` rust,ignore (making doc tests pass cross-platform is hard)
247
+ ` ` ` rust
248
248
#! [feature(naked_functions)]
249
249
250
- use std::arch::asm ;
250
+ use std::arch::naked_asm ;
251
251
use std::mem;
252
252
253
253
fn add_one(x: i32) -> i32 {
254
254
x + 1
255
255
}
256
256
257
257
# [naked]
258
+ # #[cfg(target_arch = "x86_64")]
258
259
pub extern " C" fn add_two(x: i32) {
259
260
// x + 2 preceded by a landing pad/nop block
260
261
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
- );
262
+ naked_asm! (
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
+ )
277
275
}
278
276
}
279
277
280
278
fn do_twice(f: fn(i32) -> i32, arg: i32) -> i32 {
281
279
f(arg) + f(arg)
282
280
}
283
281
282
+ # #[cfg(target_arch = "x86_64")]
284
283
fn main () {
285
284
let answer = do_twice(add_one, 5);
286
285
@@ -297,6 +296,7 @@ fn main() {
297
296
298
297
println! (" The next answer is: {}" , next_answer);
299
298
}
299
+ # #[cfg(not(target_arch = "x86_64"))] fn main() {}
300
300
` ` `
301
301
Fig. 1. Redirecting control flow using an indirect branch/call to an invalid
302
302
destination (i.e., within the body of the function).
You can’t perform that action at this time.
0 commit comments