Ejemplo n.º 1
0
static void printOut( const char *string, size_t offset, size_t size )
{
    const char          *string_left;
    size_t              item_size;
    bool                ascii;

    /* unused parameters */ (void)offset;

    ascii = !IsMasmOutput();
    item_size = 0;
    string_left = string;
    for( ; string_left < ( string + size ); ) {
        if( !ascii || !printableString( string_left ) || strlen( string_left ) == 0 ) {
            printRest( (unsigned_8 *)string_left, size - (size_t)( string_left - string ) );
            break;
        }
        if( strlen( string_left ) < ( size - item_size ) ) {
            BufferConcat( "    .asciiz\t" );
            item_size = printString( string_left, ASCIZ );
        } else {
            BufferConcat( "    .ascii\t" );
            item_size = printString( string_left, ASCII );
        }
        string_left += item_size;
        BufferConcatNL();
        BufferPrint();
    }
}
Ejemplo n.º 2
0
static void printOut( char *string, size_t offset, size_t size )
{
    char *              string_left = string;
    size_t              curr_pos = 0;
    int                 ascii;

    offset = offset;

    ascii = !IsMasmOutput();
    for( ;; ) {
        if( string_left < ( string + size ) ) {
            if( ascii && printableString( string_left ) && strlen( string_left ) > 0 ) {
                if( strlen( string_left ) < ( size - curr_pos ) ) {
                    BufferConcat( "    .asciiz\t" );
                    curr_pos = printString( string_left, ASCIZ );
                } else {
                    BufferConcat( "    .ascii\t" );
                    curr_pos = printString( string_left, ASCII );
                }
                string_left += curr_pos;
            } else {
                printRest( (unsigned_8 *)string_left, size - (size_t)( string_left - string ) );
                break;
            }
        } else {
            break;
        }
        BufferConcatNL();
        BufferPrint();
    }
}
Ejemplo n.º 3
0
unsigned HandleRefInData( ref_entry r_entry, void *data, bool asmLabels )
{
    unsigned            rv;
    const char          * const *types;
    char                buff[MAX_SYM_LEN];      // fixme: should be TS_MAX_OBJNAME or something
    dis_value           value;

    if( IsMasmOutput() ) {
        types = masmTypes;
    } else {
        types = unixTypes;
    }
    rv = RelocSize( r_entry );
    value.u._32[I64HI32] = 0;
    switch( rv ) {
    case 6:
        value.u._32[I64LO32] = *(unsigned_32 *)data;
        break;
    case 4:
        value.u._32[I64LO32] = *(unsigned_32 *)data;
        break;
    case 2:
        value.u._32[I64LO32] = *(unsigned_16 *)data;
        break;
    case 1:
        value.u._32[I64LO32] = *(unsigned_8 *)data;
        break;
    case 8:
        value.u._32[I64LO32] = 0;
        break;
    default:
        value.u._32[I64LO32] = 0;
        break;
    }
    if( asmLabels && types[rv] != NULL ) {
        BufferConcat( types[rv] );
    }
    HandleAReference( value, 0, RFLAG_DEFAULT | RFLAG_IS_IMMED, r_entry->offset, r_entry->offset + rv, &r_entry, buff );
    BufferConcat( buff );
    switch( rv ) {
    case 8:
        value.u._32[I64LO32] = *(unsigned_32 *)data;
        value.u._32[I64HI32] = *((unsigned_32 *)data + 1);
        if( value.u._32[I64LO32] != 0 || value.u._32[I64HI32] != 0 ) {
            BufferConcat( "+" );
            if( value.u._32[I64HI32] != 0 ) {
                BufferStore( "0x%x", value.u._32[I64HI32] );
                BufferStore( "%08x", value.u._32[I64LO32] );
            } else {
                BufferStore( "0x%x", value.u._32[I64LO32] );
            }
        }
        break;
    }
    return( rv );
}
Ejemplo n.º 4
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 );
}
Ejemplo n.º 5
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 );
}
Ejemplo n.º 6
0
static void printRest( unsigned_8 *bytes, size_t size )
{
    size_t      i;
    size_t      d;
    const char  *btype;
    bool        is_masm;
    dis_value   value;

    is_masm = IsMasmOutput();
    if( is_masm ) {
        btype = "    DB\t";
    } else {
        btype = "    .byte\t";
    }
    BufferConcat( btype );
    value.u._32[I64HI32] = 0;
    for( i = 0; i < size; ) {
        // see if we can replace large chunks of homogenous
        // segment space by using the DUP macro
        if( is_masm && (i % 8) == 0 ) {
            d = tryDUP( bytes, i, size );
            if( d > 0 ) {
                i += d;
                if( i < size ) {
                    BufferConcatNL();
                    BufferConcat( btype );
                    BufferPrint();
                }
                continue;
            }
        }

        value.u._32[I64LO32] = bytes[i];
        BufferHex( 2, value );
        if( i < size - 1 ) {
            if( (i % 8) == 7 ) {
                BufferConcatNL();
                BufferConcat( btype );
                BufferPrint();
            } else {
                BufferConcat( ", " );
            }
        }
        i++;
    }
    BufferConcatNL();
    BufferPrint();
}
Ejemplo n.º 7
0
static label_entry resolveTwoLabelsAtLocation( label_list sec_label_list, label_entry entry, label_entry previous_entry, label_entry old_entry )
{
    label_entry first_entry = old_entry;

    for( ; old_entry != NULL && old_entry->offset == entry->offset; old_entry = old_entry->next ) {
        if( entry->type == LTYP_UNNAMED ) {
            if( old_entry->type == LTYP_UNNAMED ) {
                MemFree( entry );
                entry = old_entry;
                return( entry );
            } else if( old_entry->type == LTYP_NAMED ) {
                MemFree( entry );
                entry = old_entry;
                return( entry );
            } else if( old_entry->type == LTYP_ABSOLUTE ) {
            } else if( old_entry->type == LTYP_FUNC_INFO ) {
            } else if( old_entry->type == LTYP_SECTION ) {
                if( !IsMasmOutput() ) {
                    MemFree( entry );
                    entry = old_entry;
                    return( entry );
                }
            } else {
                MemFree( entry );
                entry = old_entry;
                return( entry );
            }
        } else if( entry->type == LTYP_ABSOLUTE ) {
            if( old_entry->type == LTYP_ABSOLUTE ) {
                // merge entry into old_entry
                MemFree( entry );
                entry = old_entry;
                return( entry );
            }
        } else if( entry->type == LTYP_EXTERNAL_NAMED ) {
            break;
        } else {
        }
    }
    // two labels for this location!
    entry->next = first_entry;
    if( previous_entry ) {
        previous_entry->next = entry;
    } else {
        sec_label_list->first = entry;
    }
    return( entry );
}
Ejemplo n.º 8
0
bool NeedsQuoting( const char *name )
{
    // If the name contains funny characters and we are producing
    // assemblable output, put back-quotes around it.

    if( !(DFormat & DFF_ASM) ) return( FALSE );
    if( isdigit( *name ) ) return( TRUE );
    while( *name ) {
        if( isalnum( *name ) || *name == '_' || *name == '?' || *name == '$' ) {
            /* OK character */
        } else if( *name == '.' && !IsMasmOutput() ) {
            /* OK character */
        } else {
            /* character needs quoting */
            return( TRUE );
        }
        name++;
    }
    return( FALSE );
}
Ejemplo n.º 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 ) );
    }
}
Ejemplo n.º 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 ) );
    }
}
Ejemplo n.º 11
0
return_val Init( void )
{
    return_val          error;
    const char *        const *list;
    const char          *name;
    hash_entry_data     key_entry;

    error = RC_OKAY;

    OutputDest = STDOUT_FILENO;
    ChangePrintDest( OutputDest );

    relocSections.first = NULL;
    relocSections.last = NULL;
    if( !MsgInit() ) {
        // MsgInit does its own error message printing
        return( RC_ERROR );
    }
    MemOpen();

    error = HandleArgs();
    if( error != RC_OKAY ) {
        return( error );
    }

    openFiles();
    initGlobals();
    error = initHashTables();
    if( error != RC_OKAY ) {
        PrintErrorMsg( error, WHERE_INIT_HASH_TABLES );
        return( error );
    }
    error = initServicesUsed();
    if( error != RC_OKAY ) {
        // initServicesUsed does its own error message printing
        return( error );
    }
    error = initSectionTables();
    if( error != RC_OKAY ) {
        PrintErrorMsg( error, WHERE_CREATE_SEC_TABLES );
        return( error );
    }
    if( Options & PRINT_PUBLICS ) {
        CreatePublicsArray();
    }
    if( IsMasmOutput() ) {
        CommentString = MASM_COMMENT_STRING;
    }
    if( IsIntelx86() ) {
        SkipRefTable = HashTableCreate( RECOGNITION_TABLE_SIZE, HASH_STRING_IGNORECASE );
        if( SkipRefTable != NULL ) {
            for( list = intelSkipRefList; (name = *list) != NULL; ++list ) {
                key_entry.key.u.string = name;
                key_entry.data.u.string = *list;
                error = HashTableInsert( SkipRefTable, &key_entry );
                if( error != RC_OKAY ) {
                    break;
                }
            }
        }
    }
    if( LabelChar == 0 ) {
        if( IsMasmOutput() ) {
            LabelChar = 'L';
        } else {
            LabelChar = 'X';
        }
    }
    return( error );
}
Ejemplo n.º 12
0
void Init( void )
{
    char                cmd_line[ CMD_LINE_LEN ];
    return_val          error;
    char                **list;

    OutputDest = STDOUT_FILENO;
    ChangePrintDest( OutputDest );

    relocSections.first = NULL;
    relocSections.last = NULL;
    if( !MsgInit() ) {
        // MsgInit does its own error message printing
        exit( -1 );
    }
    MemOpen();

    getcmd( cmd_line );
    HandleArgs( cmd_line );

    openFiles();
    initGlobals();
    error = initHashTables();
    if( error == OKAY ) {
        error = initServicesUsed();
        if( error == OKAY ) {
            error = initSectionTables();
            if( error != OKAY ) {
                // free hash tables and services
                MemClose();
                LeaveProgram( error, WHERE_CREATE_SEC_TABLES );
            }
        } else {
            // free hash tables
            CloseFiles();
            FreeHashTables();
            // initServicesUsed does its own error message printing
            exit( error );
        }
    } else {
        CloseFiles();
        MemClose();
        LeaveProgram( error, WHERE_INIT_HASH_TABLES );
    }
    if( Options & PRINT_PUBLICS ) {
        CreatePublicsArray();
    }
    if( IsMasmOutput() ) {
        CommentString = MASM_COMMENT_STRING;
    }
    if( IsIntelx86() ) {
        SkipRefTable = HashTableCreate( RECOGNITION_TABLE_SIZE, HASH_STRING,
                                        (hash_table_comparison_func) stricmp );
        if( SkipRefTable ) {
            list = intelSkipRefList;
            while( *list ) {
                error = HashTableInsert( SkipRefTable, (hash_value) *list,
                                         (hash_data) *list );
                if( error != OKAY ) break;
                list++;
            }
        }
    }

    if( !LabelChar ) {
        if( IsMasmOutput() ) {
            LabelChar = 'L';
        } else {
            LabelChar = 'X';
        }
    }
}
Ejemplo n.º 13
0
static label_entry dumpAsmLabel( label_entry l_entry, section_ptr sec,
                                 orl_sec_offset curr_pos, orl_sec_offset end,
                                 unsigned_8 *contents, char *buffer )
{
    int         raw;
    int         is_masm;

    end = end;

    raw = buffer && contents;

    is_masm = IsMasmOutput();

    while( l_entry != NULL
        && ( l_entry->type == LTYP_ABSOLUTE || l_entry->offset <= curr_pos ) ) {
        switch( l_entry->type ) {
        case( LTYP_ABSOLUTE ):
            // no print any absolute label here
            break;
        case( LTYP_SECTION ):
            if( is_masm )
                break;
            /* fall through */
        case( LTYP_NAMED ):
            if( strcmp( l_entry->label.name, sec->name ) == 0 )
                break;
            /* fall through */
        case( LTYP_UNNAMED ):

            if( raw ) {
                strncpy( buffer, (char *)contents + curr_pos, sizeof( unsigned_32 ) );
            }
            if( l_entry->type == LTYP_UNNAMED ) {
                if( !(DFormat & DFF_ASM) ) {
                    BufferStore( "\t     %04X\t%c$%d:", LabelChar, curr_pos,
                                 l_entry->label.number );
                    if( raw ) {
                        printRawAndAddress( buffer, curr_pos );
                    }
                } else {
                    if( l_entry->offset != curr_pos ) {
                        BufferStore( "%c$%d equ $-%d", LabelChar, l_entry->label.number, (int)( curr_pos - l_entry->offset ) );
                    } else {
                        BufferStore( "%c$%d:", LabelChar, l_entry->label.number );
                    }
                }
            } else {
                if( !(DFormat & DFF_ASM) ) {
                    BufferStore( "\t     %04X\t%s:", curr_pos,
                                 l_entry->label.name );
                    if( raw ) {
                        printRawAndAddress( buffer, curr_pos );
                    }
                } else {
                    if( l_entry->offset != curr_pos ) {
                        BufferStore( "%s equ $-%d", l_entry->label.name, (int)( curr_pos - l_entry->offset ) );
                    } else {
                        BufferStore( "%s:", l_entry->label.name );
                    }
                }
            }
            BufferConcatNL();
            BufferPrint();
        }
        l_entry = l_entry->next;
    }
    return( l_entry );
}
Ejemplo n.º 14
0
orl_sec_offset HandleRefInData( ref_entry r_entry, void *data, bool asmLabels )
{
    orl_sec_offset      rv;
    const char          * const *types;
    char                buff[MAX_SYM_LEN];      // fixme: should be TS_MAX_OBJNAME or something

    if( IsMasmOutput() ) {
        types = masmTypes;
    } else {
        types = unixTypes;
    }

    rv = RelocSize( r_entry );
    switch( rv ) {
    case 6:
        if( asmLabels && types[rv] ) {
            BufferConcat( types[rv] );
        }
        HandleAReference(*((unsigned_32 *)data), 0, RFLAG_DEFAULT | RFLAG_IS_IMMED, r_entry->offset,
                         r_entry->offset + rv, &r_entry, buff );
        BufferConcat( buff );
        break;
    case 4:
        if( asmLabels ) {
            BufferConcat( types[rv] );
        }
        HandleAReference(*((unsigned_32 *)data), 0, RFLAG_DEFAULT | RFLAG_IS_IMMED, r_entry->offset,
                         r_entry->offset + rv, &r_entry, buff );
        BufferConcat( buff );
        break;
    case 2:
        if( asmLabels ) {
            BufferConcat( types[rv] );
        }
        HandleAReference(*((unsigned_16 *)data), 0, RFLAG_DEFAULT | RFLAG_IS_IMMED, r_entry->offset,
                         r_entry->offset + rv, &r_entry, buff );
        BufferConcat( buff );
        break;
    case 1:
        if( asmLabels ) {
            BufferConcat( types[rv] );
        }
        HandleAReference(*((unsigned_8 *)data), 0, RFLAG_DEFAULT | RFLAG_IS_IMMED, r_entry->offset,
                         r_entry->offset + rv, &r_entry, buff );
        BufferConcat( buff );
        break;
    case 8:
        if( asmLabels ) {
            BufferConcat( types[rv] );
        }
        HandleAReference( 0, 0, RFLAG_DEFAULT | RFLAG_IS_IMMED, r_entry->offset,
                          r_entry->offset + rv, &r_entry, buff );
        BufferConcat( buff );
        if( *((long *)data)!=0 || *((long *)data+4)!=0 ) {
            BufferConcat("+");
            if( *((long *)data+4)!=0 ) {
                BufferStore("0x%x", *((long *)data+4) );
                BufferStore("%08x", *((long *)data) );
            } else {
                BufferStore("0x%x", *((long *)data) );
            }
        }
        break;
    }
    return( rv );
}
Ejemplo n.º 15
0
static label_entry dumpAsmLabel( label_entry l_entry, section_ptr section,
                                 dis_sec_offset curr_pos, dis_sec_offset end,
                                 unsigned_8 *contents, char *buffer )
{
    bool        raw;
    bool        is_masm;

    /* unused parameters */ (void)end;

    raw = ( buffer != NULL && contents != NULL );

    is_masm = IsMasmOutput();

    for( ; l_entry != NULL && ( l_entry->type == LTYP_ABSOLUTE || l_entry->offset <= curr_pos ); l_entry = l_entry->next ) {
        switch( l_entry->type ) {
        case LTYP_ABSOLUTE:
            // no print any absolute label here
            break;
        case LTYP_SECTION:
            if( is_masm )
                break;
            /* fall through */
        case LTYP_NAMED:
            if( strcmp( l_entry->label.name, section->name ) == 0 )
                break;
            /* fall through */
        case LTYP_UNNAMED:
            if( raw ) {
                strncpy( buffer, (char *)contents + curr_pos, sizeof( unsigned_32 ) );
            }
            if( l_entry->type == LTYP_UNNAMED ) {
                if( (DFormat & DFF_ASM) == 0 ) {
                    BufferStore( "\t     %04X\t%c$%d:", LabelChar, curr_pos, l_entry->label.number );
                    if( raw ) {
                        printRawAndAddress( buffer, curr_pos );
                    }
                } else {
                    if( l_entry->offset != curr_pos ) {
                        BufferStore( "%c$%d equ $-%d", LabelChar, l_entry->label.number, (int)( curr_pos - l_entry->offset ) );
                    } else {
                        BufferStore( "%c$%d:", LabelChar, l_entry->label.number );
                    }
                }
            } else {
                if( (DFormat & DFF_ASM) == 0 ) {
                    BufferStore( "\t     %04X\t%s:", curr_pos, l_entry->label.name );
                    if( raw ) {
                        printRawAndAddress( buffer, curr_pos );
                    }
                } else {
                    if( l_entry->offset != curr_pos ) {
                        BufferStore( "%s equ $-%d", l_entry->label.name, (int)( curr_pos - l_entry->offset ) );
                    } else {
                        BufferStore( "%s:", l_entry->label.name );
                    }
                }
            }
            BufferConcatNL();
            BufferPrint();
        }
    }
    return( l_entry );
}
Ejemplo n.º 16
0
size_t HandleAReference( dis_value value, int ins_size, ref_flags flags,
                           orl_sec_offset offset, orl_sec_size sec_size,
                           ref_entry * r_entry, char *buff )
// handle any references at this offset
{
    return_val          error;
    dis_value           nvalue;
    char                *p;

    buff[0] = '\0';
    for( ; *r_entry && (*r_entry)->offset == offset; *r_entry = (*r_entry)->next ) {
        if( (*r_entry)->no_val == 0 ) {
            nvalue = value;
        } else if( (*r_entry)->addend ) {
            nvalue = HandleAddend( *r_entry );
        } else {
            nvalue = 0;
        }
        switch( (*r_entry)->type ) {
        case ORL_RELOC_TYPE_MAX + 1:
        case ORL_RELOC_TYPE_JUMP:
        case ORL_RELOC_TYPE_REL_21_SH:
        case ORL_RELOC_TYPE_WORD_26:
            error = referenceString( *r_entry, sec_size, "j^", "", "",
                                     buff, flags );
            if( error != RC_OKAY ) {
                // label is defined to be beyond the boundaries of the section!
                if( !(DFormat & DFF_ASM) ){
                    BufferStore("\t     %04X", offset );
                    BufferAlignToTab( COMMENT_TAB_POS );
                } else {
                    BufferConcat("\t" );
                }
                BufferConcat( CommentString );
                BufferMsg( LABEL_BEYOND_SECTION );
                BufferConcatNL();
                BufferPrint();
                *r_entry = (*r_entry)->next;
                return( 0 );
            }
            continue; // Don't print addend
            break;
        case ORL_RELOC_TYPE_SEC_REL:
            referenceString( *r_entry, sec_size, "s^", "s^", "@s", buff,
                             flags );
            break;
        case ORL_RELOC_TYPE_HALF_HI:
            referenceString( *r_entry, sec_size, "h^", "h^", "@h", buff,
                             flags );
            break;
        case ORL_RELOC_TYPE_HALF_HA:
            referenceString( *r_entry, sec_size, "ha^", "ha^", "@ha", buff,
                             flags );
            break;
        case ORL_RELOC_TYPE_HALF_LO:
            referenceString( *r_entry, sec_size, "l^", "l^", "@l", buff,
                             flags );
            break;
        case ORL_RELOC_TYPE_REL_14:
        case ORL_RELOC_TYPE_REL_24:
        case ORL_RELOC_TYPE_WORD_14:
        case ORL_RELOC_TYPE_WORD_24:
            nvalue &= ~0x3;
        case ORL_RELOC_TYPE_WORD_16:
        case ORL_RELOC_TYPE_WORD_32:
        case ORL_RELOC_TYPE_WORD_64:
            if( ( (*r_entry)->label->type != LTYP_GROUP ) &&
              ( flags & RFLAG_IS_IMMED ) && IsMasmOutput() ) {
                referenceString( *r_entry, sec_size, "offset ", "offset ",
                                 "", buff, flags );
            } else {
                referenceString( *r_entry, sec_size, "", "", "", buff,
                                 flags );
            }
            break;
        case ORL_RELOC_TYPE_REL_16:
            if( IsIntelx86() && !(*r_entry)->no_val ) {
                nvalue -= ins_size;
            }
            if( ( (*r_entry)->label->type != LTYP_GROUP ) &&
              ( flags & RFLAG_IS_IMMED ) && IsMasmOutput() ) {
                referenceString( *r_entry, sec_size, "offset ", "offset ",
                                 "", buff, flags );
            } else {
                referenceString( *r_entry, sec_size, "", "", "", buff,
                                 flags  );
            }
            break;
        case ORL_RELOC_TYPE_WORD_8:
        case ORL_RELOC_TYPE_WORD_16_SEG:
        case ORL_RELOC_TYPE_WORD_HI_8:
        case ORL_RELOC_TYPE_WORD_32_SEG:
            // Keep these seperate because they are OMF specific
            referenceString( *r_entry, sec_size, "", "", "", buff, flags );
            break;
        case ORL_RELOC_TYPE_SEGMENT:
            if( ( (*r_entry)->label->type != LTYP_GROUP )
                && ( (*r_entry)->label->type != LTYP_SECTION )
                && ( flags & RFLAG_IS_IMMED )
                && IsMasmOutput() ) {
                referenceString( *r_entry, sec_size, "seg ", "seg ", "",
                                 buff, flags );
            } else {
                referenceString( *r_entry, sec_size, "", "", "", buff,
                                 flags );
            }
            break;

        case ORL_RELOC_TYPE_REL_32_NOADJ:
            // this is a little kluge because Brian's ELF files seem to have
            // -4 in the implicit addend for calls and such BBB May 09, 1997
            nvalue += 4;
            // fall through
        case ORL_RELOC_TYPE_REL_8:
        case ORL_RELOC_TYPE_REL_16_SEG:
        case ORL_RELOC_TYPE_REL_HI_8:
        case ORL_RELOC_TYPE_REL_32_SEG:
        case ORL_RELOC_TYPE_REL_32:
        case ORL_RELOC_TYPE_REL_32_ADJ5:
        case ORL_RELOC_TYPE_REL_32_ADJ4:
        case ORL_RELOC_TYPE_REL_32_ADJ3:
        case ORL_RELOC_TYPE_REL_32_ADJ2:
        case ORL_RELOC_TYPE_REL_32_ADJ1:
            // For some reason we add the instruction size to the value
            // of the displacement in a relative call and get a bad
            // offset, due to CORE implementation
            //
            // Main reason :
            // instruction size with displacement and with addend is correct for
            // relative addresses without relocate
            //
            // in amd64 code the instruction size will be added in pass1.c!
            if( (*r_entry)->no_val == 0 && !( GetMachineType() == ORL_MACHINE_TYPE_AMD64 ) ) {
                nvalue -= ins_size;
            }
            referenceString( *r_entry, sec_size, "", "", "", buff, flags );
            break;
        case ORL_RELOC_TYPE_TOCREL_14:
            nvalue &= ~0x3;
        case ORL_RELOC_TYPE_TOCREL_16:
            referenceString( *r_entry, sec_size, "[toc]", "[toc]", "@toc",
                             buff, flags );
            break;
        case ORL_RELOC_TYPE_TOCVREL_14:
            nvalue &= ~0x3;
        case ORL_RELOC_TYPE_TOCVREL_16:
            referenceString( *r_entry, sec_size, "[tocv]", "[tocv]", "@tocv",
                             buff, flags );
            break;
        case ORL_RELOC_TYPE_GOT_16:
            referenceString( *r_entry, sec_size, "", "", "@got", buff, flags );
            break;
        case ORL_RELOC_TYPE_GOT_16_HI:
            referenceString( *r_entry, sec_size, "", "", "@got@h", buff, flags );
            break;
        case ORL_RELOC_TYPE_GOT_16_HA:
            referenceString( *r_entry, sec_size, "", "", "@got@ha", buff, flags );
            break;
        case ORL_RELOC_TYPE_GOT_16_LO:
            referenceString( *r_entry, sec_size, "", "", "@got@l", buff, flags );
            break;
        case ORL_RELOC_TYPE_PLTREL_24:
        case ORL_RELOC_TYPE_PLTREL_32:
        case ORL_RELOC_TYPE_PLT_32:
            referenceString( *r_entry, sec_size, "", "", "@plt", buff, flags );
            break;
        case ORL_RELOC_TYPE_PLT_16_HI:
            referenceString( *r_entry, sec_size, "", "", "@plt@h", buff, flags );
            break;
        case ORL_RELOC_TYPE_PLT_16_HA:
            referenceString( *r_entry, sec_size, "", "", "@plt@ha", buff, flags );
            break;
        case ORL_RELOC_TYPE_PLT_16_LO:
            referenceString( *r_entry, sec_size, "", "", "@plt@l", buff, flags );
            break;
        default:
            continue;
        }
        // LTYP_UNNAMED labels are always at the correct location
        // if( nvalue != 0 && (*r_entry)->label->type != LTYP_UNNAMED ) {
        // not so - BBB Oct 28, 1996
        if(( (*r_entry)->no_val == 0 ) && ( nvalue != 0 )) {
            p = &buff[strlen(buff)];
            if( nvalue < 0 ) {
                *p++ = '-';
                nvalue = -nvalue;
            } else {
                *p++ = '+';
            }
            FmtHexNum( p, 0, nvalue, FALSE );
        }
    }
    return( strlen( buff ) );
}