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]

inline asm clobber bug with -fpic


Hi,

First, I'm not sure if it's a bug of me or egcs, because it shows up with
gcc-2.7.2.3 too, and I'm only a beginner with asm().  Here is with
egcs-19980803.

I want to detect the MMX functionality, so I have the following code:

int  mmx_unit_present;

static inline void detect_mmx(void)
{
        unsigned int cpuid, dummy;

        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.  It seems it's not the case when I compile with "-O2 -fpic".
Removing "-fpic", it works.
To make it work, I need to save %ebx on the stack, with the push/pop.

Please CC me, I'm not subscribed.

-- 
Sylvain


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