Changeset 245a92c


Ignore:
Timestamp:
Sep 8, 2018, 8:41:29 AM (3 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer
Children:
bec4d24
Parents:
ba80f99
Message:

handle 0-byte assembler file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • driver/as.cc

    rba80f99 r245a92c  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // as.c --
     7// as.c -- map assembler file, scan for debug information. If found, expand file by one character and insert Cforall
     8//         language code on the N line from the start of the debug information.
    89//
    910// Author           : Peter A. Buhr
    1011// Created On       : Wed Aug  1 10:49:42 2018
    1112// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Aug 22 17:30:24 2018
    13 // Update Count     : 93
     13// Last Modified On : Sat Sep  8 08:40:16 2018
     14// Update Count     : 97
    1415//
    1516
     
    4344        off_t size = mystat.st_size;
    4445
    45         char * start = (char *)mmap( NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 );
    46         if ( start == (void *)-1 ) { perror( "mmap" ); exit( EXIT_FAILURE ); };
     46        if ( size ) {                                                                           // cannot map 0 sized file
     47                char * start = (char *)mmap( NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 );
     48                if ( start == (void *)-1 ) { perror( "mmap" ); exit( EXIT_FAILURE ); };
    4749
    48         if ( char * cursor = strstr( start, ".Ldebug_info0:" ) ) { // debug information ?
    49                 // Expand file by one byte to hold 2 character Cforall language code.
    50                 if ( ftruncate( fd, size + 1 ) ) { perror( "ftruncate" ); exit( EXIT_FAILURE ); };
     50                if ( char * cursor = strstr( start, ".Ldebug_info0:" ) ) { // debug information ?
     51                        // Expand file by one byte to hold 2 character Cforall language code.
     52                        if ( ftruncate( fd, size + 1 ) ) { perror( "ftruncate" ); exit( EXIT_FAILURE ); };
    5153
    52                 for ( int i = 0; i < 8; i += 1 ) {                              // move N (magic) lines forward
    53                         cursor = strstr( cursor, "\n" ) + 1;
    54                 } // for
     54                        for ( int i = 0; i < 8; i += 1 ) {                      // move N (magic) lines forward
     55                                cursor = strstr( cursor, "\n" ) + 1;
     56                        } // for
    5557
    56                 cursor -= 2;                                                                    // backup over "c\n" language value
    57                 if ( *(cursor - 1) != 'x' ) { fprintf( stderr, "invalid C language code\n" ); exit( EXIT_FAILURE ); };
     58                        cursor -= 2;                                                            // backup over "c\n" language value
     59                        if ( *(cursor - 1) != 'x' ) { fprintf( stderr, "invalid C language code\n" ); exit( EXIT_FAILURE ); };
    5860
    59                 memmove( cursor + 2, cursor + 1, start + size - cursor - 1 ); // move remaining text 1 character right
     61                        memmove( cursor + 2, cursor + 1, start + size - cursor - 1 ); // move remaining text 1 character right
    6062
    61                 *(cursor) = '2';                                                                // replace C language value with CFA
    62                 *(cursor + 1) = '5';
     63                        *(cursor) = '2';                                                        // replace C language value with CFA
     64                        *(cursor + 1) = '5';
     65                } // if
     66
     67                if ( munmap( start, size ) ) { perror( "munmap" ); exit( EXIT_FAILURE ); }; // update on disk
    6368        } // if
    64 
    65         if ( munmap( start, size ) ) { perror( "munmap" ); exit( EXIT_FAILURE ); }; // update on disk
    6669
    6770        argv[0] = "as";
Note: See TracChangeset for help on using the changeset viewer.