Exemplo n.º 1
0
static void *checkArraySize( omf_file_handle ofh, void *old_arr, long num, long inc, long elem )
{
    long        size;
    void        *new_arr;

    assert( ofh );
    assert( num >= 0 );
    assert( inc > 0 );
    assert( elem > 0 );

    if( !( num % inc ) ) {
        size = ( num + inc ) * elem;
        new_arr = _ClientAlloc( ofh, size );
        if( !new_arr ) return( NULL );
        memset( new_arr, 0, size );
        if( num ) {
            assert( old_arr );
            size = num * elem;
            memcpy( new_arr, old_arr, size );
            _ClientFree( ofh, old_arr );
        }
        old_arr = new_arr;
    }
    return( old_arr );
}
Exemplo n.º 2
0
static void emitSectionData( owl_file_handle file ) {
//****************************************************

    owl_section_info    *curr;
    owl_offset          relocs_size;
    owl_reloc_info      *reloc;
    coff_reloc          *next_reloc;
    coff_reloc          *reloc_buffer;

    for( curr = file->sections; curr != NULL; curr = curr->next ) {
        emitSectionPadding( curr );
        if( !_OwlSectionBSS( curr ) ) {
            OWLBufferEmit( curr->buffer );
        }
        if( curr->first_reloc != NULL ) {
            relocs_size = sizeof( coff_reloc ) * curr->num_relocs;
            reloc_buffer = _ClientAlloc( file, relocs_size );
            next_reloc = reloc_buffer;
            for( reloc = curr->first_reloc; reloc != NULL; reloc = reloc->next ) {
                emitReloc( file, reloc, next_reloc );
                next_reloc++;
            }
            _ClientWrite( file, (const char *)reloc_buffer, relocs_size );
            _ClientFree( file, reloc_buffer );
        }
        // now emit linenumbers
        if( curr->num_linenums != 0 ) {
            OWLBufferEmit( curr->linenum_buffer );
        }
    }
}
Exemplo n.º 3
0
static void emitSymbolTable( owl_file_handle file ) {
//***************************************************

    unsigned            count;
    coff_offset         symbol_table_size;
    owl_symbol_info     *symbol;
    coff_symbol         *symbol_buffer;

    symbol_table_size = numSymbols( file ) * sizeof( coff_symbol );
    if( symbol_table_size != 0 ) {
        lastFunc = NULL;
        lastBf = NULL;
        lastFile = NULL;
        symbol_buffer = _ClientAlloc( file, symbol_table_size );
    #if 1
        memset( symbol_buffer, 0, symbol_table_size );
    #else
        memset( symbol_buffer, 0xBB, symbol_table_size );
    #endif
        count = 0;
        for( symbol = file->symbol_table->head; symbol != NULL; symbol = symbol->next ) {
            if( symbol->flags & OWL_SYM_DEAD ) continue;
            formatOneSymbol( symbol, &symbol_buffer[ count ] );
            count += numAuxSymbols( symbol ) + 1;
            if( symComdat( symbol ) ) {
                formatComdatSymbol( symbol, &symbol_buffer[ count ] );
                count += 1;
            }
        }
        _ClientWrite( file, (const char *)symbol_buffer, symbol_table_size );
        _ClientFree( file, symbol_buffer );
    }
}
Exemplo n.º 4
0
static void doReloc( owl_section_handle section, owl_reloc_info *reloc ) {
//************************************************************************

    owl_offset          displacement;
    owl_offset          old_loc;
    unsigned_32         data;
    unsigned_32         bit_mask;

    displacement = OWLRelocTargetDisp( section, reloc->location, reloc->symbol->offset );
    bit_mask = OWLRelocBitMask( section->file, reloc );
    // OWLBufferPatch( section->buffer, reloc->location, displacement, bitMask );
    old_loc = OWLBufferTell( section->buffer );
    OWLBufferSeek( section->buffer, reloc->location );
    OWLBufferRead( section->buffer, reloc->location, (char *)&data, 4 );
    if( section->file->format == OWL_FORMAT_COFF &&
        section->file->info->cpu == OWL_CPU_PPC &&
        reloc->type == OWL_RELOC_JUMP_REL ) {
        // ugly kludge for the MOTOROLA PPC linker
        displacement += reloc->location;
    }
    if( section->file->format == OWL_FORMAT_ELF &&
        section->file->info->cpu == OWL_CPU_INTEL &&
        reloc->type == OWL_RELOC_BRANCH_REL ) {
        // ugly kludge for 386 ELF objects
        displacement += 4;
    }
    data = (data&~bit_mask)|(((displacement&bit_mask)+(data&bit_mask))&bit_mask);
    OWLBufferWrite( section->buffer, (char *)&data, 4 );
    OWLBufferSeek( section->buffer, old_loc );
    _ClientFree( section->file, reloc );
    section->num_relocs -= 1;
}
Exemplo n.º 5
0
static void binFini( owl_buffer *buffer ) {
//*****************************************

    int                 i;

    for( i = 0; i < NUM_BINS; i++ ) {
        if( buffer->bins[ i ] == NULL ) break;
        _ClientFree( buffer->file, buffer->bins[ i ] );
    }
}
Exemplo n.º 6
0
static void freeRelocs( owl_file_handle file, owl_reloc_info *relocs ) {
/**********************************************************************/

    owl_reloc_info      *ptr;
    owl_reloc_info      *next;

    for( ptr = relocs; ptr != NULL; ptr = next ) {
        next = ptr->next;
        _ClientFree( file, ptr );
    }
}
Exemplo n.º 7
0
static void free_coff_sec_handles( coff_file_handle coff_file_hnd, coff_quantity num_alloced )
/********************************************************************************************/
{
    coff_quantity   i;

    if( coff_file_hnd->coff_sec_hnd != NULL ) {
        for( i = 0; i < num_alloced; i++ ) {
            if( coff_file_hnd->coff_sec_hnd[i]->name_alloced ) {
                _ClientFree( coff_file_hnd, coff_file_hnd->coff_sec_hnd[i]->name );
            }
            _ClientFree( coff_file_hnd, coff_file_hnd->coff_sec_hnd[i] );
        }
        _ClientFree( coff_file_hnd, coff_file_hnd->coff_sec_hnd );
    } else {
        for( i = 0; i < num_alloced; i++ ) {
            _ClientFree( coff_file_hnd, coff_file_hnd->orig_sec_hnd[i] );
        }
    }
    _ClientFree( coff_file_hnd, coff_file_hnd->orig_sec_hnd );
}
Exemplo n.º 8
0
static void free_coff_sec_handles( coff_file_handle coff_file_hnd,
                                   int num_alloced )
/****************************************************************/
{
    int                                 loop;

    if( coff_file_hnd->coff_sec_hnd != NULL ) {
        for( loop = 0; loop < num_alloced; loop++ ) {
            if( coff_file_hnd->coff_sec_hnd[loop]->name_alloced ) {
                _ClientFree( coff_file_hnd,
                             coff_file_hnd->coff_sec_hnd[loop]->name );
            }
            _ClientFree( coff_file_hnd, coff_file_hnd->coff_sec_hnd[loop] );
        }
        _ClientFree( coff_file_hnd, coff_file_hnd->coff_sec_hnd );
    } else {
        for( loop = 0; loop < num_alloced; loop++ ) {
            _ClientFree( coff_file_hnd, coff_file_hnd->orig_sec_hnd[loop] );
        }
    }
    _ClientFree( coff_file_hnd, coff_file_hnd->orig_sec_hnd );
}
Exemplo n.º 9
0
static void emitSectionPadding( owl_section_info *curr ) {
//********************************************************

    char                *buffer;
    owl_offset          padding;

    padding = curr->x.coff.alignment_padding;
    if( padding != 0 ) {
        buffer = _ClientAlloc( curr->file, padding );
        memset( buffer, 0, padding );
        _ClientWrite( curr->file, buffer, padding );
        _ClientFree( curr->file, buffer );
    }
}
Exemplo n.º 10
0
static void AddCoffString( coff_lib_file *c_file, const char *name, size_t len )
{
    char    *x;

    len++;  // add space for terminator character
    if( ( c_file->string_table_size + len ) >= c_file->max_string_table_size ) {
        c_file->max_string_table_size *= 2;
        x = _ClientAlloc( c_file->coff_file_hnd, c_file->max_string_table_size );
        if( x == NULL )
            return;
        memcpy( x, c_file->string_table, c_file->string_table_size );
        _ClientFree( c_file->coff_file_hnd, c_file->string_table );
        c_file->string_table = x;
    }
    memcpy( c_file->string_table + c_file->string_table_size, name, len );
    c_file->string_table_size += (unsigned_32)len;
}
Exemplo n.º 11
0
static void AddCoffString( coff_lib_file  *c_file, char *name, int len )
{
    char    *x;

    len++;
    if( ( c_file->string_table_size + len ) >= c_file->max_string_table_size ) {
        c_file->max_string_table_size *= 2;
        x = _ClientAlloc( c_file->coff_file_hnd, c_file->max_string_table_size );
        if( x == NULL )
            return;
        memcpy( x, c_file->string_table, c_file->string_table_size );
        _ClientFree( c_file->coff_file_hnd, c_file->string_table );
        c_file->string_table = x;
    }
    memcpy( c_file->string_table + c_file->string_table_size, name, len );
    c_file->string_table_size += len;
}
Exemplo n.º 12
0
static void free_coff_file_hnd( coff_file_handle coff_file_hnd )
{
    int                 loop;
    coff_sec_handle     coff_sec_hnd;

    if( coff_file_hnd->coff_sec_hnd ) {
        for( loop = 0; loop < coff_file_hnd->num_sections; loop++ ) {
            coff_sec_hnd = coff_file_hnd->coff_sec_hnd[loop];
            if( coff_sec_hnd->type == ORL_SEC_TYPE_RELOCS ) {
                if( coff_sec_hnd->assoc.reloc.relocs ) {
                    _ClientFree( coff_file_hnd, coff_sec_hnd->assoc.reloc.relocs );
                }
            }
            if( coff_sec_hnd->name_alloced ) {
                _ClientFree( coff_file_hnd, coff_sec_hnd->name );
            }
            _ClientFree( coff_file_hnd, coff_file_hnd->coff_sec_hnd[loop] );
        }
        _ClientFree( coff_file_hnd, coff_file_hnd->coff_sec_hnd );
    }
    _ClientFree( coff_file_hnd, coff_file_hnd->orig_sec_hnd );
    if( coff_file_hnd->symbol_handles ) {
        for( loop = 0; loop < coff_file_hnd->num_symbols; loop++ ) {
            if( coff_file_hnd->symbol_handles[loop].name_alloced ) {
                _ClientFree( coff_file_hnd, coff_file_hnd->symbol_handles[loop].name );
            }
            loop += coff_file_hnd->symbol_handles[loop].symbol->num_aux;
        }
        _ClientFree( coff_file_hnd, coff_file_hnd->symbol_handles );
    }
    if( coff_file_hnd->sec_name_hash_table ) {
        ORLHashTableFree( coff_file_hnd->sec_name_hash_table );
    }
    if( coff_file_hnd->implib_data != NULL ) {
        _ClientFree( coff_file_hnd, coff_file_hnd->implib_data );
    }
    _ClientFree( coff_file_hnd, coff_file_hnd );
}
Exemplo n.º 13
0
static void bufferCollapse( owl_buffer *buffer ) {
//************************************************

    char                *bin;
    char                *dst;
    unsigned            i;

    assert( buffer->size == ( buffer->bin_size * NUM_BINS ) );
    bin = _ClientAlloc( buffer->file, buffer->size );
    for( dst = bin, i = 0; i < NUM_BINS; i++ ) {
        memcpy( dst, buffer->bins[ i ], buffer->bin_size );
        _ClientFree( buffer->file, buffer->bins[ i ] );
        buffer->bins[ i ] = NULL;
        dst += buffer->bin_size;
    }
    buffer->bins[ 0 ] = bin;
    buffer->bin_size = buffer->size;
}
Exemplo n.º 14
0
void OWLENTRY OWLSectionFree( owl_section_handle section ) {
//**********************************************************

    owl_file_handle     file;

    file = section->file;
    deleteSection( file, section );
    if( section->buffer != NULL ) {
        OWLBufferFini( section->buffer );
    }
    if( section->linenum_buffer != NULL ) {
        OWLBufferFini( section->linenum_buffer );
    }
    if( section->first_reloc != NULL ) {
        freeRelocs( file, section->first_reloc );
    }
    _ClientFree( file, section );
    _Log(( file, "OWLSectionFree( %x )\n", section ));
}
Exemplo n.º 15
0
static void emitSectionHeaders( owl_file_handle file ) {
//******************************************************

    uint_32             section_table_size;
    coff_section_header *section_table;
    unsigned            count;
    owl_section_info    *curr;

    section_table_size = numSections( file ) * sizeof( coff_section_header );
    if( section_table_size != 0 ) {
        section_table = _ClientAlloc( file, section_table_size );
        count = 0;
        for( curr = file->sections; curr != NULL; curr = curr->next ) {
            formatSectionHeader( curr, &section_table[ curr->index ] );
            curr->index = count++;
        }
        _ClientWrite( file, (const char *)section_table, section_table_size );
        _ClientFree( file, section_table );
    }
}
Exemplo n.º 16
0
static orl_return       checkSegmentLength( omf_sec_handle sh, uint_32 max )
{
    omf_bytes   conts;

    assert( sh );

    if( max > sh->size ) return( ORL_ERROR );
    if( max > sh->assoc.seg.cur_size ) {
        max = ( max / STD_CODE_SIZE ) + 1;
        max *= STD_CODE_SIZE;
        conts = _ClientAlloc( sh->omf_file_hnd, max );
        if( !conts ) return( ORL_OUT_OF_MEMORY );
        memset( conts, 0, max );
        if( sh->contents ) {
            memcpy( conts, sh->contents, sh->assoc.seg.cur_size );
            _ClientFree( sh->omf_file_hnd, sh->contents );
        }
        sh->contents = conts;
        sh->assoc.seg.cur_size = max;
    }
    return( ORL_OKAY );
}
Exemplo n.º 17
0
static void free_coff_file_hnd( coff_file_handle coff_file_hnd )
{
    coff_quantity       i;
    coff_sec_handle     coff_sec_hnd;

    if( coff_file_hnd->coff_sec_hnd != NULL ) {
        for( i = 0; i < coff_file_hnd->num_sections; ++i ) {
            coff_sec_hnd = coff_file_hnd->coff_sec_hnd[i];
            if( coff_sec_hnd->type == ORL_SEC_TYPE_RELOCS ) {
                if( coff_sec_hnd->assoc.reloc.relocs != NULL ) {
                    _ClientFree( coff_file_hnd, (void *)coff_sec_hnd->assoc.reloc.relocs );
                }
            }
            if( coff_sec_hnd->name_alloced ) {
                _ClientFree( coff_file_hnd, coff_sec_hnd->name );
            }
            _ClientFree( coff_file_hnd, coff_file_hnd->coff_sec_hnd[i] );
        }
        _ClientFree( coff_file_hnd, coff_file_hnd->coff_sec_hnd );
    }
    _ClientFree( coff_file_hnd, coff_file_hnd->orig_sec_hnd );
    if( coff_file_hnd->symbol_handles != NULL ) {
        for( i = 0; i < coff_file_hnd->num_symbols; ++i ) {
            if( coff_file_hnd->symbol_handles[i].name_alloced ) {
                _ClientFree( coff_file_hnd, coff_file_hnd->symbol_handles[i].name );
            }
            i += coff_file_hnd->symbol_handles[i].symbol->num_aux;
        }
        _ClientFree( coff_file_hnd, coff_file_hnd->symbol_handles );
    }
    if( coff_file_hnd->sec_name_hash_table != NULL ) {
        ORLHashTableFree( coff_file_hnd->sec_name_hash_table );
    }
    convert_import_library_fini( coff_file_hnd );
    _ClientFree( coff_file_hnd, coff_file_hnd );
}
Exemplo n.º 18
0
void OWLENTRY OWLFileFini( owl_file_handle file ) {
//*************************************************

    owl_section_handle  curr;
    owl_section_handle  next;

    resolveRelativeRelocs( file );
    resolveLabelNames( file );
    resolveComdefSymbols( file );
    if( file->format == OWL_FORMAT_COFF ) {
        COFFFileEmit( file );
    } else {
        ELFFileEmit( file );
    }
    for( curr = file->sections; curr != NULL; curr = next ) {
        next = curr->next;
        OWLSectionFree( curr );
    }
    OWLSymbolTableFini( file->symbol_table );
    OWLStringFini( file->string_table );
    deleteFile( file->info, file );
    _ClientFree( file, file );
}
Exemplo n.º 19
0
static orl_return load_coff_sec_handles( coff_file_handle coff_file_hnd,
                                         coff_file_header *f_hdr )
/**********************************************************************/
{
    coff_section_header     *s_hdr;
    coff_sec_handle         coff_sec_hnd;
    coff_sec_handle         coff_reloc_sec_hnd;
    coff_quantity           i;
    coff_quantity           num_reloc_secs = 0;
    coff_sec_offset         *reloc_sec_offset;
    coff_sec_size           *reloc_sec_size;
    coff_quantity           reloc_secs_created;

    if( coff_file_hnd->num_sections == 0 ) {
        reloc_sec_offset = NULL;
        reloc_sec_size = NULL;
        coff_file_hnd->orig_sec_hnd = NULL;
    } else {
        reloc_sec_offset = (coff_sec_offset *)_ClientAlloc( coff_file_hnd, sizeof( coff_sec_offset ) * coff_file_hnd->num_sections );
        if( reloc_sec_offset == NULL )
            return( ORL_OUT_OF_MEMORY );
        reloc_sec_size = (coff_sec_size *)_ClientAlloc( coff_file_hnd, sizeof( coff_sec_size ) * coff_file_hnd->num_sections );
        if( reloc_sec_size == NULL ) {
            _ClientFree( coff_file_hnd, reloc_sec_offset );
            return( ORL_OUT_OF_MEMORY );
        }
        memset( reloc_sec_offset, 0, sizeof( coff_sec_offset ) * coff_file_hnd->num_sections );
        memset( reloc_sec_size, 0, sizeof( coff_sec_size ) * coff_file_hnd->num_sections );
        coff_file_hnd->orig_sec_hnd = (coff_sec_handle *)_ClientAlloc( coff_file_hnd, sizeof( coff_sec_handle ) * coff_file_hnd->num_sections );
        if( coff_file_hnd->orig_sec_hnd == NULL ) {
            _ClientFree( coff_file_hnd, reloc_sec_offset );
            _ClientFree( coff_file_hnd, reloc_sec_size );
            return( ORL_OUT_OF_MEMORY );
        }
    }
    coff_file_hnd->coff_sec_hnd = NULL;
    s_hdr = (coff_section_header *)coff_file_hnd->s_hdr_table_buffer;
    for( i = 0; i < coff_file_hnd->num_sections; ++i ) {
        coff_sec_hnd = (coff_sec_handle)_ClientAlloc( coff_file_hnd, sizeof( ORL_STRUCT( coff_sec_handle ) ) );
        if( coff_sec_hnd == NULL ) {
            free_coff_sec_handles( coff_file_hnd, i );
            _ClientFree( coff_file_hnd, reloc_sec_offset );
            _ClientFree( coff_file_hnd, reloc_sec_size );
            return( ORL_OUT_OF_MEMORY );
        }
        coff_file_hnd->orig_sec_hnd[i] = coff_sec_hnd;
        if( s_hdr->name[0] != '/' ) {
            coff_sec_hnd->name = _ClientAlloc( coff_file_hnd, COFF_SEC_NAME_LEN + 1 );
            if( coff_sec_hnd->name == NULL ) {
                free_coff_sec_handles( coff_file_hnd, i );
                _ClientFree( coff_file_hnd, reloc_sec_offset );
                _ClientFree( coff_file_hnd, reloc_sec_size );
                return( ORL_OUT_OF_MEMORY );
            }
            coff_sec_hnd->name_alloced = true;
            strncpy( coff_sec_hnd->name, s_hdr->name, COFF_SEC_NAME_LEN );
            coff_sec_hnd->name[COFF_SEC_NAME_LEN] = 0;
        } else {
            coff_sec_hnd->name = s_hdr->name;
            coff_sec_hnd->name_alloced = false;
        }
        coff_sec_hnd->file_format = ORL_COFF;
        coff_sec_hnd->relocs_done = false;
        coff_sec_hnd->coff_file_hnd = coff_file_hnd;
        coff_sec_hnd->size = s_hdr->size;
        coff_sec_hnd->base = s_hdr->offset;
        coff_sec_hnd->offset = s_hdr->rawdata_ptr;
        coff_sec_hnd->hdr = s_hdr;
        determine_section_specs( coff_sec_hnd, s_hdr );
        coff_sec_hnd->contents = NULL;
        coff_sec_hnd->assoc.normal.reloc_sec = NULL;
        reloc_sec_offset[i] = s_hdr->reloc_ptr;
        if( s_hdr->num_relocs > 0 ) {
            num_reloc_secs++;
        }
        reloc_sec_size[i] = s_hdr->num_relocs * sizeof( coff_reloc );
        s_hdr++;
    }
    /* There are num_reloc_secs + 2 additional section handles to create
     (one each for the symbol and string tables) */
    coff_file_hnd->coff_sec_hnd = (coff_sec_handle *)_ClientAlloc( coff_file_hnd, sizeof( coff_sec_handle ) * (coff_file_hnd->num_sections + num_reloc_secs + 2) );
    if( coff_file_hnd->coff_sec_hnd == NULL ) {
        free_coff_sec_handles( coff_file_hnd, coff_file_hnd->num_sections );
        _ClientFree( coff_file_hnd, reloc_sec_offset );
        _ClientFree( coff_file_hnd, reloc_sec_size );
        return( ORL_OUT_OF_MEMORY );
    }
    memcpy( coff_file_hnd->coff_sec_hnd, coff_file_hnd->orig_sec_hnd, sizeof( coff_sec_handle ) * coff_file_hnd->num_sections );
    reloc_secs_created = 0;
    for( i = 0; i < coff_file_hnd->num_sections; ++i ) {
        if( reloc_sec_size[i] > 0 ) {
            reloc_secs_created++;
            // create a reloc section
            coff_file_hnd->coff_sec_hnd[coff_file_hnd->num_sections + reloc_secs_created] = (coff_sec_handle)_ClientAlloc( coff_file_hnd, sizeof( ORL_STRUCT( coff_sec_handle ) ) );
            coff_reloc_sec_hnd = coff_file_hnd->coff_sec_hnd[coff_file_hnd->num_sections + reloc_secs_created];
            if( coff_reloc_sec_hnd == NULL ) {
                free_coff_sec_handles( coff_file_hnd, coff_file_hnd->num_sections + reloc_secs_created );
                _ClientFree( coff_file_hnd, reloc_sec_offset );
                _ClientFree( coff_file_hnd, reloc_sec_size );
                return( ORL_OUT_OF_MEMORY );
            }
            coff_reloc_sec_hnd->file_format = ORL_COFF;
            coff_reloc_sec_hnd->coff_file_hnd = coff_file_hnd;
            coff_reloc_sec_hnd->name = SectionNames[0];     // ".rel"
            coff_reloc_sec_hnd->name_alloced = false;
            coff_reloc_sec_hnd->relocs_done = false;
            coff_reloc_sec_hnd->size = reloc_sec_size[i];
            coff_reloc_sec_hnd->base = 0;
            coff_reloc_sec_hnd->offset = reloc_sec_offset[i];
            coff_reloc_sec_hnd->type = ORL_SEC_TYPE_RELOCS;
            coff_reloc_sec_hnd->flags = ORL_SEC_FLAG_NONE;
            coff_reloc_sec_hnd->hdr = NULL;
            coff_reloc_sec_hnd->assoc.reloc.orig_sec = coff_file_hnd->coff_sec_hnd[i];
            coff_reloc_sec_hnd->assoc.reloc.relocs = NULL;
            coff_reloc_sec_hnd->align = 4;
            coff_file_hnd->coff_sec_hnd[i]->assoc.normal.reloc_sec = coff_reloc_sec_hnd;
            coff_file_hnd->coff_sec_hnd[coff_file_hnd->num_sections + reloc_secs_created - 1] = coff_reloc_sec_hnd;
        }
    }
    // create the symbol table section
    coff_file_hnd->symbol_table = (coff_sec_handle)_ClientAlloc( coff_file_hnd, sizeof( ORL_STRUCT( coff_sec_handle ) ) );
    if( coff_file_hnd->symbol_table == NULL ) {
        free_coff_sec_handles( coff_file_hnd, i + coff_file_hnd->num_sections );
        _ClientFree( coff_file_hnd, reloc_sec_offset );
        _ClientFree( coff_file_hnd, reloc_sec_size );
        return( ORL_OUT_OF_MEMORY );
    }
    coff_file_hnd->symbol_table->file_format = ORL_COFF;
    coff_file_hnd->symbol_table->coff_file_hnd = coff_file_hnd;
    coff_file_hnd->symbol_table->name = SectionNames[1];    // ".symtab"
    coff_file_hnd->symbol_table->name_alloced = false;
    coff_file_hnd->symbol_table->relocs_done = false;
    coff_file_hnd->symbol_table->size = f_hdr->num_symbols * sizeof( coff_symbol );
    coff_file_hnd->symbol_table->base = 0;
    coff_file_hnd->symbol_table->offset = f_hdr->sym_table;
    coff_file_hnd->symbol_table->hdr = NULL;
    coff_file_hnd->symbol_table->assoc.normal.reloc_sec = NULL;
    coff_file_hnd->symbol_table->type = ORL_SEC_TYPE_SYM_TABLE;
    coff_file_hnd->symbol_table->flags = ORL_SEC_FLAG_NONE;
    coff_file_hnd->symbol_table->align = 4;
    coff_file_hnd->coff_sec_hnd[coff_file_hnd->num_sections + reloc_secs_created] = coff_file_hnd->symbol_table;
    i++;
    // create the string table section
    coff_file_hnd->string_table = (coff_sec_handle)_ClientAlloc( coff_file_hnd, sizeof( ORL_STRUCT( coff_sec_handle ) ) );
    if( coff_file_hnd->string_table == NULL ) {
        free_coff_sec_handles( coff_file_hnd, i + coff_file_hnd->num_sections );
        _ClientFree( coff_file_hnd, reloc_sec_offset );
        _ClientFree( coff_file_hnd, reloc_sec_size );
        return( ORL_OUT_OF_MEMORY );
    }
    coff_file_hnd->string_table->file_format = ORL_COFF;
    coff_file_hnd->string_table->coff_file_hnd = coff_file_hnd;
    coff_file_hnd->string_table->name = SectionNames[2];    // ".strtab"
    coff_file_hnd->string_table->name_alloced = false;
    coff_file_hnd->string_table->relocs_done = false;
    coff_file_hnd->string_table->size = 0;  // determined later
    coff_file_hnd->string_table->base = 0;
    coff_file_hnd->string_table->offset = coff_file_hnd->symbol_table->offset + coff_file_hnd->symbol_table->size;
    coff_file_hnd->string_table->hdr = NULL;
    coff_file_hnd->string_table->assoc.normal.reloc_sec = NULL;
    coff_file_hnd->string_table->type = ORL_SEC_TYPE_STR_TABLE;
    coff_file_hnd->string_table->flags = ORL_SEC_FLAG_NONE;
    coff_file_hnd->string_table->align = 4;
    coff_file_hnd->coff_sec_hnd[coff_file_hnd->num_sections + reloc_secs_created + 1] = coff_file_hnd->string_table;
    _ClientFree( coff_file_hnd, reloc_sec_offset );
    _ClientFree( coff_file_hnd, reloc_sec_size );
    coff_file_hnd->num_sections += num_reloc_secs + 2;
    return( ORL_OKAY );
}
Exemplo n.º 20
0
static void emitStringTable( owl_file_handle file ) {
//***************************************************

    _ClientWrite( file, (const char *)file->x.coff.string_table, sizeof( coff_string_table ) + file->x.coff.string_table->size - 5 );
    _ClientFree( file, file->x.coff.string_table );
}
Exemplo n.º 21
0
static orl_return       applyBakpats( omf_file_handle ofh )
{
    omf_sec_handle      sh;
    orl_return          err = ORL_OKAY;
    omf_tmp_bkfix       tbf;
    uint_8              *pfix8;
    uint_16             *pfix16;
    uint_32             *pfix32;

    assert( ofh );
    assert( ofh->bakpat );

    ofh->bakpat->last_fixup = NULL;

    /* Go through all the backpatches and update the segment data. The BAKPATs
     * aren't normal fixups and may modify all sorts of instructions.
     */
    while( ofh->bakpat->first_fixup ) {
        tbf = ofh->bakpat->first_fixup;
        ofh->bakpat->first_fixup = tbf->next;

        assert( tbf->segidx || tbf->symidx );
        if( tbf->segidx )
            sh = findSegment( ofh, tbf->segidx );
        else 
            sh = findComDatByName( ofh, tbf->symidx );
        if( !sh ) {
            err = ORL_ERROR;
            break;
        }
        switch( tbf->reltype ) {
        case ORL_RELOC_TYPE_WORD_8:
            pfix8 = sh->contents + tbf->offset;
            *pfix8 += tbf->disp;
            break;
        case ORL_RELOC_TYPE_WORD_16:
            pfix16 = (uint_16 *)(sh->contents + tbf->offset);
            *pfix16 += tbf->disp;
            break;
        case ORL_RELOC_TYPE_WORD_32:
            pfix32 = (uint_32 *)(sh->contents + tbf->offset);
            *pfix32 += tbf->disp;
            break;
        default:
            assert( 0 );
            err = ORL_ERROR;
            break;
        }
        if( err != ORL_OKAY )
            break;

        _ClientFree( ofh, tbf );
    }

    assert( !(ofh->status & OMF_STATUS_ADD_BAKPAT) );
    /* Free the entire bakpat structure as well. */
    _ClientFree( ofh, ofh->bakpat );
    ofh->bakpat = NULL;

    return( err );
}
Exemplo n.º 22
0
static orl_return       expandPrevLIData( omf_file_handle ofh )
{
    omf_sec_handle      sh;
    int                 size;
    omf_bytes           buffer;
    orl_return          err = ORL_OKAY;
    unsigned char       tmp[1024];
    omf_tmp_fixup       ftr;
    orl_sec_offset      offset;

    assert( ofh );
    assert( ofh->work_sec );
    assert( ofh->lidata );

    sh = ofh->work_sec;
    size = ofh->lidata->size;

    if( size > 1024 ) {
        buffer = _ClientAlloc( ofh, size );
        if( !buffer ) return( ORL_OUT_OF_MEMORY );
    } else {
        buffer = tmp;
    }

    /* we must remember to save the current offset of the lidata and then
     * restore it
     */
    ofh->lidata->last_fixup = NULL;
    offset = sh->assoc.seg.cur_offset;

    /* make a working copy of the LIDATA
     */
    memcpy( buffer, sh->contents + offset, size );

    while( ofh->lidata->size > 0 ) {
        err = writeAndFixupLIData( ofh, sh, buffer );
        if( err != ORL_OKAY ) return( err );
    }
    sh->assoc.seg.cur_offset = offset;

    if( size > 1024 ) {
        _ClientFree( ofh, buffer );
    }

    assert( !( ofh->status & OMF_STATUS_ADD_MASK ) );

    /* Destroy original fixups
     */
    while( ofh->lidata->first_fixup ) {
        ftr = ofh->lidata->first_fixup;
        ofh->lidata->first_fixup = ftr->next;
        _ClientFree( ofh, ftr );
    }

    /* Add the generated fixups
     */
    while( ofh->lidata->new_fixup ) {
        ftr = ofh->lidata->new_fixup;
        err = OmfAddFixupp( ofh, ftr->is32, ftr->mode, ftr->location,
                            ftr->offset, ftr->fmethod, ftr->fidx, ftr->tmethod,
                            ftr->tidx, ftr->disp );
        if( err != ORL_OKAY ) break;
        ofh->lidata->new_fixup = ftr->next;
        _ClientFree( ofh, ftr );
    }

    ofh->lidata->last_fixup = NULL;

    return( err );
}
Exemplo n.º 23
0
static void FiniCoffLibFile( coff_lib_file *c_file )
{
    _ClientFree( c_file->coff_file_hnd, c_file->string_table );
}
Exemplo n.º 24
0
void OWLENTRY OWLBufferFini( owl_buffer *buffer ) {
//*************************************************

    binFini( buffer );
    _ClientFree( buffer->file, buffer );
}