Hurry! compile question about switch case statement in GCC2.96

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Nathan:


#define VOS_OK                 (0)
typedef unsigned long          VOS_UINT32;
VOS_UINT32 VOS_ShowDopraInfoEx( VOS_UINT32  ulFlag )     
{                                                        
    int x = ulFlag;                                      
        switch(x){                                       
            case 1:                                      
                    vos_printf("para is 1\n");               
                    break;                                   
            case 2:                                  
                    vos_printf("para is 2\n");           
                    break;                               
            case 3:                                      
                    vos_printf("para is 3\n");           
                    break;                               
            case 4:                                      
                    vos_printf("para is 4\n");           
                    break;                               
            case 5:                                      
                    vos_printf("para is 5\n");           
                    break;                               
            case 6:                                      
                    vos_printf("para is 6\n");           
                    break;                               
            default:                                     
                    vos_printf("para is default.\n");                    
                    break;                               
        }                                                
            return VOS_OK;                               
        }

I use MIPS GCC 2.96 in Tornado2.2 to compile it, following is disassemble code with ?dr, please note red part(can't highligh, please note 18,20 in bracket) .

addiu	$a0,$a0,-1                  
addiu	$sp,$sp,-40                 
sltiu	$v0,$a0,6                   
beqz	$v0,c0 <testFunc+0xc0>      
sd	$ra,32($sp)                 
sll	$v0,$a0,0x2                 
lui	$v1,0x0                     
(18: R_MIPS_HI16	.rodata+0x78)
daddu	$v1,$v1,$v0                 
lw	$v1,120($v1)                
(20: R_MIPS_LO16	.rodata+0x78)         
jr	$v1                         
                                    
lui	$a0,0x0                     
30: R_MIPS_HI16	.rodata             
jal	0 <testFunc>                
34: R_MIPS_26	vos_printf          
daddiu	$a0,$a0,0                   
38: R_MIPS_LO16	.rodata             
j	d0 <testFunc+0xd0>          
3c: R_MIPS_26	.text+0xd0          
ld	$ra,32($sp)                 
….
Following is rodata section of obj:

80180000:  7061 7261 2069 7320 310a 0000 0000 0000   *para is 1.......*
80180010:  7061 7261 2069 7320 320a 0000 0000 0000   *para is 2.......*
80180020:  7061 7261 2069 7320 330a 0000 0000 0000   *para is 3.......*
80180030:  7061 7261 2069 7320 340a 0000 0000 0000   *para is 4.......*
80180040:  7061 7261 2069 7320 350a 0000 0000 0000   *para is 5.......*
80180050:  7061 7261 2069 7320 360a 0000 0000 0000   *para is 6.......*
80180060:  7061 7261 2069 7320 6465 6661 756c 740a   *para is default.*
80180070:  0000 0000 0000 0000 0000 0030 0000 0048   *...........0...H*
80180080:  0000 0060 0000 0078 0000 0090 0000 00a8   *...`...x........*

please note offset 0x78 in .rodata.
value: 0000 0030 0000 0048 0000 0060 0000 0078 0000 0090 0000 00a8

Following is rodata section of executable program,

8123a7c0:  7061 7261 2069 7320 310a 0000 0000 0000   *para is 1.......*
8123a7d0:  7061 7261 2069 7320 320a 0000 0000 0000   *para is 2.......*
8123a7e0:  7061 7261 2069 7320 330a 0000 0000 0000   *para is 3.......*
8123a7f0:  7061 7261 2069 7320 340a 0000 0000 0000   *para is 4.......*
8123a800:  7061 7261 2069 7320 350a 0000 0000 0000   *para is 5.......*
8123a810:  7061 7261 2069 7320 360a 0000 0000 0000   *para is 6.......*
8123a820:  7061 7261 2069 7320 6465 6661 756c 740a   *para is default.*
8123a830:  0000 0000 0000 0000 80e1 38a0 80e1 38b8   *..........8...8.*
8123a840:  80e1 38d0 80e1 38e8 80e1 3900 80e1 3918   *..8...8...9...9.*

Compare rodata section:

value: 0000 0030 0000 0048 0000 0060 0000 0078 0000 0090 0000 00a8
vlaue: 80e1 38a0 80e1 38b8 80e1 38d0 80e1 38e8 80e1 3900 80e1 3918

we know rodata section have been relocated.
There have 24 bytes (6*4) modified.

But as we know, relocation doesn’t tell how much byte will be modified, 
why linker know six words will be relocated, 
this is my question.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux