Skip to content
This repository was archived by the owner on Jun 20, 2019. It is now read-only.

Commit b4581b0

Browse files
committed
Replace abort() in deh runtime with builtin trap()
1 parent 02c3456 commit b4581b0

File tree

3 files changed

+64
-68
lines changed

3 files changed

+64
-68
lines changed

libphobos/libdruntime/gcc/deh.d

+2-5
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ import gcc.unwind.pe;
2424
import gcc.builtins;
2525
import gcc.config;
2626

27-
import core.memory;
28-
import core.stdc.stdlib;
29-
3027
extern(C)
3128
{
3229
int _d_isbaseof(ClassInfo, ClassInfo);
@@ -125,7 +122,7 @@ private void
125122
__gdc_terminate()
126123
{
127124
// Replaces std::terminate and terminating with a specific handler
128-
abort();
125+
__builtin_trap();
129126
}
130127

131128
// This is called by the unwinder.
@@ -408,7 +405,7 @@ else
408405
return _URC_CONTINUE_UNWIND;
409406

410407
default:
411-
abort();
408+
__builtin_trap();
412409
}
413410
actions |= state & _US_FORCE_UNWIND;
414411

libphobos/libdruntime/gcc/unwind/generic.d

+42-43
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,21 @@
2222
module gcc.unwind.generic;
2323

2424
private import gcc.builtins;
25-
private import core.stdc.stdlib; // for abort
2625

2726
/* This is derived from the C++ ABI for IA-64. Where we diverge
2827
for cross-architecture compatibility are noted with "@@@". */
2928

30-
extern (C):
29+
extern(C):
3130

3231
/* Level 1: Base ABI */
3332

3433
/* @@@ The IA-64 ABI uses uint64 throughout. Most places this is
3534
inefficient for 32-bit and smaller machines. */
3635
alias _Unwind_Word = __builtin_unwind_uint;
3736
alias _Unwind_Sword = __builtin_unwind_int;
38-
version (IA64)
37+
version(IA64)
3938
{
40-
version (HPUX)
39+
version(HPUX)
4140
alias _Unwind_Ptr = __builtin_machine_uint;
4241
else
4342
alias _Unwind_Ptr = __builtin_pointer_uint;
@@ -110,55 +109,55 @@ enum
110109
struct _Unwind_Context;
111110

112111
/* Raise an exception, passing along the given exception object. */
113-
_Unwind_Reason_Code _Unwind_RaiseException (_Unwind_Exception *);
112+
_Unwind_Reason_Code _Unwind_RaiseException(_Unwind_Exception *);
114113

115114
/* Raise an exception for forced unwinding. */
116115

117116
extern(C) alias _Unwind_Stop_Fn
118-
= _Unwind_Reason_Code function (int, _Unwind_Action,
119-
_Unwind_Exception_Class,
120-
_Unwind_Exception *,
121-
_Unwind_Context *, void *);
117+
= _Unwind_Reason_Code function(int, _Unwind_Action,
118+
_Unwind_Exception_Class,
119+
_Unwind_Exception *,
120+
_Unwind_Context *, void *);
122121

123-
_Unwind_Reason_Code _Unwind_ForcedUnwind (_Unwind_Exception *, _Unwind_Stop_Fn, void *);
122+
_Unwind_Reason_Code _Unwind_ForcedUnwind(_Unwind_Exception *, _Unwind_Stop_Fn, void *);
124123

125124
/* Helper to invoke the exception_cleanup routine. */
126-
void _Unwind_DeleteException (_Unwind_Exception *);
125+
void _Unwind_DeleteException(_Unwind_Exception *);
127126

128127
/* Resume propagation of an existing exception. This is used after
129128
e.g. executing cleanup code, and not to implement rethrowing. */
130-
void _Unwind_Resume (_Unwind_Exception *);
129+
void _Unwind_Resume(_Unwind_Exception *);
131130

132131
/* @@@ Resume propagation of an FORCE_UNWIND exception, or to rethrow
133132
a normal exception that was handled. */
134-
_Unwind_Reason_Code _Unwind_Resume_or_Rethrow (_Unwind_Exception *);
133+
_Unwind_Reason_Code _Unwind_Resume_or_Rethrow(_Unwind_Exception *);
135134

136135
/* @@@ Use unwind data to perform a stack backtrace. The trace callback
137136
is called for every stack frame in the call chain, but no cleanup
138137
actions are performed. */
139138
extern(C) alias _Unwind_Trace_Fn
140-
= _Unwind_Reason_Code function (_Unwind_Context *, void *);
139+
= _Unwind_Reason_Code function(_Unwind_Context *, void *);
141140

142-
_Unwind_Reason_Code _Unwind_Backtrace (_Unwind_Trace_Fn, void *);
141+
_Unwind_Reason_Code _Unwind_Backtrace(_Unwind_Trace_Fn, void *);
143142

144143
/* These functions are used for communicating information about the unwind
145144
context (i.e. the unwind descriptors and the user register state) between
146145
the unwind library and the personality routine and landing pad. Only
147146
selected registers may be manipulated. */
148147

149-
_Unwind_Word _Unwind_GetGR (_Unwind_Context *, int);
150-
void _Unwind_SetGR (_Unwind_Context *, int, _Unwind_Word);
148+
_Unwind_Word _Unwind_GetGR(_Unwind_Context *, int);
149+
void _Unwind_SetGR(_Unwind_Context *, int, _Unwind_Word);
151150

152-
_Unwind_Ptr _Unwind_GetIP (_Unwind_Context *);
153-
_Unwind_Ptr _Unwind_GetIPInfo (_Unwind_Context *, int *);
154-
void _Unwind_SetIP (_Unwind_Context *, _Unwind_Ptr);
151+
_Unwind_Ptr _Unwind_GetIP(_Unwind_Context *);
152+
_Unwind_Ptr _Unwind_GetIPInfo(_Unwind_Context *, int *);
153+
void _Unwind_SetIP(_Unwind_Context *, _Unwind_Ptr);
155154

156155
/* @@@ Retrieve the CFA of the given context. */
157-
_Unwind_Word _Unwind_GetCFA (_Unwind_Context *);
156+
_Unwind_Word _Unwind_GetCFA(_Unwind_Context *);
158157

159-
void *_Unwind_GetLanguageSpecificData (_Unwind_Context *);
158+
void *_Unwind_GetLanguageSpecificData(_Unwind_Context *);
160159

161-
_Unwind_Ptr _Unwind_GetRegionStart (_Unwind_Context *);
160+
_Unwind_Ptr _Unwind_GetRegionStart(_Unwind_Context *);
162161

163162

164163
/* The personality routine is the function in the C++ (or other language)
@@ -176,55 +175,55 @@ _Unwind_Ptr _Unwind_GetRegionStart (_Unwind_Context *);
176175
lack of code to handle the different data format. */
177176

178177
extern(C) alias _Unwind_Personality_Fn
179-
= _Unwind_Reason_Code function (int, _Unwind_Action,
180-
_Unwind_Exception_Class,
181-
_Unwind_Exception *,
182-
_Unwind_Context *);
178+
= _Unwind_Reason_Code function(int, _Unwind_Action,
179+
_Unwind_Exception_Class,
180+
_Unwind_Exception *,
181+
_Unwind_Context *);
183182

184183
/* @@@ The following alternate entry points are for setjmp/longjmp
185184
based unwinding. */
186185

187186
struct SjLj_Function_Context;
188-
extern void _Unwind_SjLj_Register (SjLj_Function_Context *);
189-
extern void _Unwind_SjLj_Unregister (SjLj_Function_Context *);
187+
extern void _Unwind_SjLj_Register(SjLj_Function_Context *);
188+
extern void _Unwind_SjLj_Unregister(SjLj_Function_Context *);
190189

191-
_Unwind_Reason_Code _Unwind_SjLj_RaiseException (_Unwind_Exception *);
192-
_Unwind_Reason_Code _Unwind_SjLj_ForcedUnwind (_Unwind_Exception *, _Unwind_Stop_Fn, void *);
193-
void _Unwind_SjLj_Resume (_Unwind_Exception *);
194-
_Unwind_Reason_Code _Unwind_SjLj_Resume_or_Rethrow (_Unwind_Exception *);
190+
_Unwind_Reason_Code _Unwind_SjLj_RaiseException(_Unwind_Exception *);
191+
_Unwind_Reason_Code _Unwind_SjLj_ForcedUnwind(_Unwind_Exception *, _Unwind_Stop_Fn, void *);
192+
void _Unwind_SjLj_Resume(_Unwind_Exception *);
193+
_Unwind_Reason_Code _Unwind_SjLj_Resume_or_Rethrow(_Unwind_Exception *);
195194

196195
/* @@@ The following provide access to the base addresses for text
197196
and data-relative addressing in the LDSA. In order to stay link
198197
compatible with the standard ABI for IA-64, we inline these. */
199198

200-
version (IA64)
199+
version(IA64)
201200
{
202201
_Unwind_Ptr
203-
_Unwind_GetDataRelBase (_Unwind_Context *_C)
202+
_Unwind_GetDataRelBase(_Unwind_Context *_C)
204203
{
205204
/* The GP is stored in R1. */
206-
return _Unwind_GetGR (_C, 1);
205+
return _Unwind_GetGR(_C, 1);
207206
}
208207

209208
_Unwind_Ptr
210-
_Unwind_GetTextRelBase (_Unwind_Context *)
209+
_Unwind_GetTextRelBase(_Unwind_Context *)
211210
{
212-
abort ();
211+
__builtin_trap();
213212
return 0;
214213
}
215214

216215
/* @@@ Retrieve the Backing Store Pointer of the given context. */
217-
_Unwind_Word _Unwind_GetBSP (_Unwind_Context *);
216+
_Unwind_Word _Unwind_GetBSP(_Unwind_Context *);
218217
}
219218
else
220219
{
221-
_Unwind_Ptr _Unwind_GetDataRelBase (_Unwind_Context *);
222-
_Unwind_Ptr _Unwind_GetTextRelBase (_Unwind_Context *);
220+
_Unwind_Ptr _Unwind_GetDataRelBase(_Unwind_Context *);
221+
_Unwind_Ptr _Unwind_GetTextRelBase(_Unwind_Context *);
223222
}
224223

225224
/* @@@ Given an address, return the entry point of the function that
226225
contains it. */
227-
extern void * _Unwind_FindEnclosingFunction (void *pc);
226+
extern void * _Unwind_FindEnclosingFunction(void *pc);
228227

229228

230229
/* leb128 type numbers have a potentially unlimited size.
@@ -247,6 +246,6 @@ else static if (long.sizeof >= (void*).sizeof)
247246
}
248247
else
249248
{
250-
static assert (0, "What type shall we use for _sleb128_t?");
249+
static assert(0, "What type shall we use for _sleb128_t?");
251250
}
252251

libphobos/libdruntime/gcc/unwind/pe.d

+20-20
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
module gcc.unwind.pe;
2222

2323
import gcc.unwind;
24-
private import core.stdc.stdlib : abort;
24+
import gcc.builtins;
2525

2626
/* Pointer encodings, from dwarf2.h. */
2727
enum
@@ -48,13 +48,13 @@ enum
4848
DW_EH_PE_indirect = 0x80
4949
}
5050

51-
version (NO_SIZE_OF_ENCODED_VALUE) {}
51+
version(NO_SIZE_OF_ENCODED_VALUE) {}
5252
else
5353
{
5454
/* Given an encoding, return the number of bytes the format occupies.
5555
This is only defined for fixed-size encodings, and so does not
5656
include leb128. */
57-
uint size_of_encoded_value (ubyte encoding)
57+
uint size_of_encoded_value(ubyte encoding)
5858
{
5959
if (encoding == DW_EH_PE_omit)
6060
return 0;
@@ -74,7 +74,7 @@ else
7474
}
7575
}
7676

77-
version (NO_BASE_OF_ENCODED_VALUE) {}
77+
version(NO_BASE_OF_ENCODED_VALUE) {}
7878
else
7979
{
8080
/* Given an encoding and an _Unwind_Context, return the base to which
@@ -83,7 +83,7 @@ else
8383
not available. */
8484

8585
_Unwind_Ptr
86-
base_of_encoded_value (ubyte encoding, _Unwind_Context *context)
86+
base_of_encoded_value(ubyte encoding, _Unwind_Context *context)
8787
{
8888
if (encoding == DW_EH_PE_omit)
8989
return cast(_Unwind_Ptr) 0;
@@ -96,13 +96,13 @@ else
9696
return cast(_Unwind_Ptr) 0;
9797

9898
case DW_EH_PE_textrel:
99-
return _Unwind_GetTextRelBase (context);
99+
return _Unwind_GetTextRelBase(context);
100100
case DW_EH_PE_datarel:
101-
return _Unwind_GetDataRelBase (context);
101+
return _Unwind_GetDataRelBase(context);
102102
case DW_EH_PE_funcrel:
103-
return _Unwind_GetRegionStart (context);
103+
return _Unwind_GetRegionStart(context);
104104
}
105-
assert (0);
105+
assert(0);
106106
}
107107
}
108108

@@ -112,7 +112,7 @@ else
112112
pointers should not be leb128 encoded on that target. */
113113

114114
ubyte *
115-
read_uleb128 (ubyte *p, _uleb128_t *val)
115+
read_uleb128(ubyte *p, _uleb128_t *val)
116116
{
117117
uint shift = 0;
118118
ubyte a_byte;
@@ -134,7 +134,7 @@ read_uleb128 (ubyte *p, _uleb128_t *val)
134134
/* Similar, but read a signed leb128 value. */
135135

136136
ubyte *
137-
read_sleb128 (ubyte *p, _sleb128_t *val)
137+
read_sleb128(ubyte *p, _sleb128_t *val)
138138
{
139139
uint shift = 0;
140140
ubyte a_byte;
@@ -162,8 +162,8 @@ read_sleb128 (ubyte *p, _sleb128_t *val)
162162
by base_of_encoded_value for this encoding in the appropriate context. */
163163

164164
ubyte *
165-
read_encoded_value_with_base (ubyte encoding, _Unwind_Ptr base,
166-
ubyte *p, _Unwind_Ptr *val)
165+
read_encoded_value_with_base(ubyte encoding, _Unwind_Ptr base,
166+
ubyte *p, _Unwind_Ptr *val)
167167
{
168168
union unaligned
169169
{
@@ -199,15 +199,15 @@ read_encoded_value_with_base (ubyte encoding, _Unwind_Ptr base,
199199
case DW_EH_PE_uleb128:
200200
{
201201
_uleb128_t tmp;
202-
p = read_uleb128 (p, &tmp);
202+
p = read_uleb128(p, &tmp);
203203
result = cast(_Unwind_Internal_Ptr) tmp;
204204
}
205205
break;
206206

207207
case DW_EH_PE_sleb128:
208208
{
209209
_sleb128_t tmp;
210-
p = read_sleb128 (p, &tmp);
210+
p = read_sleb128(p, &tmp);
211211
result = cast(_Unwind_Internal_Ptr) tmp;
212212
}
213213
break;
@@ -239,7 +239,7 @@ read_encoded_value_with_base (ubyte encoding, _Unwind_Ptr base,
239239
break;
240240

241241
default:
242-
abort ();
242+
__builtin_trap();
243243
}
244244

245245
if (result != 0)
@@ -262,11 +262,11 @@ else
262262
rather than providing it directly. */
263263

264264
ubyte *
265-
read_encoded_value (_Unwind_Context *context, ubyte encoding,
266-
ubyte *p, _Unwind_Ptr *val)
265+
read_encoded_value(_Unwind_Context *context, ubyte encoding,
266+
ubyte *p, _Unwind_Ptr *val)
267267
{
268-
return read_encoded_value_with_base (encoding,
269-
base_of_encoded_value (encoding, context),
268+
return read_encoded_value_with_base(encoding,
269+
base_of_encoded_value(encoding, context),
270270
p, val);
271271
}
272272
}

0 commit comments

Comments
 (0)