File tree 1 file changed +8
-2
lines changed
src/doc/unstable-book/src/compiler-flags
1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -213,7 +213,7 @@ See the [Clang ControlFlowIntegrity documentation][clang-cfi] for more details.
213
213
214
214
# # Example
215
215
216
- ` ` ` text
216
+ ` ` ` rust
217
217
#! [feature(naked_functions)]
218
218
219
219
use std::arch::asm;
@@ -223,6 +223,8 @@ fn add_one(x: i32) -> i32 {
223
223
x + 1
224
224
}
225
225
226
+ # // Only define this function if the assembly works
227
+ # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
226
228
# [naked]
227
229
pub extern " C" fn add_two(x: i32) {
228
230
// x + 2 preceded by a landing pad/nop block
@@ -238,7 +240,7 @@ pub extern "C" fn add_two(x: i32) {
238
240
nop
239
241
nop
240
242
nop
241
- lea rax , [rdi +2]
243
+ lea eax , [edi +2]
242
244
ret
243
245
" ,
244
246
options(noreturn)
@@ -250,6 +252,10 @@ fn do_twice(f: fn(i32) -> i32, arg: i32) -> i32 {
250
252
f(arg) + f(arg)
251
253
}
252
254
255
+ # // Can only call add_two on x86/64
256
+ # #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
257
+ # fn main() { println!("this test does not work on this target") }
258
+ # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
253
259
fn main () {
254
260
let answer = do_twice(add_one, 5);
255
261
You can’t perform that action at this time.
0 commit comments