Re: Inline assembly problem (GCC bug?)

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

 



Simon Kagstrom <simon.kagstrom@xxxxxx> writes:

> When disassembling the generated code, this generates the following
> MIPS assembly code, with my comments
> 
> 00000000 <problem>:
>    0:	27bdffe8 	addiu	sp,sp,-24
>    4:	afbf0010 	sw	ra,16(sp)
>    8:	24020001 	li	v0,1          # Result of the inline assembly piece
>    c:	0c000000 	jal	overwriter    # Overwrites v0
>   10:	00000000 	nop                   # jal delay slot - v0 should have been saved here!
>   14:	00402021 	move	a0,v0         # GCC thinks v0 still contains the result of the inline assembly
>   18:	0c000000 	jal	tst
>   1c:	00402821 	move	a1,v0         # ... *and* the result of overwriter()!
>   20:	8fbf0010 	lw	ra,16(sp)
>   24:	00000000 	nop
>   28:	03e00008 	jr	ra
>   2c:	27bd0018 	addiu	sp,sp,24

This is not a bug.  It is a documented restriction on local register
variables:

    Local register variables in specific registers do not reserve the
    registers, except at the point where they are used as input or
    output operands in an asm statement and the asm statement itself
    is not deleted.

There are several ways to avoid this problem.  Simply returning the
register variable doesn't help, but it should work to store the value
in a different register.  Or change the asm to explicitly copy the
value to a variable with the "d" constraint.

Ian

[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