|
1 | 1 | // hotpatch has two requirements: |
2 | | -// 1. the first instruction of a functin must be at least two bytes long |
3 | | -// 2. there must not be a jump to the first instruction |
| 2 | +// 1) the first instruction of a functin must be at least two bytes long |
| 3 | +// 2) there must not be a jump to the first instruction |
4 | 4 |
|
5 | | -// the hotpatch flag should insert nops as needed to fullfil the requirements, |
6 | | -// but only if the the function does not already fulfill them. |
7 | | -// Over 99% of function in regular codebases already fulfill the conditions, |
8 | | -// so its important to check that those are |
9 | | -// unneccessarily affected |
10 | | - |
11 | | -// ---------------------------------------------------------------------------------------------- |
12 | | - |
13 | | -// regularly this tailcall would jump to the first instruction the function |
14 | | -// CHECK-LABEL: <tailcall_fn>: |
15 | | -// CHECK: jne 0x0 <tailcall_fn> |
16 | | - |
17 | | -// hotpatch insert nops so that the tailcall will not jump to the first instruction of the function |
18 | | -// HOTPATCH-LABEL: <tailcall_fn>: |
19 | | -// HOTPATCH-NOT: jne 0x0 <tailcall_fn> |
20 | | - |
21 | | -#[no_mangle] |
22 | | -pub fn tailcall_fn() { |
23 | | - use std::sync::atomic::{AtomicUsize, Ordering}; |
24 | | - static COUNT: AtomicUsize = AtomicUsize::new(0); |
25 | | - if COUNT.fetch_sub(1, Ordering::Relaxed) != 0 { |
26 | | - tailcall_fn() |
27 | | - } |
28 | | -} |
| 5 | +// The LLVM attribute we use '"patchable-function", "prologue-short-redirect"' only ensures 1) |
| 6 | +// However in practice 2) rarely matters. Its rare that it occurs and the problems it caused can be |
| 7 | +// avoided by the hotpatch tool. |
| 8 | +// In this test we check if 1) is ensured by inserted nops as needed |
29 | 9 |
|
30 | 10 | // ---------------------------------------------------------------------------------------------- |
31 | 11 |
|
32 | 12 | // empty_fn just returns. Note that 'ret' is a single byte instruction, but hotpatch requires |
33 | 13 | // a two or more byte instructions to be at the start of the functions. |
34 | 14 | // Preferably we would also tests a different single byte instruction, |
35 | | -// but I was not able to make rustc emit anything but 'ret'. |
| 15 | +// but I was not able to find an example with another one byte intstruction. |
36 | 16 |
|
37 | 17 | // check that if the first instruction is just a single byte, so our test is valid |
38 | 18 | // CHECK-LABEL: <empty_fn>: |
|
0 commit comments