GCC Inline ASM generates incorrect assembler code (or documentation is unclear, or I am &*&$@$#*&).

Armand Liberi aliberi@acutronic.com
Fri Dec 14 14:27:00 GMT 2001


Hello,

I have a small example of what I think might be a GCC bug involving inline
asm constraints.  I get the same results on three different versions of GCC,
one in RedHat Linux 7.2, one in the newest CygWin distribution for Windows,
and one in a LynxOS distribution that also comes via RedHat as I understand
it and is several years old.

I first submitted it to the PR web site but it was rejected because of the
LynxOS GCC version number.  It was suggested that I send it to you as a more
general question.

So, if you could tell me if it is a bug, a documentation error, or stupidty,
I would appreciate it.

-------------------------------------------------
Problem
-------------------------------------------------
With the variable declarations:

unsigned int singleInt;
unsigned int lotsOfInts[100]={0};

                asm ("FSTPL %0":"=m" (singleInt)); generates "FSTPL
singleInt" as expected, and

                asm ("FSTPL %0":"=m" (lotsOfInts)); generates "FSTPL
lotsOfInts" as expected, and

                asm ("FLDL %0"::"m" (singleInt)); generates "FLDL singleInt"
as expected, BUT

                asm ("FLDL %0"::"m" (lotsOfInts)); generates "FLDL .LC0"
which is NOT expected (by me).

This actually happened using an FSAVE/FRSTOR sequence in a SIGFPE signal
handler.  As the above illustrates, it was not the instruction that caused
the problem - just that an array address is involved rather than a single
variable.  We pay for support from LynuxWorks and they gave me two fixes
shown below.  Those also appear to be bugs to me but, like so many other
people on the net, I'm a little confused about the constraint rules, etc.,
and cannot find any clear statement of those rules.
-------------------------------------------------
Fixes
-------------------------------------------------
 Two have been suggested to me by LynuxWorks support:

1.  Change 'asm ("FLDL %0"::"m" (lotsOfInts));'
    to 'asm ("FLDL %0":"=m" (lotsOfInts));'.  I.E., use an output constraint
to describe an input (???)

2.  Use 'asm ("FLDL lotsOfInts);'.  I.E., don't use constraints."  (I found
a page on the web that said that if the restraints are left off of the
inputs/outputs, then a "clobber" restraint of "memory" should be included
but I can't find any reference to that any where else.

And, I found that:

3.  Using lotsOfInts[0] corrects the code also.
-------------------------------------------------

Thanks for taking the time to look at this.

Regards,
Armand

He who asks is a fool for five minutes, but he who does not ask remains a
fool forever. - Chinese proverb
Life is just one five minute period after another. - Armand Liberi"





More information about the Gcc mailing list