assembler relaxation

nagaraju.m nagaraju.m@redpinesignals.com
Wed Dec 30 11:00:00 GMT 2009


Hi Nick,


 Nick Clifton wrote:
> Hi Nagaraju,
>
>>    case 6:
>>    value = (long) (target_address - (address_of_var_part  + 4)) + 4;
>>    value >>= 1;
>>    switch (opcodep[0])
>>    {
>>        case BEZ:
>>        //printf("BEZ 16 value = %d\n",value);
>>        opcodep[2] = 0x54; //emit beq, insertng its opcode
>>        break;
>>        case BNEZ:
>>        //printf("BNEZ 16 value = %d\n",value);
>>        opcodep[2] = 0x94; //emit bne, insertng its opcode
>>        break;
>>    }
>>    opcodep[0] = 0x7; //insert cmp instruction instead of bez
>>    opcodep[3] = ( value & 0xff );//insert offset
>>    fixp = fix_new (fragp, fragp->fr_fix, 4, fragp->fr_symbol,
>>           fragp->fr_offset, 1, BFD_RELOC_RPINE_S8_PCREL);
>>    fixp->fx_pcrel_adjust = 2;
>>    fragp->fr_fix += 2;
>
> OK, so at this point you are presumably expecting that:
>
>   opcodep[0] contains the CMP instruction.
>   opcodep[1] contains zero.
(Nagaraju)          opcodep[1] contains the register which is to compared.
>   opcodep[2] contains the BEQ or BNE instruction.
>   opcodep[3] contains offset to LABEL.
>
> Right ?  But in some cases it would appear that opcodep[2] and 
> opcodep[3] are being replaced with zeroes.
(Nagaraju) absolutely right.
>
> Obviously some other part of the assembler is corrupting the contents 
> of the opcodep[] array.  If you have access to a debugger (eg gdb) I 
> would suggest that you run it and place a watchpoint on opcodep[2] and 
> opcodep[3] to see how they get corrupted.
(Nagaraju) I have kept the watchpoint at that location but no where it 
is getting hit.
>
> Without knowing more, my guess would be that it is connected with 
> how/where this opcodep[] array is declared.  Is it part of a bigger 
> structure that gets reused maybe ?
(Nagaraju)      opcodep[] is pointing to fragp->fr_opcode.
   
    it is declared in md_convert_frag
    {
      unsigned char *opcodep;

     opcodep = fragp->fr_opcode;
      
          ....
    }
>
> Cheers
>   Nick
>
>
>
>
Thanks,
Nagaraju



More information about the Binutils mailing list