This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: inline asm clobber bug with -fpic


Sylvain.Pion@sophia.inria.fr (Sylvain Pion) writes:

>         asm const (
> //              "pushl %%ebx\n\t"
>                 "cpuid\n\t"
> //              "popl %%ebx"
>                 : "=a" (dummy), "=d" (cpuid)
>                 : "0" (1)
>                 : "bx", "cx"
>         );
>         mmx_unit_present = ((cpuid & 0x800000) != 0);  // segfault here.
> }
> 
> This code produces a segfault a few instructions later, because it tries to
> use the contents of %ebx, which has been set to 0 by CPUID.
> As far as I understand, since "bx" is in the clobber list, gcc should take
> care of this.

No.  If the %ebx register is used in PIC you cannot rely on gcc doing
anything to restore the value.  Gcc has not enough knowledge about the
special value in %ebx.  This will hopefully change some day but
currently it is not and you indeed have to save and restore %ebx.

-- 
---------------.      drepper at gnu.org  ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Cygnus Solutions `--' drepper at cygnus.com   `------------------------


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]