Skip to content

Commit 1deefc3

Browse files
committed
Rewrite for dealing with constant expressions
1 parent b12e2fb commit 1deefc3

File tree

3 files changed

+469
-64
lines changed

3 files changed

+469
-64
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Global constant data such as exception handler tables should not be redirected by Windows Secure Hot-Patching
2+
//
3+
// RUN: %clang_cl -c --target=x86_64-windows-msvc /EHsc -O2 -fms-secure-hotpatch-functions-list=this_gets_hotpatched /Fo%t.obj /clang:-S /clang:-o- %s 2>& 1 | FileCheck %s
4+
5+
class Foo {
6+
public:
7+
int x;
8+
};
9+
10+
void this_might_throw();
11+
12+
extern "C" int this_gets_hotpatched(int k) {
13+
int ret;
14+
try {
15+
this_might_throw();
16+
ret = 1;
17+
} catch (Foo& f) {
18+
ret = 2;
19+
}
20+
return ret;
21+
}
22+
23+
// We expect that RTTI data is not redirected.
24+
// CHECK-NOT: "__ref_??_R0?AVFoo@@@8"
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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

Comments
 (0)