Ignore:
Timestamp:
Feb 18, 2020, 12:10:08 PM (22 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
arm-eh, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr
Children:
fca3bf8
Parents:
921cd82
Message:

Expections now supported in position independent code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/exception.c

    r921cd82 r3b9c674  
    248248}
    249249
    250 #if defined(PIC)
    251 #warning Exceptions not yet supported when using Position-Independent Code
    252 __attribute__((noinline))
    253 void __cfaabi_ehm__try_terminate(void (*try_block)(),
    254                 void (*catch_block)(int index, exception_t * except),
    255                 __attribute__((unused)) int (*match_block)(exception_t * except)) {
    256         abort();
    257 }
    258 #else // PIC
     250#pragma GCC push_options
     251#pragma GCC optimize("O0")
     252
    259253// This is our personality routine. For every stack frame annotated with
    260254// ".cfi_personality 0x3,__gcfa_personality_v0" this function will be called twice when unwinding.
     
    431425
    432426        // Setup the personality routine and exception table.
     427#ifdef __PIC__
     428        asm volatile (".cfi_personality 0x9b,CFA.ref.__gcfa_personality_v0");
     429        asm volatile (".cfi_lsda 0x1b, .LLSDACFA2");
     430#else
    433431        asm volatile (".cfi_personality 0x3,__gcfa_personality_v0");
    434432        asm volatile (".cfi_lsda 0x3, .LLSDACFA2");
     433#endif
    435434
    436435        // Label which defines the start of the area for which the handler is setup.
     
    464463// have a single call to the try routine.
    465464
     465#ifdef __PIC__
     466#if defined( __i386 ) || defined( __x86_64 )
     467asm (
     468        // HEADER
     469        ".LFECFA1:\n"
     470        "       .globl  __gcfa_personality_v0\n"
     471        "       .section        .gcc_except_table,\"a\",@progbits\n"
     472        // TABLE HEADER (important field is the BODY length at the end)
     473        ".LLSDACFA2:\n"
     474        "       .byte   0xff\n"
     475        "       .byte   0xff\n"
     476        "       .byte   0x1\n"
     477        "       .uleb128 .LLSDACSECFA2-.LLSDACSBCFA2\n"
     478        // BODY (language specific data)
     479        // This uses language specific data and can be modified arbitrarily
     480        // We use handled area offset, handled area length,
     481        // handler landing pad offset and 1 (action code, gcc seems to use 0).
     482        ".LLSDACSBCFA2:\n"
     483        "       .uleb128 .TRYSTART-__cfaabi_ehm__try_terminate\n"
     484        "       .uleb128 .TRYEND-.TRYSTART\n"
     485        "       .uleb128 .CATCH-__cfaabi_ehm__try_terminate\n"
     486        "       .uleb128 1\n"
     487        ".LLSDACSECFA2:\n"
     488        // TABLE FOOTER
     489        "       .text\n"
     490        "       .size   __cfaabi_ehm__try_terminate, .-__cfaabi_ehm__try_terminate\n"
     491);
     492
     493// Somehow this piece of helps with the resolution of debug symbols.
     494__attribute__((unused)) static const int dummy = 0;
     495
     496asm (
     497        // Add a hidden symbol which points at the function.
     498        "       .hidden CFA.ref.__gcfa_personality_v0\n"
     499        "       .weak   CFA.ref.__gcfa_personality_v0\n"
     500        // No clue what this does specifically
     501        "       .section        .data.rel.local.CFA.ref.__gcfa_personality_v0,\"awG\",@progbits,CFA.ref.__gcfa_personality_v0,comdat\n"
     502        "       .align 8\n"
     503        "       .type CFA.ref.__gcfa_personality_v0, @object\n"
     504        "       .size CFA.ref.__gcfa_personality_v0, 8\n"
     505        "CFA.ref.__gcfa_personality_v0:\n"
     506#if defined( __x86_64 )
     507        "       .quad __gcfa_personality_v0\n"
     508#else // then __i386
     509        "   .long __gcfa_personality_v0\n"
     510#endif
     511);
     512#else
     513#error Exception Handling: unknown architecture for position independent code.
     514#endif // __i386 || __x86_64
     515#else // __PIC__
    466516#if defined( __i386 ) || defined( __x86_64 )
    467517asm (
     
    491541        "       .size   __cfaabi_ehm__try_terminate, .-__cfaabi_ehm__try_terminate\n"
    492542        "       .ident  \"GCC: (Ubuntu 6.2.0-3ubuntu11~16.04) 6.2.0 20160901\"\n"
    493 //      "       .section        .note.GNU-stack,\"x\",@progbits\n"
     543        "       .section        .note.GNU-stack,\"x\",@progbits\n"
    494544);
     545#else
     546#error Exception Handling: unknown architecture for position dependent code.
    495547#endif // __i386 || __x86_64
    496 #endif // PIC
     548#endif // __PIC__
     549
     550#pragma GCC pop_options
Note: See TracChangeset for help on using the changeset viewer.