ObjFW  Check-in [879e69dd3d]

Overview
Comment:Make usage of several _Unwind_* functions optional

This removes the special casing for Itanium and makes compilation on
OpenBSD/SPARC64 work with clang.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 879e69dd3df06ea24264ff973d3f6607e102d2abdfe60a894621bd57fa0721ca
User & Date: js on 2018-04-08 18:18:16
Other Links: manifest | tags
Context
2018-04-08
18:56
configure: Also check for _Unwind_* in libc++ check-in: c16de18443 user: js tags: trunk
18:18
Make usage of several _Unwind_* functions optional check-in: 879e69dd3d user: js tags: trunk
16:09
Use -integrated-as on OpenBSD/SPARC64 with Clang check-in: 3a831de131 user: js tags: trunk
Changes

Modified configure.ac from [2541cd5bb5] to [e4bc8d17f8].

467
468
469
470
471
472
473


474
475
476
477
478
479
480
481
482
483
484
485
486


487
488
489
490
491
492
493
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497







+
+













+
+







			esac

			AC_MSG_RESULT($exception_type)
		], [
			AC_MSG_RESULT(exceptions unavailable!)
			AC_MSG_ERROR([Exceptions not accepted by compiler!])
		])

		AC_CHECK_FUNCS(_Unwind_GetDataRelBase _Unwind_GetTextRelBase)
		;;
	"Apple runtime")
		AC_DEFINE(OF_APPLE_RUNTIME, 1,
			[Whether we use the Apple ObjC runtime])

		AC_CHECK_LIB(objc, objc_msgSend, [
			AC_SUBST(RUNTIME_LIBS, "-lobjc")
			AC_SUBST(RUNTIME_FRAMEWORK_LIBS, "-lobjc")
		], [
			AC_MSG_ERROR([libobjc not found!])
		])
		;;
esac

AC_CHECK_FUNCS(_Unwind_Backtrace)

AC_CHECK_FUNC(objc_constructInstance, [], [
	AC_SUBST(INSTANCE_M, "instance.m")
])

AC_CHECK_FUNC(objc_autoreleasePoolPush, [], [
	AC_SUBST(AUTORELEASE_M, "autorelease.m")

Modified src/exceptions/OFException.m from [4b731d03ec] to [7a9ee871b5].

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

80
81

82

83
84

85
86
87
88
89
90
91
92
93
94
39
40
41
42
43
44
45


















46
47
48
49

50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

65
66

67
68
69

70
71
72
73
74
75
76







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




-











+


+
-
+

-
+


-







# import "threading.h"
#endif

#if defined(OF_WINDOWS) && defined(OF_HAVE_SOCKETS)
# include <winerror.h>
#endif

/*
 * Define HAVE_DWARF_EXCEPTIONS if OBJC_ZEROCOST_EXCEPTIONS is defined, but
 * don't do so on iOS, as it is defined there even if SjLj exceptions are used.
 */
#ifndef HAVE_DWARF_EXCEPTIONS
# if defined(OBJC_ZEROCOST_EXCEPTIONS) && !defined(OF_IOS)
#  define HAVE_DWARF_EXCEPTIONS
# endif
#endif

/*
 * Define HAVE_DWARF_EXCEPTIONS if HAVE_SEH_EXCEPTIONS is defined, as SEH
 * exceptions are implemented as a wrapper around DWARF exceptions.
 */
#ifdef HAVE_SEH_EXCEPTIONS
# define HAVE_DWARF_EXCEPTIONS
#endif

#if defined(OF_ARM) && !defined(__ARM_DWARF_EH__)
# define HAVE_ARM_EHABI_EXCEPTIONS
#endif

#ifdef HAVE_DWARF_EXCEPTIONS
struct _Unwind_Context;
typedef enum {
	_URC_OK		  = 0,
	_URC_END_OF_STACK = 5
}_Unwind_Reason_Code;

struct backtrace_ctx {
	void **backtrace;
	uint8_t i;
};

#ifdef HAVE__UNWIND_BACKTRACE
extern _Unwind_Reason_Code _Unwind_Backtrace(
    _Unwind_Reason_Code (*)(struct _Unwind_Context *, void *), void *);
#endif
# ifndef HAVE_ARM_EHABI_EXCEPTIONS
#ifndef HAVE_ARM_EHABI_EXCEPTIONS
extern uintptr_t _Unwind_GetIP(struct _Unwind_Context *);
# else
#else
extern int _Unwind_VRS_Get(struct _Unwind_Context *, int, uint32_t, int,
    void *);
# endif
#endif

#if !defined(HAVE_STRERROR_R) && defined(OF_HAVE_THREADS)
static of_mutex_t mutex;

OF_CONSTRUCTOR()
{
221
222
223
224
225
226
227
228

229
230
231
232
233
234
235
203
204
205
206
207
208
209

210
211
212
213
214
215
216
217







-
+







	}
# endif
#endif

	return ret;
}

#ifdef HAVE_DWARF_EXCEPTIONS
#ifdef HAVE__UNWIND_BACKTRACE
static _Unwind_Reason_Code
backtrace_callback(struct _Unwind_Context *ctx, void *data)
{
	struct backtrace_ctx *bt = data;

	if (bt->i < OF_BACKTRACE_SIZE) {
# ifndef HAVE_ARM_EHABI_EXCEPTIONS
249
250
251
252
253
254
255
256

257
258
259
260
261
262
263
231
232
233
234
235
236
237

238
239
240
241
242
243
244
245







-
+








@implementation OFException
+ (instancetype)exception
{
	return [[[self alloc] init] autorelease];
}

#ifdef HAVE_DWARF_EXCEPTIONS
#ifdef HAVE__UNWIND_BACKTRACE
- (instancetype)init
{
	struct backtrace_ctx ctx;

	self = [super init];

	ctx.backtrace = _backtrace;
272
273
274
275
276
277
278
279

280
281
282
283
284
285
286
254
255
256
257
258
259
260

261
262
263
264
265
266
267
268







-
+







{
	return [OFString stringWithFormat:
	    @"An exception of type %@ occurred!", [self class]];
}

- (OFArray OF_GENERIC(OFString *) *)backtrace
{
#ifdef HAVE_DWARF_EXCEPTIONS
#ifdef HAVE__UNWIND_BACKTRACE
	OFMutableArray OF_GENERIC(OFString *) *backtrace =
	    [OFMutableArray array];
	void *pool = objc_autoreleasePoolPush();

	for (uint8_t i = 0;
	    i < OF_BACKTRACE_SIZE && _backtrace[i] != NULL; i++) {
# ifdef HAVE_DLADDR

Modified src/runtime/exception.m from [2f76cd89bc] to [dc5760d5ce].

167
168
169
170
171
172
173
174

175


176
177
178
179
180
181
182
183
184

185
186
187
188
189
190
191
167
168
169
170
171
172
173

174
175
176
177
178


179
180
181
182
183
184
185
186
187
188
189
190
191
192







-
+

+
+

-
-






+







	const uint8_t *callsites, *actiontable;
};

extern _Unwind_Reason_Code _Unwind_RaiseException(struct _Unwind_Exception *);
extern void _Unwind_DeleteException(struct _Unwind_Exception *);
extern void *_Unwind_GetLanguageSpecificData(struct _Unwind_Context *);
extern uintptr_t _Unwind_GetRegionStart(struct _Unwind_Context *);
#ifndef OF_ITANIUM
#ifdef HAVE__UNWIND_GETDATARELBASE
extern uintptr_t _Unwind_GetDataRelBase(struct _Unwind_Context *);
#endif
#ifdef HAVE__UNWIND_GETTEXTRELBASE
extern uintptr_t _Unwind_GetTextRelBase(struct _Unwind_Context *);
#else
extern uintptr_t _Unwind_GetGR(struct _Unwind_Context *, int);
#endif

#ifndef HAVE_ARM_EHABI_EXCEPTIONS
# define CONTINUE_UNWIND return _URC_CONTINUE_UNWIND

extern uintptr_t _Unwind_GetIP(struct _Unwind_Context *);
extern uintptr_t _Unwind_GetGR(struct _Unwind_Context *, int);
extern void _Unwind_SetIP(struct _Unwind_Context *, uintptr_t);
extern void _Unwind_SetGR(struct _Unwind_Context *, int, uintptr_t);
#else
extern _Unwind_Reason_Code __gnu_unwind_frame(struct _Unwind_Exception *,
    struct _Unwind_Context *);
extern int _Unwind_VRS_Get(struct _Unwind_Context *, int, uint32_t, int,
    void *);
290
291
292
293
294
295
296
297

298
299
300
301
302
303
304
305




306
307
308
309
310
311
312
291
292
293
294
295
296
297

298
299
300


301
302
303
304
305
306
307
308
309
310
311
312
313
314
315







-
+


-
-




+
+
+
+







	switch (enc & 0x70) {
	case DW_EH_PE_absptr:
	case DW_EH_PE_pcrel:
	case DW_EH_PE_aligned:
		return 0;
	case DW_EH_PE_funcrel:
		return _Unwind_GetRegionStart(ctx);
#ifndef OF_ITANIUM
#ifdef HAVE__UNWIND_GETDATARELBASE
	case DW_EH_PE_datarel:
		return _Unwind_GetDataRelBase(ctx);
	case DW_EH_PE_textrel:
		return _Unwind_GetTextRelBase(ctx);
#else
	case DW_EH_PE_datarel:
		return _Unwind_GetGR(ctx, 1);
#endif
#ifdef HAVE__UNWIND_GETTEXTRELBASE
	case DW_EH_PE_textrel:
		return _Unwind_GetTextRelBase(ctx);
#endif
	}

	OBJC_ERROR("Unknown encoding!")
}

static size_t
size_for_encoding(uint8_t enc)