- Timestamp:
- Oct 24, 2023, 4:54:24 PM (14 months ago)
- Branches:
- master
- Children:
- dd7c2ce0
- Parents:
- d8a0e51
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
driver/as.cc
rd8a0e51 r1da2affb 11 11 // Created On : Wed Aug 1 10:49:42 2018 12 12 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Mon Oct 23 16:10:26202314 // Update Count : 1 3713 // Last Modified On : Tue Oct 24 16:53:18 2023 14 // Update Count : 155 15 15 // 16 16 … … 39 39 off_t size = mystat.st_size; 40 40 41 //if ( size ) { // cannot map 0 sized file42 //char * start = (char *)mmap( NULL, size + 2, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 );43 //if ( start == (void *)-1 ) { perror( "mmap" ); exit( EXIT_FAILURE ); };41 if ( size ) { // cannot map 0 sized file 42 char * start = (char *)mmap( NULL, size + 2, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 ); 43 if ( start == (void *)-1 ) { perror( "mmap" ); exit( EXIT_FAILURE ); }; 44 44 45 // char * dcursor; 46 // if ( (dcursor = strstr( start, ".Ldebug_info0:" ) ) ) { // debug information ? 45 char * dcursor; 46 if ( (dcursor = strstr( start, ".Ldebug_info0:" ) ) ) { // debug information ? 47 // fprintf( stderr, "found .Ldebug_info0:\n" ); 48 #if defined( __x86_64__ ) 49 if ( char * cursor = strstr( dcursor, ".long\t.LASF" ) ) { // language code ? 50 // fprintf( stderr, ".long\t.LASF\n" ); 51 #elif defined( __aarch64__ ) 52 if ( char * cursor = strstr( dcursor, ".4byte\t.LASF" ) ) { // language code ? 53 // fprintf( stderr, ".4byte\t.LASF\n" ); 54 #else 55 #error unsupported architecture 56 #endif 57 for ( int i = 0; i < 2; i += 1 ) { // move N (magic) lines forward 58 cursor = strstr( cursor, "\n" ) + 1; 59 } // for 60 cursor -= 2; // backup over "d\n", where d is a hex digit 61 // From elfcpp/dwarf.h in the binutils source tree. 62 // DW_LANG_C89 = 0x1, DW_LANG_C = 0x2, DW_LANG_C99 = 0xc, DW_LANG_C11 = 0x1d 63 if ( *(cursor - 2) == '0' && *(cursor - 1) == 'x' && 64 (*cursor == 'c' || *cursor == '1' || *cursor == '2') ) { // C99/C89/C 65 fprintf( stderr, "language code %c\n", *cursor ); 66 // Expand file by one byte to hold 2 character Cforall language code. 67 if ( ftruncate( fd, size + 1 ) ) { perror( "ftruncate" ); exit( EXIT_FAILURE ); }; 68 memmove( cursor + 2, cursor + 1, start + size - cursor - 1 ); // move remaining text 1 character right 69 } else if ( *(cursor - 3) == '0' && *(cursor - 2) == 'x' && *(cursor - 1) == '1' && *cursor == 'd' ) { // C11 70 } else { 71 for ( int i = 0; i < 6; i += 1 ) { // move N (magic) lines forward 72 cursor = strstr( cursor, "\n" ) + 1; 73 } // for 74 fprintf( stderr, "*** ERROR *** Invalid C language code found in assembler file: %s\n" 75 "Assembler debug information:\n%.*s", 76 argv[argc - 1], (int)(cursor - dcursor), dcursor ); 77 exit( EXIT_FAILURE ); 78 } // if 47 79 48 // if ( char * cursor = strstr( dcursor, ".long\t.LASF" ) ) { // language code ? 49 // for ( int i = 0; i < 2; i += 1 ) { // move N (magic) lines forward 50 // cursor = strstr( cursor, "\n" ) + 1; 51 // } // for 52 // cursor -= 2; // backup over "d\n", where d is a hex digit 53 // // From elfcpp/dwarf.h in the binutils source tree. 54 // // DW_LANG_C89 = 0x1, DW_LANG_C = 0x2, DW_LANG_C99 = 0xc, DW_LANG_C11 = 0x1d 55 // if ( *(cursor - 2) == '0' && *(cursor - 1) == 'x' && 56 // (*cursor == 'c' || *cursor == '1' || *cursor == '2') ) { // C99/C89/C 57 // // Expand file by one byte to hold 2 character Cforall language code. 58 // if ( ftruncate( fd, size + 1 ) ) { perror( "ftruncate" ); exit( EXIT_FAILURE ); }; 59 // memmove( cursor + 2, cursor + 1, start + size - cursor - 1 ); // move remaining text 1 character right 60 // } else if ( *(cursor - 3) == '0' && *(cursor - 2) == 'x' && *(cursor - 1) == '1' && *cursor == 'd' ) { // C11 61 // } else { 62 // for ( int i = 0; i < 6; i += 1 ) { // move N (magic) lines forward 63 // cursor = strstr( cursor, "\n" ) + 1; 64 // } // for 65 // fprintf( stderr, "*** ERROR *** Invalid C language code found in assembler file: %s\n" 66 // "Assembler debug information:\n%.*s", 67 // argv[argc - 1], (int)(cursor - dcursor), dcursor ); 68 // exit( EXIT_FAILURE ); 69 // } // if 80 *(cursor - 1) = '2'; // replace C89/C/C99/C11 language code with CFA code 81 *cursor = '5'; 82 } // if 83 } // if 70 84 71 // *(cursor - 1) = '2'; // replace C89/C/C99/C11 language code with CFA code 72 // *cursor = '5'; 73 // } // if 74 // } // if 75 76 // if ( munmap( start, size + 2 ) ) { perror( "munmap" ); exit( EXIT_FAILURE ); }; // update on disk 77 // } // if 85 if ( munmap( start, size + 2 ) ) { perror( "munmap" ); exit( EXIT_FAILURE ); }; // update on disk 86 } // if 78 87 79 88 argv[0] = "as";
Note: See TracChangeset
for help on using the changeset viewer.