annotate tango-0.99.9.patch @ 1650:40bd4a0d4870

Update to work with LLVM 2.7. Removed use of dyn_cast, llvm no compiles without exceptions and rtti by default. We do need exceptions for the libconfig stuff, but rtti isn't necessary (anymore). Debug info needs to be rewritten, as in LLVM 2.7 the format has completely changed. To have something to look at while rewriting, the old code has been wrapped inside #ifndef DISABLE_DEBUG_INFO , this means that you have to define this to compile at the moment. Updated tango 0.99.9 patch to include updated EH runtime code, which is needed for LLVM 2.7 as well.
author Tomas Lindquist Olsen
date Wed, 19 May 2010 12:42:32 +0200
parents 5c0cebff9be8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1633
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
1 Index: tango/core/rt/compiler/ldc/rt/lifetime.d
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
2 ===================================================================
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
3 --- tango/core/rt/compiler/ldc/rt/lifetime.d (revision 5462)
1633
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
4 +++ tango/core/rt/compiler/ldc/rt/lifetime.d (working copy)
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
5 @@ -786,6 +786,7 @@
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
6 return *cast(long*)px;
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
7 }
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
8
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
9 ++/
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
10
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
11 /**
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
12 *
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
13 @@ -849,10 +850,11 @@
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
14
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
15
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
16 /**
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
17 - *
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
18 + * Appends a single element to an array.
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
19 */
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
20 -extern (C) byte[] _d_arrayappendcT(TypeInfo ti, ref byte[] x, ...)
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
21 +extern (C) byte[] _d_arrayappendcT(TypeInfo ti, void* array, void* element)
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
22 {
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
23 + auto x = cast(byte[]*)array;
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
24 auto sizeelem = ti.next.tsize(); // array element size
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
25 auto info = gc_query(x.ptr);
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
26 auto length = x.length;
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
27 @@ -879,16 +881,16 @@
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
28 assert(newcap >= newlength * sizeelem);
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
29 newdata = cast(byte *)gc_malloc(newcap + 1, info.attr);
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
30 memcpy(newdata, x.ptr, length * sizeelem);
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
31 - (cast(void**)(&x))[1] = newdata;
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
32 + (cast(void**)x)[1] = newdata;
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
33 }
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
34 L1:
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
35 - byte *argp = cast(byte *)(&ti + 2);
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
36 + byte *argp = cast(byte *)element;
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
37
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
38 - *cast(size_t *)&x = newlength;
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
39 + *cast(size_t *)x = newlength;
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
40 x.ptr[length * sizeelem .. newsize] = argp[0 .. sizeelem];
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
41 assert((cast(size_t)x.ptr & 15) == 0);
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
42 assert(gc_sizeOf(x.ptr) > x.length * sizeelem);
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
43 - return x;
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
44 + return *x;
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
45 }
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
46
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
47
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
48 @@ -1128,6 +1130,7 @@
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
49 return result;
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
50 }
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
51
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
52 +/+
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
53
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
54 /**
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
diff changeset
55 *
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
56 Index: tango/core/rt/compiler/ldc/rt/eh.d
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
57 ===================================================================
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
58 --- tango/core/rt/compiler/ldc/rt/eh.d (revision 5462)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
59 +++ tango/core/rt/compiler/ldc/rt/eh.d (working copy)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
60 @@ -1,38 +1,34 @@
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
61 /**
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
62 * This module contains functions and structures required for
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
63 - * exception handling.
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
64 + * dwarf exception handling with llvm
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
65 */
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
66 module rt.eh;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
67
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
68 -import ldc.cstdarg;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
69 -import rt.compiler.util.console;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
70 +//debug = EH_personality;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
71
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
72 -// debug = EH_personality;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
73 -
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
74 // current EH implementation works on x86
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
75 // if it has a working unwind runtime
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
76 version(X86) {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
77 version(linux) version=X86_UNWIND;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
78 version(darwin) version=X86_UNWIND;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
79 version(solaris) version=X86_UNWIND;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
80 - version(freebsd) version=X86_UNWIND;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
81 }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
82 version(X86_64) {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
83 version(linux) version=X86_UNWIND;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
84 version(darwin) version=X86_UNWIND;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
85 version(solaris) version=X86_UNWIND;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
86 - version(freebsd) version=X86_UNWIND;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
87 }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
88
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
89 //version = HP_LIBUNWIND;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
90
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
91 private extern(C) void abort();
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
92 private extern(C) int printf(char*, ...);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
93 -private extern(C) int vprintf(char*, va_list va);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
94 +//private extern(C) int vprintf(char*, va_list va);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
95
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
96 // D runtime functions
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
97 extern(C) {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
98 - int _d_isbaseof(ClassInfo oc, ClassInfo c);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
99 +// int _d_isbaseof(ClassInfo oc, ClassInfo c);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
100 + Object _d_dynamic_cast(Object o, ClassInfo c);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
101 }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
102
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
103 // libunwind headers
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
104 @@ -74,16 +70,19 @@
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
105 // interface to HP's libunwind from http://www.nongnu.org/libunwind/
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
106 version(HP_LIBUNWIND)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
107 {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
108 + // Haven't checked whether and how it has _Unwind_Get{Text,Data}RelBase
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
109 + pragma (msg, "HP_LIBUNWIND interface is out of date and untested");
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
110 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
111 void __libunwind_Unwind_Resume(_Unwind_Exception *);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
112 _Unwind_Reason_Code __libunwind_Unwind_RaiseException(_Unwind_Exception *);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
113 ptrdiff_t __libunwind_Unwind_GetLanguageSpecificData(_Unwind_Context_Ptr
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
114 context);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
115 - ptrdiff_t __libunwind_Unwind_GetIP(_Unwind_Context_Ptr context);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
116 + size_t __libunwind_Unwind_GetIP(_Unwind_Context_Ptr context);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
117 ptrdiff_t __libunwind_Unwind_SetIP(_Unwind_Context_Ptr context,
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
118 ptrdiff_t new_value);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
119 ptrdiff_t __libunwind_Unwind_SetGR(_Unwind_Context_Ptr context, int index,
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
120 ptrdiff_t new_value);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
121 - ptrdiff_t __libunwind_Unwind_GetRegionStart(_Unwind_Context_Ptr context);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
122 + size_t __libunwind_Unwind_GetRegionStart(_Unwind_Context_Ptr context);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
123
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
124 alias __libunwind_Unwind_Resume _Unwind_Resume;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
125 alias __libunwind_Unwind_RaiseException _Unwind_RaiseException;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
126 @@ -94,27 +93,30 @@
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
127 alias __libunwind_Unwind_SetGR _Unwind_SetGR;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
128 alias __libunwind_Unwind_GetRegionStart _Unwind_GetRegionStart;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
129 }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
130 -else version(X86_UNWIND)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
131 +else version(X86_UNWIND)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
132 {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
133 void _Unwind_Resume(_Unwind_Exception*);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
134 _Unwind_Reason_Code _Unwind_RaiseException(_Unwind_Exception*);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
135 ptrdiff_t _Unwind_GetLanguageSpecificData(_Unwind_Context_Ptr context);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
136 - ptrdiff_t _Unwind_GetIP(_Unwind_Context_Ptr context);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
137 + size_t _Unwind_GetIP(_Unwind_Context_Ptr context);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
138 ptrdiff_t _Unwind_SetIP(_Unwind_Context_Ptr context, ptrdiff_t new_value);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
139 ptrdiff_t _Unwind_SetGR(_Unwind_Context_Ptr context, int index,
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
140 ptrdiff_t new_value);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
141 - ptrdiff_t _Unwind_GetRegionStart(_Unwind_Context_Ptr context);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
142 + size_t _Unwind_GetRegionStart(_Unwind_Context_Ptr context);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
143 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
144 + size_t _Unwind_GetTextRelBase(_Unwind_Context_Ptr);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
145 + size_t _Unwind_GetDataRelBase(_Unwind_Context_Ptr);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
146 }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
147 else
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
148 {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
149 // runtime calls these directly
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
150 void _Unwind_Resume(_Unwind_Exception*)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
151 {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
152 - console("_Unwind_Resume is not implemented on this platform.\n");
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
153 + printf("_Unwind_Resume is not implemented on this platform.\n");
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
154 }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
155 _Unwind_Reason_Code _Unwind_RaiseException(_Unwind_Exception*)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
156 {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
157 - console("_Unwind_RaiseException is not implemented on this platform.\n");
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
158 + printf("_Unwind_RaiseException is not implemented on this platform.\n");
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
159 return _Unwind_Reason_Code.FATAL_PHASE1_ERROR;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
160 }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
161 }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
162 @@ -122,14 +124,161 @@
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
163 }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
164
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
165 // error and exit
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
166 -extern(C) private void fatalerror(char[] format)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
167 +extern(C) private void fatalerror(char* format, ...)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
168 {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
169 - printf("Fatal error in EH code: %.*s\n", format.length, format.ptr);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
170 +// va_list args;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
171 +// va_start(args, format);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
172 + printf("Fatal error in EH code: ");
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
173 +// vprintf(format, args);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
174 + printf("\n");
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
175 abort();
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
176 }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
177
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
178
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
179 -// helpers for reading certain DWARF data
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
180 +// DWARF EH encoding enum
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
181 +// See e.g. http://refspecs.freestandards.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/dwarfext.html
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
182 +private enum : ubyte {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
183 + DW_EH_PE_omit = 0xff, // value is not present
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
184 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
185 + // value format
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
186 + DW_EH_PE_absptr = 0x00, // literal pointer
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
187 + DW_EH_PE_uleb128 = 0x01,
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
188 + DW_EH_PE_udata2 = 0x02, // unsigned 2-byte
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
189 + DW_EH_PE_udata4 = 0x03,
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
190 + DW_EH_PE_udata8 = 0x04,
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
191 + DW_EH_PE_sleb128 = 0x09,
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
192 + DW_EH_PE_sdata2 = 0x0a,
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
193 + DW_EH_PE_sdata4 = 0x0b,
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
194 + DW_EH_PE_sdata8 = 0x0c,
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
195 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
196 + // value meaning
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
197 + DW_EH_PE_pcrel = 0x10, // relative to program counter
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
198 + DW_EH_PE_textrel = 0x20, // relative to .text
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
199 + DW_EH_PE_datarel = 0x30, // relative to .got or .eh_frame_hdr
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
200 + DW_EH_PE_funcrel = 0x40, // relative to beginning of function
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
201 + DW_EH_PE_aligned = 0x50, // is an aligned void*
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
202 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
203 + // value is a pointer to the actual value
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
204 + // this is a mask on top of one of the above
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
205 + DW_EH_PE_indirect = 0x80
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
206 +}
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
207 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
208 +// Helpers for reading DWARF data
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
209 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
210 +// Given an encoding and a context, return the base to which the encoding is
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
211 +// relative
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
212 +private size_t base_of_encoded(_Unwind_Context_Ptr context, ubyte encoding)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
213 +{
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
214 + if (encoding == DW_EH_PE_omit)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
215 + return 0;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
216 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
217 + switch (encoding & 0x70) // ignore DW_EH_PE_indirect
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
218 + {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
219 + case DW_EH_PE_absptr, DW_EH_PE_pcrel, DW_EH_PE_aligned:
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
220 + return 0;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
221 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
222 + case DW_EH_PE_textrel: return _Unwind_GetTextRelBase(context);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
223 + case DW_EH_PE_datarel: return _Unwind_GetDataRelBase(context);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
224 + case DW_EH_PE_funcrel: return _Unwind_GetRegionStart(context);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
225 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
226 + default: fatalerror("Unrecognized base for DWARF value");
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
227 + }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
228 +}
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
229 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
230 +// Only defined for fixed-size encodings
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
231 +private size_t size_of_encoded(ubyte encoding)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
232 +{
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
233 + if (encoding == DW_EH_PE_omit)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
234 + return 0;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
235 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
236 + switch (encoding & 0x07) // ignore leb128
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
237 + {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
238 + case DW_EH_PE_absptr: return (void*).sizeof;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
239 + case DW_EH_PE_udata2: return 2;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
240 + case DW_EH_PE_udata4: return 4;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
241 + case DW_EH_PE_udata8: return 8;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
242 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
243 + default: fatalerror("Unrecognized fixed-size DWARF value encoding");
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
244 + }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
245 +}
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
246 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
247 +// Actual value readers below: read a value from the given ubyte* into the
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
248 +// output parameter and return the pointer incremented past the value.
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
249 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
250 +// Like read_encoded_with_base but gets the base from the given context
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
251 +private ubyte* read_encoded(_Unwind_Context_Ptr context, ubyte encoding, ubyte* p, out size_t val)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
252 +{
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
253 + return read_encoded_with_base(encoding, base_of_encoded(context, encoding), p, val);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
254 +}
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
255 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
256 +private ubyte* read_encoded_with_base(ubyte encoding, size_t base, ubyte* p, out size_t val)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
257 +{
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
258 + if (encoding == DW_EH_PE_aligned)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
259 + {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
260 + auto a = cast(size_t)p;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
261 + a = (a + (void*).sizeof - 1) & -(void*).sizeof;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
262 + val = *cast(size_t*)a;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
263 + return cast(ubyte*)(a + (void*).sizeof);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
264 + }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
265 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
266 + union U
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
267 + {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
268 + size_t ptr;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
269 + ushort udata2;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
270 + uint udata4;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
271 + ulong udata8;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
272 + short sdata2;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
273 + int sdata4;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
274 + long sdata8;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
275 + }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
276 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
277 + auto u = cast(U*)p;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
278 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
279 + size_t result;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
280 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
281 + switch (encoding & 0x0f)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
282 + {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
283 + case DW_EH_PE_absptr:
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
284 + result = u.ptr;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
285 + p += (void*).sizeof;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
286 + break;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
287 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
288 + case DW_EH_PE_uleb128:
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
289 + {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
290 + p = get_uleb128(p, result);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
291 + break;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
292 + }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
293 + case DW_EH_PE_sleb128:
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
294 + {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
295 + ptrdiff_t sleb128;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
296 + p = get_sleb128(p, sleb128);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
297 + result = cast(size_t)sleb128;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
298 + break;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
299 + }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
300 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
301 + case DW_EH_PE_udata2: result = cast(size_t)u.udata2; p += 2; break;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
302 + case DW_EH_PE_udata4: result = cast(size_t)u.udata4; p += 4; break;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
303 + case DW_EH_PE_udata8: result = cast(size_t)u.udata8; p += 8; break;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
304 + case DW_EH_PE_sdata2: result = cast(size_t)u.sdata2; p += 2; break;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
305 + case DW_EH_PE_sdata4: result = cast(size_t)u.sdata4; p += 4; break;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
306 + case DW_EH_PE_sdata8: result = cast(size_t)u.sdata8; p += 8; break;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
307 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
308 + default: fatalerror("Unrecognized DWARF value encoding format");
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
309 + }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
310 + if (result)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
311 + {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
312 + if ((encoding & 0x70) == DW_EH_PE_pcrel)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
313 + result += cast(size_t)u;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
314 + else
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
315 + result += base;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
316 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
317 + if (encoding & DW_EH_PE_indirect)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
318 + result = *cast(size_t*)result;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
319 + }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
320 + val = result;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
321 + return p;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
322 +}
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
323 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
324 private ubyte* get_uleb128(ubyte* addr, ref size_t res)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
325 {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
326 res = 0;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
327 @@ -137,7 +286,7 @@
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
328
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
329 // read as long as high bit is set
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
330 while(*addr & 0x80) {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
331 - res |= (*addr & 0x7f) << bitsize;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
332 + res |= (*addr & 0x7fU) << bitsize;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
333 bitsize += 7;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
334 addr += 1;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
335 if(bitsize >= size_t.sizeof*8)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
336 @@ -153,12 +302,12 @@
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
337
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
338 private ubyte* get_sleb128(ubyte* addr, ref ptrdiff_t res)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
339 {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
340 - res = 0;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
341 + size_t tres = 0;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
342 size_t bitsize = 0;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
343
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
344 // read as long as high bit is set
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
345 while(*addr & 0x80) {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
346 - res |= (*addr & 0x7f) << bitsize;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
347 + tres |= (*addr & 0x7fU) << bitsize;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
348 bitsize += 7;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
349 addr += 1;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
350 if(bitsize >= size_t.sizeof*8)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
351 @@ -167,12 +316,14 @@
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
352 // read last
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
353 if(bitsize != 0 && *addr >= 1 << size_t.sizeof*8 - bitsize)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
354 fatalerror("tried to read sleb128 that exceeded size of size_t");
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
355 - res |= (*addr) << bitsize;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
356 + tres |= (*addr) << bitsize;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
357
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
358 // take care of sign
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
359 - if(bitsize < size_t.sizeof*8 && ((*addr) & 0x40))
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
360 - res |= cast(ptrdiff_t)(-1) ^ ((1 << (bitsize+7)) - 1);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
361 + if(bitsize < size_t.sizeof*8 && (*addr & 0x40U) != 0)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
362 + tres |= cast(size_t)(-1) ^ ((1 << (bitsize+7)) - 1);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
363
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
364 + res = cast(ptrdiff_t)tres;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
365 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
366 return addr + 1;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
367 }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
368
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
369 @@ -190,8 +341,7 @@
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
370
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
371 // the 8-byte string identifying the type of exception
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
372 // the first 4 are for vendor, the second 4 for language
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
373 -//TODO: This may be the wrong way around
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
374 -const char[8] _d_exception_class = "LLDCD1\0\0";
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
375 +const char[8] _d_exception_class = "LDC_D_10";
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
376
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
377
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
378 //
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
379 @@ -201,118 +351,174 @@
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
380 version(X86_UNWIND)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
381 {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
382
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
383 +// Various stuff we need
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
384 +struct Region
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
385 +{
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
386 + ubyte* callsite_table;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
387 + ubyte* action_table;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
388 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
389 + // Note: classinfo_table points past the end of the table
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
390 + ubyte* classinfo_table;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
391 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
392 + size_t start;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
393 + size_t lpStart_base; // landing pad base
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
394 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
395 + ubyte ttypeEnc;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
396 + size_t ttype_base; // typeinfo base
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
397 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
398 + ubyte callSiteEnc;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
399 +}
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
400 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
401 // the personality routine gets called by the unwind handler and is responsible for
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
402 // reading the EH tables and deciding what to do
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
403 extern(C) _Unwind_Reason_Code _d_eh_personality(int ver, _Unwind_Action actions, ulong exception_class, _Unwind_Exception* exception_info, _Unwind_Context_Ptr context)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
404 {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
405 + debug(EH_personality) printf("Entering personality routine, context=%p\n", context);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
406 // check ver: the C++ Itanium ABI only allows ver == 1
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
407 if(ver != 1)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
408 + {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
409 + debug(EH_personality) printf("eh version mismatch\n");
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
410 return _Unwind_Reason_Code.FATAL_PHASE1_ERROR;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
411 + }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
412
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
413 // check exceptionClass
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
414 //TODO: Treat foreign exceptions with more respect
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
415 - if((cast(char*)&exception_class)[0..8] != _d_exception_class)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
416 + auto wanted_ec = *cast(ulong*)_d_exception_class.ptr;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
417 + if(exception_class != wanted_ec)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
418 + {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
419 + debug(EH_personality) printf("exception class mismatch %p vs %p\n", exception_class, wanted_ec);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
420 return _Unwind_Reason_Code.FATAL_PHASE1_ERROR;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
421 + }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
422
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
423 // find call site table, action table and classinfo table
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
424 // Note: callsite and action tables do not contain static-length
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
425 // data and will be parsed as needed
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
426 - // Note: classinfo_table points past the end of the table
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
427 - ubyte* callsite_table;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
428 - ubyte* action_table;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
429 - ClassInfo* classinfo_table;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
430 - _d_getLanguageSpecificTables(context, callsite_table, action_table, classinfo_table);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
431 - if (!callsite_table)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
432 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
433 + Region region;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
434 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
435 + _d_getLanguageSpecificTables(context, region);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
436 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
437 + // workaround. this should not happen
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
438 + if (!region.callsite_table)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
439 + {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
440 + debug(EH_personality) printf("callsite_table is null\n");
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
441 return _Unwind_Reason_Code.CONTINUE_UNWIND;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
442 + }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
443
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
444 + debug(EH_personality) printf("yay, checking\n");
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
445 + debug(EH_personality) printf("region.start = %p\n", region.start);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
446 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
447 /*
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
448 find landing pad and action table index belonging to ip by walking
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
449 the callsite_table
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
450 */
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
451 - ubyte* callsite_walker = callsite_table;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
452 + ubyte* callsite_walker = region.callsite_table;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
453 + debug(EH_personality) printf("callsite table at: %p\n", region.callsite_table);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
454 + debug(EH_personality) printf("action table at: %p\n", region.action_table);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
455 + debug(EH_personality) printf("rtti table at %p\n", region.classinfo_table);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
456
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
457 // get the instruction pointer
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
458 // will be used to find the right entry in the callsite_table
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
459 // -1 because it will point past the last instruction
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
460 - ptrdiff_t ip = _Unwind_GetIP(context) - 1;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
461 + debug(EH_personality) printf("check1\n");
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
462 + size_t ip = _Unwind_GetIP(context) - 1;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
463 + debug(EH_personality) printf("check2\n");
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
464
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
465 - // address block_start is relative to
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
466 - ptrdiff_t region_start = _Unwind_GetRegionStart(context);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
467 -
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
468 // table entries
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
469 - uint block_start_offset, block_size;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
470 - ptrdiff_t landing_pad;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
471 + size_t landing_pad;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
472 size_t action_offset;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
473
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
474 while(true) {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
475 // if we've gone through the list and found nothing...
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
476 - if(callsite_walker >= action_table)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
477 + if(callsite_walker >= region.action_table)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
478 + {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
479 + debug(EH_personality) printf("found nothing\n");
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
480 return _Unwind_Reason_Code.CONTINUE_UNWIND;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
481 + }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
482
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
483 - block_start_offset = *cast(uint*)callsite_walker;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
484 - block_size = *(cast(uint*)callsite_walker + 1);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
485 - landing_pad = *(cast(uint*)callsite_walker + 2);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
486 - if(landing_pad)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
487 - landing_pad += region_start;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
488 - callsite_walker = get_uleb128(callsite_walker + 3*uint.sizeof, action_offset);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
489 + size_t block_start, block_size;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
490
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
491 - debug(EH_personality_verbose) printf("ip=%llx %d %d %llx\n", ip, block_start_offset, block_size, landing_pad);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
492 + callsite_walker = read_encoded(null, region.callSiteEnc, callsite_walker, block_start);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
493 + callsite_walker = read_encoded(null, region.callSiteEnc, callsite_walker, block_size);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
494 + callsite_walker = read_encoded(null, region.callSiteEnc, callsite_walker, landing_pad);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
495 + callsite_walker = get_uleb128(callsite_walker, action_offset);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
496
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
497 + debug(EH_personality) printf("*block start offset = %p\n", block_start);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
498 + debug(EH_personality) printf(" block size = %p\n", block_size);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
499 + debug(EH_personality) printf(" landing pad = %p\n", landing_pad);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
500 + debug(EH_personality) printf(" ip=%p %p %p %p\n", ip, block_start, block_size, landing_pad);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
501 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
502 // since the list is sorted, as soon as we're past the ip
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
503 // there's no handler to be found
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
504 - if(ip < region_start + block_start_offset)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
505 + if(ip < region.start + block_start)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
506 + {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
507 + debug(EH_personality) printf("found nothing2\n");
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
508 return _Unwind_Reason_Code.CONTINUE_UNWIND;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
509 + }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
510
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
511 + if(landing_pad)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
512 + landing_pad += region.lpStart_base;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
513 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
514 // if we've found our block, exit
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
515 - if(ip < region_start + block_start_offset + block_size)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
516 + if(ip < region.start + block_start + block_size)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
517 break;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
518 }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
519
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
520 - debug(EH_personality) printf("Found correct landing pad and actionOffset %d\n", action_offset);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
521 + debug(EH_personality) printf("Found correct landing pad %p and actionOffset %p\n", landing_pad, action_offset);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
522
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
523 // now we need the exception's classinfo to find a handler
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
524 // the exception_info is actually a member of a larger _d_exception struct
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
525 // the runtime allocated. get that now
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
526 - _d_exception* exception_struct = cast(_d_exception*)(cast(ubyte*)exception_info - _d_exception.unwind_info.offsetof);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
527 + _d_exception* exception_struct = cast(_d_exception*)(cast(ubyte*)exception_info - size_t.sizeof); //_d_exception.unwind_info.offsetof);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
528
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
529 // if there's no action offset and no landing pad, continue unwinding
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
530 if(!action_offset && !landing_pad)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
531 return _Unwind_Reason_Code.CONTINUE_UNWIND;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
532
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
533 // if there's no action offset but a landing pad, this is a cleanup handler
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
534 - else if(!action_offset && landing_pad)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
535 - return _d_eh_install_finally_context(actions, landing_pad, exception_struct, context);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
536 + else if(!action_offset && landing_pad != 0)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
537 + {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
538 + debug(EH_personality) printf("installing finally context\n");
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
539 + return _d_eh_install_finally_context(actions, cast(ptrdiff_t)landing_pad, exception_struct, context);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
540 + }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
541
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
542 /*
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
543 walk action table chain, comparing classinfos using _d_isbaseof
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
544 */
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
545 - ubyte* action_walker = action_table + action_offset - 1;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
546 + ubyte* action_walker = region.action_table + action_offset - 1;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
547
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
548 - ptrdiff_t ti_offset, next_action_offset;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
549 while(true) {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
550 + ptrdiff_t ti_offset, next_action_offset;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
551 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
552 action_walker = get_sleb128(action_walker, ti_offset);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
553 // it is intentional that we not modify action_walker here
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
554 // next_action_offset is from current action_walker position
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
555 get_sleb128(action_walker, next_action_offset);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
556
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
557 // negative are 'filters' which we don't use
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
558 - if(!(ti_offset >= 0))
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
559 + if(ti_offset < 0)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
560 fatalerror("Filter actions are unsupported");
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
561
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
562 // zero means cleanup, which we require to be the last action
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
563 if(ti_offset == 0) {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
564 - if(!(next_action_offset == 0))
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
565 + if(next_action_offset != 0)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
566 fatalerror("Cleanup action must be last in chain");
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
567 - return _d_eh_install_finally_context(actions, landing_pad, exception_struct, context);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
568 + return _d_eh_install_finally_context(actions, cast(ptrdiff_t)landing_pad, exception_struct, context);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
569 }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
570
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
571 // get classinfo for action and check if the one in the
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
572 // exception structure is a base
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
573 - ClassInfo catch_ci = *(classinfo_table - ti_offset);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
574 - debug(EH_personality) printf("Comparing catch %s to exception %s\n", catch_ci.name.ptr, exception_struct.exception_object.classinfo.name.ptr);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
575 - if(_d_isbaseof(exception_struct.exception_object.classinfo, catch_ci))
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
576 - return _d_eh_install_catch_context(actions, ti_offset, landing_pad, exception_struct, context);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
577 + size_t typeinfo;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
578 + auto filter = cast(size_t)ti_offset * size_of_encoded(region.ttypeEnc);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
579 + read_encoded_with_base(region.ttypeEnc, region.ttype_base, region.classinfo_table - filter, typeinfo);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
580
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
581 + debug(EH_personality)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
582 + printf("classinfo at %zx (enc %zx (size %zx) base %zx ptr %zx)\n", typeinfo, region.ttypeEnc, size_of_encoded(region.ttypeEnc), region.ttype_base, region.classinfo_table - filter);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
583 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
584 + auto catch_ci = *cast(ClassInfo*)&typeinfo;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
585 + if(_d_dynamic_cast(exception_struct.exception_object, catch_ci) !is null)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
586 + return _d_eh_install_catch_context(actions, ti_offset, cast(ptrdiff_t)landing_pad, exception_struct, context);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
587 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
588 // we've walked through all actions and found nothing...
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
589 if(next_action_offset == 0)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
590 return _Unwind_Reason_Code.CONTINUE_UNWIND;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
591 @@ -356,6 +562,7 @@
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
592 }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
593
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
594 fatalerror("reached unreachable");
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
595 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
596 return _Unwind_Reason_Code.FATAL_PHASE2_ERROR;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
597 }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
598
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
599 @@ -370,56 +577,78 @@
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
600 _Unwind_SetGR(context, eh_exception_regno, cast(ptrdiff_t)exception_struct);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
601 _Unwind_SetGR(context, eh_selector_regno, 0);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
602 _Unwind_SetIP(context, landing_pad);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
603 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
604 return _Unwind_Reason_Code.INSTALL_CONTEXT;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
605 }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
606
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
607 -private void _d_getLanguageSpecificTables(_Unwind_Context_Ptr context, ref ubyte* callsite, ref ubyte* action, ref ClassInfo* ci)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
608 +private void _d_getLanguageSpecificTables(_Unwind_Context_Ptr context, out Region region)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
609 {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
610 - ubyte* data = cast(ubyte*)_Unwind_GetLanguageSpecificData(context);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
611 + auto data = cast(ubyte*)_Unwind_GetLanguageSpecificData(context);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
612 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
613 + // workaround. this should not be 0...
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
614 if (!data)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
615 {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
616 - callsite = null;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
617 - action = null;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
618 - ci = null;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
619 - return;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
620 + //printf("language specific data is null\n");
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
621 + return;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
622 }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
623
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
624 - //TODO: Do proper DWARF reading here
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
625 - if(*data++ != 0xff)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
626 - fatalerror("DWARF header has unexpected format 1");
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
627 + region.start = _Unwind_GetRegionStart(context);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
628
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
629 - if(*data++ != 0x00)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
630 - fatalerror("DWARF header has unexpected format 2");
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
631 - size_t cioffset;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
632 - data = get_uleb128(data, cioffset);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
633 - ci = cast(ClassInfo*)(data + cioffset);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
634 + // Read the C++-style LSDA: this is implementation-defined by GCC but LLVM
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
635 + // outputs the same kind of table
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
636
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
637 - if(*data++ != 0x03)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
638 - fatalerror("DWARF header has unexpected format 3");
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
639 - size_t callsitelength;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
640 - data = get_uleb128(data, callsitelength);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
641 - action = data + callsitelength;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
642 + // Get @LPStart: landing pad offsets are relative to it
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
643 + auto lpStartEnc = *data++;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
644 + if (lpStartEnc == DW_EH_PE_omit)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
645 + region.lpStart_base = region.start;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
646 + else
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
647 + data = read_encoded(context, lpStartEnc, data, region.lpStart_base);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
648
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
649 - callsite = data;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
650 + // Get @TType: the offset to the handler and typeinfo
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
651 + region.ttypeEnc = *data++;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
652 + if (region.ttypeEnc == DW_EH_PE_omit)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
653 + // Not sure about this one...
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
654 + fatalerror("@TType must not be omitted from DWARF header");
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
655 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
656 + size_t ciOffset;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
657 + data = get_uleb128(data, ciOffset);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
658 + region.classinfo_table = data + ciOffset;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
659 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
660 + region.ttype_base = base_of_encoded(context, region.ttypeEnc);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
661 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
662 + // Get encoding and length of the call site table, which precedes the action
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
663 + // table.
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
664 + region.callSiteEnc = *data++;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
665 + if (region.callSiteEnc == DW_EH_PE_omit)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
666 + fatalerror("Call site table encoding must not be omitted from DWARF header");
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
667 +
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
668 + size_t callSiteLength;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
669 + region.callsite_table = get_uleb128(data, callSiteLength);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
670 + region.action_table = region.callsite_table + callSiteLength;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
671 }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
672
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
673 } // end of x86 Linux specific implementation
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
674
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
675 -
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
676 -extern(C) void _d_throw_exception(Object e)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
677 +// called to throw object
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
678 +extern(C)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
679 +void _d_throw_exception(Object e)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
680 {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
681 + //printf("throwing %p, rtti = %p\n", e, **cast(ClassRTTI***)e);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
682 if (e !is null)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
683 {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
684 _d_exception* exc_struct = new _d_exception;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
685 exc_struct.unwind_info.exception_class = *cast(ulong*)_d_exception_class.ptr;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
686 exc_struct.exception_object = e;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
687 _Unwind_Reason_Code ret = _Unwind_RaiseException(&exc_struct.unwind_info);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
688 - console("_Unwind_RaiseException failed with reason code: ")(ret)("\n");
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
689 + printf("Error: returned %d from raise exception.\n", ret);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
690 + //console("_Unwind_RaiseException failed with reason code: ")(ret)("\n");
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
691 }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
692 abort();
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
693 }
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
694
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
695 -extern(C) void _d_eh_resume_unwind(_d_exception* exception_struct)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
696 +// called to resume unwinding
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
697 +extern(C)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
698 +void _d_eh_resume_unwind(void* exception_struct)
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
699 {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
700 - _Unwind_Resume(&exception_struct.unwind_info);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
701 + _Unwind_Resume(&(cast(_d_exception*)exception_struct).unwind_info);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1633
diff changeset
702 }