source: libcfa/src/exception.c @ 046a890

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 046a890 was 046a890, checked in by Andrew Beach <ajbeach@…>, 4 years ago

That should get default operations working for throws. More tests to come.

  • Property mode set to 100644
File size: 20.3 KB
RevLine 
[fa4805f]1//
2// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// exception.c --
8//
9// Author           : Andrew Beach
10// Created On       : Mon Jun 26 15:13:00 2017
[3090127]11// Last Modified By : Andrew Beach
[046a890]12// Last Modified On : Tue May 19 14:17:00 2020
13// Update Count     : 19
[fa4805f]14//
15
[9640813]16// Normally we would get this from the CFA prelude.
[cbce272]17#include <stddef.h> // for size_t
18
[fa4805f]19#include "exception.h"
20
[9640813]21// Implementation of the secret header is hardware dependent.
22#if !( defined( __x86_64 ) || defined( __i386 ) )
23#error Exception Handling: No known architecture detected.
24#endif
[fa4805f]25
26#include <stdlib.h>
27#include <stdio.h>
28#include <unwind.h>
[73abe95]29#include <bits/debug.hfa>
[a201f7b]30#include "stdhdr/assert.h"
[fa4805f]31
[b947fb2]32// FIX ME: temporary hack to keep ARM build working
33#ifndef _URC_FATAL_PHASE1_ERROR
[73530d9]34#define _URC_FATAL_PHASE1_ERROR 3
[b947fb2]35#endif // ! _URC_FATAL_PHASE1_ERROR
36#ifndef _URC_FATAL_PHASE2_ERROR
37#define _URC_FATAL_PHASE2_ERROR 2
38#endif // ! _URC_FATAL_PHASE2_ERROR
39
[fa4805f]40#include "lsda.h"
41
[73530d9]42/* The exception class for our exceptions. Because of the vendor component
43 * its value would not be standard.
44 * Vendor: UWPL
45 * Language: CFA\0
46 */
47const _Unwind_Exception_Class __cfaehm_exception_class = 0x4c50575500414643;
[cbce272]48
49// Base exception vtable is abstract, you should not have base exceptions.
[3090127]50struct __cfaehm_base_exception_t_vtable
51                ___cfaehm_base_exception_t_vtable_instance = {
[cbce272]52        .parent = NULL,
53        .size = 0,
54        .copy = NULL,
55        .free = NULL,
56        .msg = NULL
57};
58
59
[fa4805f]60// Temperary global exception context. Does not work with concurency.
[86d5ba7c]61struct exception_context_t {
[3eb5a478]62        struct __cfaehm_try_resume_node * top_resume;
[fa4805f]63
[3eb5a478]64        exception_t * current_exception;
65        int current_handler_index;
66} static shared_stack = {NULL, NULL, 0};
[86d5ba7c]67
68// Get the current exception context.
69// There can be a single global until multithreading occurs, then each stack
70// needs its own. It will have to be updated to handle that.
[9cb89b87]71struct exception_context_t * this_exception_context() {
[86d5ba7c]72        return &shared_stack;
73}
[fa4805f]74
75
76// RESUMPTION ================================================================
77
[f1b6671]78static void reset_top_resume(struct __cfaehm_try_resume_node ** store) {
79        this_exception_context()->top_resume = *store;
80}
81
[046a890]82void __cfaehm_throw_resume(exception_t * except, void (*defaultHandler)(exception_t *)) {
[2a3b019]83        struct exception_context_t * context = this_exception_context();
[fa4805f]84
[851fd92]85        __cfadbg_print_safe(exception, "Throwing resumption exception\n");
[fa4805f]86
[f1b6671]87        __attribute__((cleanup(reset_top_resume)))
[3eb5a478]88        struct __cfaehm_try_resume_node * original_head = context->top_resume;
89        struct __cfaehm_try_resume_node * current = context->top_resume;
[fa4805f]90
91        for ( ; current ; current = current->next) {
[3eb5a478]92                context->top_resume = current->next;
[307a732]93                if (current->handler(except)) {
[fa4805f]94                        return;
95                }
96        }
97
[046a890]98        // No handler found, fall back to the default operation.
[851fd92]99        __cfadbg_print_safe(exception, "Unhandled exception\n");
[046a890]100        defaultHandler(except);
[fa4805f]101}
102
[eb46fdf]103// Do we control where exceptions get thrown even with concurency?
104// If not these are not quite thread safe, the cleanup hook has to
105// be added after the node is built but before it is made the top node.
[b947fb2]106
[3090127]107void __cfaehm_try_resume_setup(struct __cfaehm_try_resume_node * node,
[0304215a]108                        _Bool (*handler)(exception_t * except)) {
[2a3b019]109        struct exception_context_t * context = this_exception_context();
110        node->next = context->top_resume;
[307a732]111        node->handler = handler;
[2a3b019]112        context->top_resume = node;
[fa4805f]113}
114
[3090127]115void __cfaehm_try_resume_cleanup(struct __cfaehm_try_resume_node * node) {
[2a3b019]116        struct exception_context_t * context = this_exception_context();
117        context->top_resume = node->next;
[fa4805f]118}
119
120
[2922871]121// MEMORY MANAGEMENT =========================================================
[ff7ff14a]122
[73530d9]123// How to clean up an exception in various situations.
124static void __cfaehm_exception_cleanup(
125                _Unwind_Reason_Code reason,
126                struct _Unwind_Exception * exception) {
127        switch (reason) {
128        case _URC_FOREIGN_EXCEPTION_CAUGHT:
129                // This one we could clean-up to allow cross-language exceptions.
130        case _URC_FATAL_PHASE1_ERROR:
131        case _URC_FATAL_PHASE2_ERROR:
132        default:
133                abort();
134        }
135}
136
137// We need a piece of storage to raise the exception, for now its a single
138// piece.
139static struct _Unwind_Exception this_exception_storage;
140
[3090127]141struct __cfaehm_node {
142        struct __cfaehm_node * next;
[ff7ff14a]143};
144
[0304215a]145#define NODE_TO_EXCEPT(node) ((exception_t *)(1 + (node)))
[3090127]146#define EXCEPT_TO_NODE(except) ((struct __cfaehm_node *)(except) - 1)
[86d5ba7c]147
148// Creates a copy of the indicated exception and sets current_exception to it.
[3090127]149static void __cfaehm_allocate_exception( exception_t * except ) {
[86d5ba7c]150        struct exception_context_t * context = this_exception_context();
151
[ff7ff14a]152        // Allocate memory for the exception.
[3090127]153        struct __cfaehm_node * store = malloc(
154                sizeof( struct __cfaehm_node ) + except->virtual_table->size );
[ff7ff14a]155
156        if ( ! store ) {
157                // Failure: cannot allocate exception. Terminate thread.
158                abort(); // <- Although I think it might be the process.
[86d5ba7c]159        }
160
[ff7ff14a]161        // Add the node to the list:
162        store->next = EXCEPT_TO_NODE(context->current_exception);
163        context->current_exception = NODE_TO_EXCEPT(store);
164
[86d5ba7c]165        // Copy the exception to storage.
[cbce272]166        except->virtual_table->copy( context->current_exception, except );
[73530d9]167
168        // Set up the exception storage.
169        this_exception_storage.exception_class = __cfaehm_exception_class;
170        this_exception_storage.exception_cleanup = __cfaehm_exception_cleanup;
[86d5ba7c]171}
172
173// Delete the provided exception, unsetting current_exception if relivant.
[3090127]174static void __cfaehm_delete_exception( exception_t * except ) {
[86d5ba7c]175        struct exception_context_t * context = this_exception_context();
176
[851fd92]177        __cfadbg_print_safe(exception, "Deleting Exception\n");
[ff7ff14a]178
179        // Remove the exception from the list.
[3090127]180        struct __cfaehm_node * to_free = EXCEPT_TO_NODE(except);
181        struct __cfaehm_node * node;
[86d5ba7c]182
183        if ( context->current_exception == except ) {
[ff7ff14a]184                node = to_free->next;
185                context->current_exception = (node) ? NODE_TO_EXCEPT(node) : 0;
[86d5ba7c]186        } else {
[ff7ff14a]187                node = EXCEPT_TO_NODE(context->current_exception);
188                // It may always be in the first or second position.
[9cb89b87]189                while ( to_free != node->next ) {
[ff7ff14a]190                        node = node->next;
191                }
192                node->next = to_free->next;
[86d5ba7c]193        }
[ff7ff14a]194
195        // Free the old exception node.
[cbce272]196        except->virtual_table->free( except );
[ff7ff14a]197        free( to_free );
[86d5ba7c]198}
199
[2922871]200// CANCELLATION ==============================================================
[fa4805f]201
202// Function needed by force unwind
203// It basically says to unwind the whole stack and then exit when we reach the end of the stack
204static _Unwind_Reason_Code _Stop_Fn(
205                int version,
206                _Unwind_Action actions,
[3090127]207                _Unwind_Exception_Class exception_class,
[fa4805f]208                struct _Unwind_Exception * unwind_exception,
[2a3b019]209                struct _Unwind_Context * unwind_context,
210                void * stop_param) {
[a201f7b]211        // Verify actions follow the rules we expect.
[851fd92]212        verify((actions & _UA_CLEANUP_PHASE) && (actions & _UA_FORCE_UNWIND));
[a201f7b]213        verify(!(actions & (_UA_SEARCH_PHASE | _UA_HANDER_FRAME)));
[fa4805f]214
[a201f7b]215        if ( actions & _UA_END_OF_STACK ) {
216                exit(1);
217        } else {
218                return _URC_NO_REASON;
219        }
[fa4805f]220}
221
[2922871]222// Cancel the current stack, prefroming approprate clean-up and messaging.
[979df46]223void __cfaehm_cancel_stack( exception_t * exception ) {
[2922871]224        // TODO: Detect current stack and pick a particular stop-function.
225        _Unwind_Reason_Code ret;
226        ret = _Unwind_ForcedUnwind( &this_exception_storage, _Stop_Fn, (void*)0x22 );
227        printf("UNWIND ERROR %d after force unwind\n", ret);
228        abort();
229}
230
231
232// TERMINATION ===============================================================
233
234// If this isn't a rethrow (*except==0), delete the provided exception.
235void __cfaehm_cleanup_terminate( void * except ) {
236        if ( *(void**)except ) __cfaehm_delete_exception( *(exception_t **)except );
237}
238
[86d5ba7c]239// The exception that is being thrown must already be stored.
[046a890]240static void __cfaehm_begin_unwind(void(*defaultHandler)(exception_t *)) {
[86d5ba7c]241        if ( ! this_exception_context()->current_exception ) {
242                printf("UNWIND ERROR missing exception in begin unwind\n");
243                abort();
244        }
[fa4805f]245
246        // Call stdlibc to raise the exception
247        _Unwind_Reason_Code ret = _Unwind_RaiseException( &this_exception_storage );
248
[eb46fdf]249        // If we reach here it means something happened. For resumption to work we need to find a way
250        // to return back to here. Most of them will probably boil down to setting a global flag and
251        // making the phase 1 either stop or fail. Causing an error on purpose may help avoiding
252        // unnecessary work but it might have some weird side effects. If we just pretend no handler
253        // was found that would work but may be expensive for no reason since we will always search
254        // the whole stack.
[fa4805f]255
[2922871]256        // No handler found, go to the default operation.
[9cb89b87]257        if ( ret == _URC_END_OF_STACK ) {
[2922871]258                __cfadbg_print_safe(exception, "Uncaught exception %p\n", &this_exception_storage);
[fa4805f]259
[046a890]260                defaultHandler( this_exception_context()->current_exception );
[fa4805f]261        }
262
[eb46fdf]263        // We did not simply reach the end of the stack without finding a handler. This is an error.
[fa4805f]264        printf("UNWIND ERROR %d after raise exception\n", ret);
265        abort();
266}
267
[046a890]268void __cfaehm_throw_terminate( exception_t * val, void (*defaultHandler)(exception_t *) ) {
[851fd92]269        __cfadbg_print_safe(exception, "Throwing termination exception\n");
[86d5ba7c]270
[3090127]271        __cfaehm_allocate_exception( val );
[046a890]272        __cfaehm_begin_unwind( defaultHandler );
273}
274
275static __attribute__((noreturn)) void __cfaehm_rethrow_adapter( exception_t * except ) {
276        // TODO: Print some error message.
277        (void)except;
278        abort();
[86d5ba7c]279}
280
[3090127]281void __cfaehm_rethrow_terminate(void) {
[851fd92]282        __cfadbg_print_safe(exception, "Rethrowing termination exception\n");
[fa4805f]283
[046a890]284        __cfaehm_begin_unwind( __cfaehm_rethrow_adapter );
285        abort();
[fa4805f]286}
287
[eb46fdf]288// This is our personality routine. For every stack frame annotated with
289// ".cfi_personality 0x3,__gcfa_personality_v0" this function will be called twice when unwinding.
290//  Once in the search phase and once in the cleanup phase.
[3090127]291_Unwind_Reason_Code __gcfa_personality_v0(
292                int version,
293                _Unwind_Action actions,
294                unsigned long long exception_class,
295                struct _Unwind_Exception * unwind_exception,
296                struct _Unwind_Context * unwind_context)
[fa4805f]297{
298
[851fd92]299        //__cfadbg_print_safe(exception, "CFA: 0x%lx\n", _Unwind_GetCFA(context));
300        __cfadbg_print_safe(exception, "Personality function (%d, %x, %llu, %p, %p):",
[3090127]301                        version, actions, exception_class, unwind_exception, unwind_context);
[fa4805f]302
[a201f7b]303        // Verify that actions follow the rules we expect.
304        // This function should never be called at the end of the stack.
305        verify(!(actions & _UA_END_OF_STACK));
306        // Either only the search phase flag is set or...
[fa4805f]307        if (actions & _UA_SEARCH_PHASE) {
[a201f7b]308                verify(actions == _UA_SEARCH_PHASE);
[851fd92]309                __cfadbg_print_safe(exception, " lookup phase");
[a201f7b]310        // ... we are in clean-up phase.
311        } else {
312                verify(actions & _UA_CLEANUP_PHASE);
[851fd92]313                __cfadbg_print_safe(exception, " cleanup phase");
[a201f7b]314                // We shouldn't be the handler frame during forced unwind.
315                if (actions & _UA_HANDLER_FRAME) {
316                        verify(!(actions & _UA_FORCE_UNWIND));
[851fd92]317                        __cfadbg_print_safe(exception, " (handler frame)");
[a201f7b]318                } else if (actions & _UA_FORCE_UNWIND) {
[851fd92]319                        __cfadbg_print_safe(exception, " (force unwind)");
[a201f7b]320                }
[fa4805f]321        }
322
323        // Get a pointer to the language specific data from which we will read what we need
[9cb89b87]324        const unsigned char * lsd = _Unwind_GetLanguageSpecificData( unwind_context );
[fa4805f]325
[9cb89b87]326        if ( !lsd ) {   //Nothing to do, keep unwinding
[fa4805f]327                printf(" no LSD");
328                goto UNWIND;
329        }
330
331        // Get the instuction pointer and a reading pointer into the exception table
332        lsda_header_info lsd_info;
[2a3b019]333        const unsigned char * cur_ptr = parse_lsda_header(unwind_context, lsd, &lsd_info);
334        _Unwind_Ptr instruction_ptr = _Unwind_GetIP(unwind_context);
335
336        struct exception_context_t * context = this_exception_context();
[fa4805f]337
338        // Linearly search the table for stuff to do
[9cb89b87]339        while ( cur_ptr < lsd_info.action_table ) {
[fa4805f]340                _Unwind_Ptr callsite_start;
341                _Unwind_Ptr callsite_len;
342                _Unwind_Ptr callsite_landing_pad;
343                _uleb128_t  callsite_action;
344
345                // Decode the common stuff we have in here
[eb46fdf]346                cur_ptr = read_encoded_value(0, lsd_info.call_site_encoding, cur_ptr, &callsite_start);
347                cur_ptr = read_encoded_value(0, lsd_info.call_site_encoding, cur_ptr, &callsite_len);
348                cur_ptr = read_encoded_value(0, lsd_info.call_site_encoding, cur_ptr, &callsite_landing_pad);
349                cur_ptr = read_uleb128(cur_ptr, &callsite_action);
[fa4805f]350
351                // Have we reach the correct frame info yet?
[9cb89b87]352                if ( lsd_info.Start + callsite_start + callsite_len < instruction_ptr ) {
[e9145a3]353#ifdef __CFA_DEBUG_PRINT__
[fa4805f]354                        void * ls = (void*)lsd_info.Start;
355                        void * cs = (void*)callsite_start;
356                        void * cl = (void*)callsite_len;
357                        void * bp = (void*)lsd_info.Start + callsite_start;
358                        void * ep = (void*)lsd_info.Start + callsite_start + callsite_len;
359                        void * ip = (void*)instruction_ptr;
[851fd92]360                        __cfadbg_print_safe(exception, "\nfound %p - %p (%p, %p, %p), looking for %p\n",
[eb46fdf]361                                        bp, ep, ls, cs, cl, ip);
[e9145a3]362#endif // __CFA_DEBUG_PRINT__
[fa4805f]363                        continue;
364                }
365
[eb46fdf]366                // Have we gone too far?
[9cb89b87]367                if ( lsd_info.Start + callsite_start > instruction_ptr ) {
[fa4805f]368                        printf(" gone too far");
369                        break;
370                }
371
[9cb89b87]372                // Check for what we must do:
[2a3b019]373                if ( 0 == callsite_landing_pad ) {
374                        // Nothing to do, move along
[851fd92]375                        __cfadbg_print_safe(exception, " no landing pad");
[9cb89b87]376                } else if (actions & _UA_SEARCH_PHASE) {
377                        // In search phase, these means we found a potential handler we must check.
378
379                        // We have arbitrarily decided that 0 means nothing to do and 1 means there is
380                        // a potential handler. This doesn't seem to conflict the gcc default behavior.
381                        if (callsite_action != 0) {
382                                // Now we want to run some code to see if the handler matches
383                                // This is the tricky part where we want to the power to run arbitrary code
384                                // However, generating a new exception table entry and try routine every time
385                                // is way more expansive than we might like
386                                // The information we have is :
387                                //  - The GR (Series of registers)
388                                //    GR1=GP Global Pointer of frame ref by context
389                                //  - The instruction pointer
390                                //  - The instruction pointer info (???)
391                                //  - The CFA (Canonical Frame Address)
392                                //  - The BSP (Probably the base stack pointer)
393
394                                // The current apprach uses one exception table entry per try block
395                                _uleb128_t imatcher;
396                                // Get the relative offset to the {...}?
397                                cur_ptr = read_uleb128(cur_ptr, &imatcher);
398
399#                               if defined( __x86_64 )
400                                _Unwind_Word match_pos = _Unwind_GetCFA(unwind_context) + 8;
401#                               elif defined( __i386 )
402                                _Unwind_Word match_pos = _Unwind_GetCFA(unwind_context) + 24;
403#                               endif
404                                int (*matcher)(exception_t *) = *(int(**)(exception_t *))match_pos;
405
406                                int index = matcher(context->current_exception);
407                                _Unwind_Reason_Code ret = (0 == index)
408                                        ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
409                                context->current_handler_index = index;
410
411                                // Based on the return value, check if we matched the exception
412                                if (ret == _URC_HANDLER_FOUND) {
[851fd92]413                                        __cfadbg_print_safe(exception, " handler found\n");
[9cb89b87]414                                } else {
[851fd92]415                                        __cfadbg_print_safe(exception, " no handler\n");
[fa4805f]416                                }
[9cb89b87]417                                return ret;
[fa4805f]418                        }
419
[9cb89b87]420                        // This is only a cleanup handler, ignore it
[851fd92]421                        __cfadbg_print_safe(exception, " no action");
[a201f7b]422                } else {
[9cb89b87]423                        // In clean-up phase, no destructors here but this could be the handler.
424
425                        if ( (callsite_action != 0) && !(actions & _UA_HANDLER_FRAME) ){
426                                // If this is a potential exception handler
427                                // but not the one that matched the exception in the seach phase,
428                                // just ignore it
429                                goto UNWIND;
430                        }
[fa4805f]431
[9cb89b87]432                        // We need to run some clean-up or a handler
433                        // These statment do the right thing but I don't know any specifics at all
434                        _Unwind_SetGR( unwind_context, __builtin_eh_return_data_regno(0),
435                                (_Unwind_Ptr)unwind_exception );
436                        _Unwind_SetGR( unwind_context, __builtin_eh_return_data_regno(1), 0 );
[fa4805f]437
[9cb89b87]438                        // I assume this sets the instruction pointer to the adress of the landing pad
439                        // It doesn't actually set it, it only state the value that needs to be set once we
440                        // return _URC_INSTALL_CONTEXT
441                        _Unwind_SetIP( unwind_context, ((lsd_info.LPStart) + (callsite_landing_pad)) );
[fa4805f]442
[851fd92]443                        __cfadbg_print_safe(exception, " action\n");
[fa4805f]444
[9cb89b87]445                        // Return have some action to run
446                        return _URC_INSTALL_CONTEXT;
[fa4805f]447                }
448        }
449        // No handling found
[851fd92]450        __cfadbg_print_safe(exception, " table end reached");
[fa4805f]451
452        UNWIND:
[851fd92]453        __cfadbg_print_safe(exception, " unwind\n");
[fa4805f]454
455        // Keep unwinding the stack
456        return _URC_CONTINUE_UNWIND;
457}
458
[0f6ac828]459#pragma GCC push_options
[f017af6]460#pragma GCC optimize(0)
[0f6ac828]461
[eb46fdf]462// Try statements are hoisted out see comments for details. While this could probably be unique
463// and simply linked from libcfa but there is one problem left, see the exception table for details
[fa4805f]464__attribute__((noinline))
[3090127]465void __cfaehm_try_terminate(void (*try_block)(),
[0304215a]466                void (*catch_block)(int index, exception_t * except),
467                __attribute__((unused)) int (*match_block)(exception_t * except)) {
[fa4805f]468        //! volatile int xy = 0;
469        //! printf("%p %p %p %p\n", &try_block, &catch_block, &match_block, &xy);
470
[eb46fdf]471        // Setup the personality routine and exception table.
[9cb89b87]472        // Unforturnately these clobber gcc cancellation support which means we can't get access to
473        // the attribute cleanup tables at the same time. We would have to inspect the assembly to
474        // create a new set ourselves.
[3b9c674]475#ifdef __PIC__
476        asm volatile (".cfi_personality 0x9b,CFA.ref.__gcfa_personality_v0");
477        asm volatile (".cfi_lsda 0x1b, .LLSDACFA2");
478#else
[fa4805f]479        asm volatile (".cfi_personality 0x3,__gcfa_personality_v0");
480        asm volatile (".cfi_lsda 0x3, .LLSDACFA2");
[3b9c674]481#endif
[fa4805f]482
[b947fb2]483        // Label which defines the start of the area for which the handler is setup.
[fa4805f]484        asm volatile (".TRYSTART:");
485
486        // The actual statements of the try blocks
487        try_block();
488
489        // asm statement to prevent deadcode removal
490        asm volatile goto ("" : : : : CATCH );
491
[eb46fdf]492        // Normal return for when there is no throw.
[fa4805f]493        return;
494
495        // Exceptionnal path
496        CATCH : __attribute__(( unused ));
[b947fb2]497        // Label which defines the end of the area for which the handler is setup.
[fa4805f]498        asm volatile (".TRYEND:");
[9cb89b87]499        // Label which defines the start of the exception landing pad. Basically what is called when
500        // the exception is caught. Note, if multiple handlers are given, the multiplexing should be
501        // done by the generated code, not the exception runtime.
[fa4805f]502        asm volatile (".CATCH:");
503
504        // Exception handler
[2a3b019]505        // Note: Saving the exception context on the stack breaks termination exceptions.
506        catch_block( this_exception_context()->current_handler_index,
507                     this_exception_context()->current_exception );
[fa4805f]508}
509
[eb46fdf]510// Exception table data we need to generate. While this is almost generic, the custom data refers
511// to {*}try_terminate, which is no way generic. Some more works need to be done if we want to
512// have a single call to the try routine.
[b947fb2]513
[3b9c674]514#ifdef __PIC__
515asm (
516        // HEADER
517        ".LFECFA1:\n"
518        "       .globl  __gcfa_personality_v0\n"
519        "       .section        .gcc_except_table,\"a\",@progbits\n"
520        // TABLE HEADER (important field is the BODY length at the end)
521        ".LLSDACFA2:\n"
522        "       .byte   0xff\n"
523        "       .byte   0xff\n"
524        "       .byte   0x1\n"
525        "       .uleb128 .LLSDACSECFA2-.LLSDACSBCFA2\n"
526        // BODY (language specific data)
527        // This uses language specific data and can be modified arbitrarily
528        // We use handled area offset, handled area length,
529        // handler landing pad offset and 1 (action code, gcc seems to use 0).
530        ".LLSDACSBCFA2:\n"
[3090127]531        "       .uleb128 .TRYSTART-__cfaehm_try_terminate\n"
[3b9c674]532        "       .uleb128 .TRYEND-.TRYSTART\n"
[3090127]533        "       .uleb128 .CATCH-__cfaehm_try_terminate\n"
[3b9c674]534        "       .uleb128 1\n"
535        ".LLSDACSECFA2:\n"
536        // TABLE FOOTER
537        "       .text\n"
[3090127]538        "       .size   __cfaehm_try_terminate, .-__cfaehm_try_terminate\n"
[3b9c674]539);
540
541// Somehow this piece of helps with the resolution of debug symbols.
542__attribute__((unused)) static const int dummy = 0;
543
544asm (
545        // Add a hidden symbol which points at the function.
546        "       .hidden CFA.ref.__gcfa_personality_v0\n"
547        "       .weak   CFA.ref.__gcfa_personality_v0\n"
548        // No clue what this does specifically
549        "       .section        .data.rel.local.CFA.ref.__gcfa_personality_v0,\"awG\",@progbits,CFA.ref.__gcfa_personality_v0,comdat\n"
550        "       .align 8\n"
551        "       .type CFA.ref.__gcfa_personality_v0, @object\n"
552        "       .size CFA.ref.__gcfa_personality_v0, 8\n"
553        "CFA.ref.__gcfa_personality_v0:\n"
554#if defined( __x86_64 )
555        "       .quad __gcfa_personality_v0\n"
556#else // then __i386
[e045590]557        "       .long __gcfa_personality_v0\n"
[3b9c674]558#endif
559);
560#else // __PIC__
[fa4805f]561asm (
[eb46fdf]562        // HEADER
[fa4805f]563        ".LFECFA1:\n"
564        "       .globl  __gcfa_personality_v0\n"
565        "       .section        .gcc_except_table,\"a\",@progbits\n"
[eb46fdf]566        // TABLE HEADER (important field is the BODY length at the end)
567        ".LLSDACFA2:\n"
[fa4805f]568        "       .byte   0xff\n"
569        "       .byte   0xff\n"
570        "       .byte   0x1\n"
[eb46fdf]571        "       .uleb128 .LLSDACSECFA2-.LLSDACSBCFA2\n"
572        // BODY (language specific data)
573        ".LLSDACSBCFA2:\n"
574        //      Handled area start (relative to start of function)
[3090127]575        "       .uleb128 .TRYSTART-__cfaehm_try_terminate\n"
[eb46fdf]576        //      Handled area length
577        "       .uleb128 .TRYEND-.TRYSTART\n"
578        //      Handler landing pad address (relative to start of function)
[3090127]579        "       .uleb128 .CATCH-__cfaehm_try_terminate\n"
[eb46fdf]580        //      Action code, gcc seems to always use 0.
581        "       .uleb128 1\n"
582        // TABLE FOOTER
583        ".LLSDACSECFA2:\n"
584        "       .text\n"
[3090127]585        "       .size   __cfaehm_try_terminate, .-__cfaehm_try_terminate\n"
[fa4805f]586        "       .ident  \"GCC: (Ubuntu 6.2.0-3ubuntu11~16.04) 6.2.0 20160901\"\n"
[3b9c674]587        "       .section        .note.GNU-stack,\"x\",@progbits\n"
[fa4805f]588);
[3b9c674]589#endif // __PIC__
590
591#pragma GCC pop_options
Note: See TracBrowser for help on using the repository browser.