|
| 1 | +// This verifies that global variable redirection works correctly when using hotpatching. |
| 2 | +// |
| 3 | +// RUN: %clang_cl -c --target=x86_64-windows-msvc -O2 /Z7 -fms-secure-hotpatch-functions-list=hp1,hp2,hp3,hp4 /clang:-S /clang:-o- %s | FileCheck %s |
| 4 | + |
| 5 | +#ifdef __clang__ |
| 6 | +#define NO_TAIL __attribute__((disable_tail_calls)) |
| 7 | +#else |
| 8 | +#define NO_TAIL |
| 9 | +#endif |
| 10 | + |
| 11 | +extern int g_data[10]; |
| 12 | + |
| 13 | +struct SomeData { |
| 14 | + int x; |
| 15 | + int y; |
| 16 | +}; |
| 17 | + |
| 18 | +const struct SomeData g_this_is_const = { 100, 200 }; |
| 19 | + |
| 20 | +struct HasPointers { |
| 21 | + int* ptr; |
| 22 | + int x; |
| 23 | +}; |
| 24 | + |
| 25 | +extern struct HasPointers g_has_pointers; |
| 26 | + |
| 27 | +void take_data(const void* p); |
| 28 | + |
| 29 | +void hp1() NO_TAIL { |
| 30 | + take_data(&g_data[5]); |
| 31 | +} |
| 32 | + |
| 33 | +// CHECK: hp1: |
| 34 | +// CHECK: mov rcx, qword ptr [rip + __ref_g_data] |
| 35 | +// CHECK: add rcx, 20 |
| 36 | +// CHECK: call take_data |
| 37 | +// CHECK: .seh_endproc |
| 38 | + |
| 39 | +void hp2() NO_TAIL { |
| 40 | + // We do not expect string literals to be redirected. |
| 41 | + take_data("hello, world!"); |
| 42 | +} |
| 43 | + |
| 44 | +// CHECK: hp2: |
| 45 | +// CHECK: lea rcx, [rip + "??_C@_0O@KJBLMJCB@hello?0?5world?$CB?$AA@"] |
| 46 | +// CHECK: call take_data |
| 47 | +// CHECK: .seh_endproc |
| 48 | + |
| 49 | +void hp3() NO_TAIL { |
| 50 | + // We do not expect g_this_is_const to be redirected because it is const |
| 51 | + // and contains no pointers. |
| 52 | + take_data(&g_this_is_const); |
| 53 | +} |
| 54 | + |
| 55 | +// CHECK: hp3: |
| 56 | +// CHECK: lea rcx, [rip + g_this_is_const] |
| 57 | +// CHECK: call take_data |
| 58 | +// CHECK-NOT: __ref_g_this_is_const |
| 59 | +// CHECK: .seh_endproc |
| 60 | + |
| 61 | +void hp4() NO_TAIL { |
| 62 | + take_data(&g_has_pointers); |
| 63 | + // We expect &g_has_pointers to be redirected. |
| 64 | +} |
| 65 | + |
| 66 | +// CHECK: hp4: |
| 67 | +// CHECK: mov rcx, qword ptr [rip + __ref_g_has_pointers] |
| 68 | +// CHECK: call take_data |
| 69 | +// CHECK: .seh_endproc |
0 commit comments