예제 #1
0
return_val DumpASMSection( section_ptr section, unsigned_8 *contents, dis_sec_size size, unsigned pass )
{
    hash_data           *h_data;
    label_list          sec_label_list;
    label_entry         l_entry;
    ref_list            sec_ref_list;
    ref_entry           r_entry;
    return_val          err;
    hash_key            h_key;

    h_key.u.sec_handle = section->shnd;
    h_data = HashTableQuery( HandleToLabelListTable, h_key );
    if( h_data != NULL ) {
        sec_label_list = h_data->u.sec_label_list;
        l_entry = sec_label_list->first;
    } else {
        sec_label_list = NULL;
        l_entry = NULL;
    }

    r_entry = NULL;
    h_data = HashTableQuery( HandleToRefListTable, h_key );
    if( h_data != NULL ) {
        sec_ref_list = h_data->u.sec_ref_list;
        if( sec_ref_list != NULL ) {
            r_entry = sec_ref_list->first;
        }
    }

    if( pass == 1 ) {
        DoPass1Relocs( contents, r_entry, 0, size );
        return( RC_OKAY );
    }

    if( size == 0 ) {
        if( IsMasmOutput() ) {
            PrintHeader( section );
            dumpAsmLabel( l_entry, section, 0, 0, NULL, NULL );
            PrintTail( section );
        }
        return( RC_OKAY );
    }

    PrintHeader( section );
    err = DumpASMDataFromSection( contents, 0, size, &l_entry, &r_entry, section );
    if( size > 0 ) {
        l_entry = dumpAsmLabel( l_entry, section, size, size, NULL, NULL );
    }
    BufferConcatNL();
    BufferPrint();
    if( err == RC_OKAY ) {
        PrintTail( section );
    }
    return( err );
}
예제 #2
0
return_val DumpASMSection( section_ptr sec, unsigned_8 *contents, orl_sec_size size, unsigned pass )
{
    hash_data           *data_ptr;
    label_list          sec_label_list;
    label_entry         l_entry;
    ref_list            sec_ref_list;
    ref_entry           r_entry;
    return_val          err;

    data_ptr = HashTableQuery( HandleToLabelListTable, (hash_value) sec->shnd );
    if( data_ptr ) {
        sec_label_list = (label_list) *data_ptr;
        l_entry = sec_label_list->first;
    } else {
        sec_label_list = NULL;
        l_entry = NULL;
    }

    r_entry = NULL;
    data_ptr = HashTableQuery( HandleToRefListTable, (hash_value) sec->shnd );
    if( data_ptr ) {
        sec_ref_list = (ref_list) *data_ptr;
        if( sec_ref_list != NULL ) {
            r_entry = sec_ref_list->first;
        }
    }

    if( pass == 1 ) {
        DoPass1Relocs( contents, r_entry, 0, size );
        return( RC_OKAY );
    }

    if( size == 0 ) {
        if( IsMasmOutput() ) {
            PrintHeader( sec );
            dumpAsmLabel( l_entry, sec, 0, 0, NULL, NULL );
            PrintTail( sec );
        }
        return( RC_OKAY );
    }

    PrintHeader( sec );
    err = DumpASMDataFromSection( contents, 0, size, &l_entry, &r_entry, sec );
    if( size > 0 ) {
        l_entry = dumpAsmLabel( l_entry, sec, size, size, NULL, NULL );
    }
    BufferConcatNL();
    BufferPrint();
    if( err == RC_OKAY ) {
        PrintTail( sec );
    }
    return( err );
}
예제 #3
0
void PrintPublics( void ) {
    int                 loop;
    label_entry         entry;
    hash_data *         data_ptr;
    section_ptr         sec;

    // fixme:  data labels get a _ in front, others one after ??
    BufferMsg( LIST_OF_PUBLICS );
    BufferMsg( SYMBOL );
    BufferConcat("\t\t\t");
    BufferMsg( SECTION );
    BufferConcat("\t\t\t");
    BufferMsg( OFFSET );
    BufferConcatNL();
    BufferPrint();
    Print( "--------------------------------------------------------\n" );
    for( loop = 0; loop < Publics.number; loop++ ) {
        entry = Publics.public_symbols[loop];
        BufferConcat( entry->label.name );
        data_ptr = HashTableQuery( HandleToSectionTable, (hash_value) entry->shnd );
        // fixme: what is the proper behavour if no section found??
        if( data_ptr ) {
            sec = (section_ptr) *data_ptr;
            BufferAlignToTab( SECTION_TAB_POS );
            BufferConcat( sec->name );
        }
        BufferAlignToTab( ADDRESS_TAB_POS );
        BufferStore( "%08X\n", entry->offset );
        BufferPrint();
    }
}
예제 #4
0
void CreateAbsoluteLabel( orl_sec_handle shnd, orl_sec_offset loc, unnamed_label_return return_struct )
{
    label_list          sec_label_list;
    hash_data *         data_ptr;
    label_entry         entry;

    entry = MemAlloc( sizeof( label_entry_struct ) );
    if( !entry ) {
        return_struct->error = RC_OUT_OF_MEMORY;
        return;
    }
    entry->offset = loc;
    entry->type = LTYP_ABSOLUTE;
    entry->label.number = 0;
    entry->shnd = shnd;
    data_ptr = HashTableQuery( HandleToLabelListTable, (hash_value) shnd );
    if( data_ptr ) {
        sec_label_list = (label_list) *data_ptr;
        entry = addLabel( sec_label_list, entry, 0 );
        return_struct->entry = entry;
        return_struct->error = RC_OKAY;
    } else {
        // error!!!! the label list should have been created
        return_struct->error = RC_ERROR;
    }
    return;
}
예제 #5
0
static void freeLabelList( orl_sec_handle shnd )
{
    hash_data *         data_ptr;
    label_list          list;
    label_entry         entry;
    label_entry         temp;

    data_ptr = HashTableQuery( HandleToLabelListTable, (hash_value) shnd );
    if( data_ptr ) {
        list = (label_list) *data_ptr;
        entry = list->first;
        while( entry ) {
            temp = entry;
            entry = entry->next;
            switch( temp->type ) {
            case LTYP_UNNAMED:
            case LTYP_ABSOLUTE:
                break;
            default:
                // Step back over backquote (`) or space where it should be.
                if( temp->label.name[-1]==1 ) {
                    temp->label.name -= 1;
                } else {
                    temp->label.name -= 2;
                }
                MemFree( temp->label.name );
                break;
            }
            MemFree( temp );
        }
        MemFree( list );
    }
}
예제 #6
0
char *SkipRef( ref_entry r_entry )
{
    hash_data   *data_ptr;

    if( SkipRefTable && ( r_entry->label->type == LTYP_EXTERNAL_NAMED ) ) {
        data_ptr = HashTableQuery( SkipRefTable, (hash_value)(r_entry->label->label.name) );
        if( data_ptr != NULL ) {
            return( (char *)*data_ptr );
        }
    }
    return( NULL );
}
예제 #7
0
const char *SkipRef( ref_entry r_entry )
{
    hash_data   *h_data;
    hash_key    h_key;

    if( SkipRefTable != NULL && ( r_entry->label->type == LTYP_EXTERNAL_NAMED ) ) {
        h_key.u.string = r_entry->label->label.name;
        h_data = HashTableQuery( SkipRefTable, h_key );
        if( h_data != NULL ) {
            return( h_data->u.string );
        }
    }
    return( NULL );
}
예제 #8
0
static void freeRefList( orl_sec_handle shnd )
{
    hash_data *         data_ptr;
    ref_list            list;
    ref_entry           entry;
    ref_entry           temp;

    data_ptr = HashTableQuery( HandleToRefListTable, (hash_value) shnd );
    if( data_ptr ) {
        list = (ref_list) *data_ptr;
        entry = list->first;
        while( entry ) {
            temp = entry;
            entry = entry->next;
            MemFree( temp );
        }
        MemFree( list );
    }
}
예제 #9
0
return_val BssASMSection( section_ptr sec, orl_sec_size size, unsigned pass )
{
    hash_data *                 data_ptr;
    label_list                  sec_label_list;

    if( pass == 1 ) {
        return RC_OKAY;
    }
    /* Obtain the Symbol Table */
    data_ptr = HashTableQuery( HandleToLabelListTable, (hash_value) sec->shnd );
    if( !data_ptr ) {
        return RC_OKAY;
    }
    sec_label_list = (label_list) *data_ptr;

    if( IsMasmOutput() ) {
        return( bssMasmASMSection( sec, size, sec_label_list->first ) );
    } else {
        return( bssUnixASMSection( sec, size, sec_label_list->first ) );
    }
}
예제 #10
0
return_val BssASMSection( section_ptr section, dis_sec_size size, unsigned pass )
{
    hash_data           *h_data;
    label_list          sec_label_list;
    hash_key            h_key;

    if( pass == 1 ) {
        return RC_OKAY;
    }
    /* Obtain the Symbol Table */
    h_key.u.sec_handle = section->shnd;
    h_data = HashTableQuery( HandleToLabelListTable, h_key );
    if( h_data == NULL ) {
        return RC_OKAY;
    }
    sec_label_list = h_data->u.sec_label_list;

    if( IsMasmOutput() ) {
        return( bssMasmASMSection( section, size, sec_label_list->first ) );
    } else {
        return( bssUnixASMSection( section, size, sec_label_list->first ) );
    }
}
예제 #11
0
static orl_return scanTabCallBack( orl_sec_handle shnd, const orl_sec_offset *pstart, const orl_sec_offset *pend, void *cookie )
{
    section_ptr         section;
    hash_data           *h_data;
    scantab_ptr         sp;
    scantab_ptr         tmp;
    scantab_struct      senitel;
    dis_sec_offset      start;
    dis_sec_offset      end;
    hash_key            h_key;

    /* unused parameters */ (void)cookie;

    if( shnd == ORL_NULL_HANDLE )
        return( ORL_OKAY );
    start = *pstart;
    end = *pend;
    if( start >= end )
        return( ORL_OKAY );
    h_key.u.sec_handle = shnd;
    h_data = HashTableQuery( HandleToSectionTable, h_key );
    if( h_data == NULL )
        return( ORL_OKAY );
    section = h_data->u.section;
    if( section == NULL )
        return( ORL_OKAY );

    sp = MemAlloc( sizeof( scantab_struct ) );
    if( sp == NULL )
        return( ORL_OUT_OF_MEMORY );
    memset( sp, 0, sizeof( scantab_struct ) );
    sp->start = start;
    sp->end = end;

    senitel.next = section->scan;
    for( tmp = &senitel; tmp->next != NULL; tmp = tmp->next ) {
        if( tmp->next->end >= start ) {
            break;
        }
    }

    if( tmp->next != NULL ) {
        if( end < tmp->next->start ) {
            sp->next = tmp->next;
            tmp->next = sp;
        } else {
            // The two records will be merged into one
            if( tmp->next->end < end ) {
                tmp->next->end = end;
            }
            if( tmp->next->start > start ) {
                tmp->next->start = start;
            }
            MemFree( sp );

            // check if we must do additional merging
            sp = tmp->next;
            while( sp->next != NULL && ( sp->end > sp->next->start ) ) {
                if( sp->end < sp->next->end ) {
                    sp->end = sp->next->end;
                }
                tmp = sp->next;
                sp->next = tmp->next;
                MemFree( tmp );
            }
        }
    } else {
        tmp->next = sp;
    }

    // restore the list
    section->scan = senitel.next;

    return( ORL_OKAY );
}
예제 #12
0
static orl_return scanTabCallBack( orl_sec_handle sh, orl_sec_offset start,
                                   orl_sec_offset end, void *cookie )
{
    section_ptr         sec;
    hash_data           *dp;
    scantab_ptr         sp;
    scantab_ptr         tmp;
    scantab_struct      senitel;

    cookie = cookie;
    if( !sh ) return( ORL_OKAY );
    if( start >= end ) return( ORL_OKAY );
    dp = HashTableQuery( HandleToSectionTable, (hash_value) sh );
    if( !dp ) return( ORL_OKAY );
    sec = (section_ptr) *dp;
    if( !sec ) return( ORL_OKAY );

    sp = MemAlloc( sizeof( scantab_struct ) );
    if( !sp ) return( ORL_OUT_OF_MEMORY );
    memset( sp, 0, sizeof( scantab_struct ) );
    sp->start = start;
    sp->end = end;

    senitel.next = sec->scan;
    tmp = &senitel;
    while( tmp->next && ( tmp->next->end < start ) ) {
        tmp = tmp->next;
    }

    if( tmp->next ) {
        if( end < tmp->next->start ) {
            sp->next = tmp->next;
            tmp->next = sp;
        } else {
            // The two records will be merged into one
            if( end > tmp->next->end ) {
                tmp->next->end = end;
            }
            if( start < tmp->next->start ) {
                tmp->next->start = start;
            }
            MemFree( sp );

            // check if we must do additional merging
            sp = tmp->next;
            while( sp->next && ( sp->end > sp->next->start ) ) {
                if( sp->end < sp->next->end ) {
                    sp->end = sp->next->end;
                }
                tmp = sp->next;
                sp->next = tmp->next;
                MemFree( tmp );
            }
        }
    } else {
        tmp->next = sp;
    }

    // restore the list
    sec->scan = senitel.next;

    return( ORL_OKAY );
}
예제 #13
0
orl_return CreateNamedLabel( orl_symbol_handle sym_hnd )
{
    hash_data *         data_ptr;
    label_list          sec_label_list;
    label_entry         entry;
    orl_symbol_type     type;
    orl_symbol_type     primary_type;
    orl_sec_handle      sec;
    char *              SourceName;
    char *              LabName;
    unsigned_64         val64;

    type = ORLSymbolGetType( sym_hnd );
    primary_type = type & 0xFF;
    switch( primary_type ) {
// No harm in including these since elf generates relocs to these.
//      case ORL_SYM_TYPE_NONE:
//      case ORL_SYM_TYPE_FUNC_INFO:
//          return( ORL_OKAY );
        case ORL_SYM_TYPE_FILE:
            SourceName = ORLSymbolGetName( sym_hnd );
            if( (SourceName != NULL) && (SourceFileInObject == NULL) ) {
                SourceFileInObject = SourceName;
            }
            return( ORL_OKAY );
    }
    entry = MemAlloc( sizeof( label_entry_struct ) );
    if( !entry ) return( ORL_OUT_OF_MEMORY );
    val64 = ORLSymbolGetValue( sym_hnd );
    entry->offset = val64.u._32[I64LO32];
    // all symbols from the object file will have names
    entry->shnd = ORLSymbolGetSecHandle( sym_hnd );
    if( primary_type == ORL_SYM_TYPE_SECTION ) {
        entry->type = LTYP_SECTION;
    } else if( primary_type == ORL_SYM_TYPE_GROUP ) {
        entry->type = LTYP_GROUP;
    } else if( entry->shnd == 0 ) {
        entry->type = LTYP_EXTERNAL_NAMED;
    } else if( primary_type == ORL_SYM_TYPE_FUNC_INFO ){
        entry->type = LTYP_FUNC_INFO;
    } else {
        entry->type = LTYP_NAMED;
    }
    entry->binding = ORLSymbolGetBinding( sym_hnd );
    LabName = ORLSymbolGetName( sym_hnd );
    if( LabName == NULL ) {
        sec = ORLSymbolGetSecHandle( sym_hnd );
        if( sec ) {
            LabName = ORLSecGetName( sec );
        } else {
            MemFree( entry );
            return( ORL_OKAY );
        }
    }

    // Demangle the name, if necessary
    if( !((Options & NODEMANGLE_NAMES) || (DFormat & DFF_ASM)) ) {
        entry->label.name = MemAlloc( MAX_LINE_LEN + 3 );
        __demangle_l( LabName, 0, &(entry->label.name[2]), MAX_LINE_LEN );
    } else {
        entry->label.name = MemAlloc( strlen( LabName )+8 );
        strcpy( &(entry->label.name[2]), LabName );
    }

    entry->label.name[0]=0;
    entry->label.name[1]=0;
    LabName = &(entry->label.name[2]);
    if( NeedsQuoting( LabName ) ) {
        // entry->label.name[-1] will be 1 if we have added a quote,
        // 0 otherwise.  This is helpful when freeing the memory.
        entry->label.name[0] = 1;
        entry->label.name[1] = '`';
        entry->label.name += 1;
        LabName += strlen( LabName );
        LabName[0] = '`';
        LabName[1] = '\0';
    } else {
        entry->label.name += 2;
    }
    data_ptr = HashTableQuery( HandleToLabelListTable, (hash_value) entry->shnd );
    if( data_ptr ) {
        sec_label_list = (label_list) *data_ptr;
        entry = addLabel( sec_label_list, entry, sym_hnd );
        if( Options & PRINT_PUBLICS && entry->shnd != 0 &&
                primary_type != ORL_SYM_TYPE_SECTION &&
                entry->binding != ORL_SYM_BINDING_LOCAL ) {
            Publics.number++;
        }
    } else {
        // error!!!! the label list should have been created
        MemFree( entry );
        return( ORL_ERROR );
    }
    return( ORL_OKAY );
}
예제 #14
0
return_val DumpPDataSection( section_ptr sec, unsigned_8 *contents,
                        orl_sec_size size, unsigned pass )
{
    orl_sec_offset      loop;
    hash_data *         data_ptr;
    ref_list            r_list;
    ref_entry           r_entry;
    descriptor_struct   descriptor;
    bool                is32bit;

    if( pass == 1 ) return( OKAY );
    if( size == 0 ) return( OKAY );

    is32bit = ( size >= 0x10000 );

    data_ptr = HashTableQuery( HandleToRefListTable, (hash_value)sec->shnd );
    if( *data_ptr ) {
        r_list = (ref_list)*data_ptr;
        if( r_list ) {
            r_entry = r_list->first;
        } else {
            r_entry = NULL;
        }
    }
    BufferConcatNL();
    PrintHeader( sec );
    BufferConcatNL();
    for( loop = 0; loop < size; loop += sizeof( descriptor_struct ) ) {
        if( r_entry == NULL ) break;
        memcpy( &descriptor, contents + loop, sizeof( descriptor_struct ) );
        if( DFormat & DFF_ASM ) {
            BufferStore( "\t\t" );
            BufferStore( "%s %04X\t\t", CommentString, loop );
        } else {
            PrintLinePrefixAddress( loop, is32bit );
            BufferAlignToTab( PREFIX_SIZE_TABS );
            BufferStore( "%s ", CommentString );
        }
        BufferMsg( PROCEDURE_DESCRIPTOR );

        /* Skip over pair relocs */
        while( r_entry && (r_entry->type == ORL_RELOC_TYPE_PAIR || r_entry->offset < loop) ) {
            r_entry = r_entry->next;
        }
        switch( r_entry->label->type ) {
        case LTYP_EXTERNAL_NAMED:
            BufferStore( "%s", r_entry->label->label.name );
            break;
        case LTYP_NAMED:
        case LTYP_SECTION:
        case LTYP_GROUP:
            BufferStore( "%s", r_entry->label->label.name );
            break;
        default:
            BufferStore( "%c$%d", LabelChar, r_entry->label->label.number );
            break;
        }
        BufferConcatNL();
        printDescriptor( loop, &descriptor, &r_entry );
    }
    return( OKAY );
}