Changeset 3b9c674


Ignore:
Timestamp:
Feb 18, 2020, 12:10:08 PM (4 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
fca3bf8
Parents:
921cd82
Message:

Expections now supported in position independent code.

Files:
4 added
4 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
  • src/ResolvExpr/Resolver.cc

    r921cd82 r3b9c674  
    8484                void previsit( ThrowStmt * throwStmt );
    8585                void previsit( CatchStmt * catchStmt );
     86                void postvisit( CatchStmt * catchStmt );
    8687                void previsit( WaitForStmt * stmt );
    8788
     
    567568
    568569        void Resolver_old::previsit( CatchStmt * catchStmt ) {
     570                // Until we are very sure this invarent (ifs that move between passes have thenPart)
     571                // holds, check it. This allows a check for when to decode the mangling.
     572                if ( IfStmt * ifStmt = dynamic_cast<IfStmt *>( catchStmt->body ) ) {
     573                        assert( ifStmt->thenPart );
     574                }
     575                // Encode the catchStmt so the condition can see the declaration.
    569576                if ( catchStmt->cond ) {
    570                         findSingleExpression( catchStmt->cond, new BasicType( noQualifiers, BasicType::Bool ), indexer );
     577                        IfStmt * ifStmt = new IfStmt( catchStmt->cond, nullptr, catchStmt->body );
     578                        catchStmt->cond = nullptr;
     579                        catchStmt->body = ifStmt;
     580                }
     581        }
     582
     583        void Resolver_old::postvisit( CatchStmt * catchStmt ) {
     584                // Decode the catchStmt so everything is stored properly.
     585                IfStmt * ifStmt = dynamic_cast<IfStmt *>( catchStmt->body );
     586                if ( nullptr != ifStmt && nullptr == ifStmt->thenPart ) {
     587                        assert( ifStmt->condition );
     588                        assert( ifStmt->elsePart );
     589                        catchStmt->cond = ifStmt->condition;
     590                        catchStmt->body = ifStmt->elsePart;
     591                        ifStmt->condition = nullptr;
     592                        ifStmt->elsePart = nullptr;
     593                        delete ifStmt;
    571594                }
    572595        }
     
    14661489
    14671490        const ast::CatchStmt * Resolver_new::previsit( const ast::CatchStmt * catchStmt ) {
     1491                // TODO: This will need a fix for the decl/cond scoping problem.
    14681492                if ( catchStmt->cond ) {
    14691493                        ast::ptr< ast::Type > boolType = new ast::BasicType{ ast::BasicType::Bool };
  • tests/exceptions/except-0.cfa

    r921cd82 r3b9c674  
    1919};
    2020
    21 void ?{}(signal_exit * this, const char * area) {
    22         this->area = area;
    23 }
    24 
    25 void ^?{}(signal_exit * this) {
    26         printf("Exiting: %s\n", this->area);
     21void ?{}(signal_exit & this, const char * area) {
     22        this.area = area;
     23}
     24
     25void ^?{}(signal_exit & this) {
     26        printf("Exiting: %s\n", this.area);
    2727//      sout | "Exiting:" | this->area;
    2828}
     
    242242
    243243        // Uncaught termination test.
     244        /* Removed due to non-deterministic output.
    244245        printf("Throw uncaught.\n");
    245246        yang z;
    246247        terminate(&z);
    247 }
     248        */
     249}
  • tests/exceptions/except-2.cfa

    r921cd82 r3b9c674  
    1212        struct TABLE(BASE_EXCEPT) const * parent;
    1313        size_t size;
    14         void (*copy)(num_error *this, num_error * other);
    15         void (*free)(num_error *this);
     14        void (*copy)(num_error &this, num_error & other);
     15        void (*free)(num_error &this);
    1616        const char * (*msg)(num_error *this);
    1717        int (*code)(num_error *this);
     
    2828        if ( ! this->msg ) {
    2929                static const char * base = "Num Error with code: X";
    30                 this->msg = malloc(22);
     30                this->msg = (char *)malloc(22);
    3131                for (int i = 0 ; (this->msg[i] = base[i]) ; ++i);
    3232        }
     
    3434        return this->msg;
    3535}
    36 void ?{}(num_error * this, int num) {
    37         this->virtual_table = &INSTANCE(num_error);
    38         this->msg = 0;
    39         this->num = num;
     36void ?{}(num_error & this, int num) {
     37        this.virtual_table = &INSTANCE(num_error);
     38        this.msg = 0;
     39        this.num = num;
    4040}
    41 void ?{}(num_error * this, num_error * other) {
    42         this->virtual_table = other->virtual_table;
    43         this->msg = 0;
    44         this->num = other->num;
     41void ?{}(num_error & this, num_error & other) {
     42        this.virtual_table = other.virtual_table;
     43        this.msg = 0;
     44        this.num = other.num;
    4545}
    46 void ^?{}(num_error * this) {
    47         if( this->msg ) free( this->msg );
     46void ^?{}(num_error & this) {
     47        if( this.msg ) free( this.msg );
    4848}
    4949int num_error_code( num_error * this ) {
Note: See TracChangeset for help on using the changeset viewer.