c/4106: gcc: i386 -fPIC asm ebx clobber no error

Kevin Ryde user42@zip.com.au
Thu Aug 23 16:16:00 GMT 2001


>Number:         4106
>Category:       c
>Synopsis:       gcc: i386 -fPIC asm ebx clobber no error
>Confidential:   yes
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          accepts-illegal
>Submitter-Id:   net
>Arrival-Date:   Thu Aug 23 16:16:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     
>Release:        3.0 (Debian) (Debian testing/unstable)
>Organization:
>Environment:
System: Linux blah 2.2.15 #1 Tue Apr 25 17:13:48 EST 2000 i586 unknown
Architecture: i586
	<machine, os, target, libraries (multiple lines)>
host: i386-pc-linux-gnu
build: i386-pc-linux-gnu
target: i386-pc-linux-gnu
configured with: ../src/configure -v --enable-languages=c,c++,java,f77,proto,objc --prefix=/usr --infodir=/share/info --mandir=/share/man --enable-shared --with-gnu-as --with-gnu-ld --with-system-zlib --enable-long-long --enable-nls --without-included-gettext --disable-checking --enable-threads=posix --enable-java-gc=boehm --with-cpp-install-dir=bin --enable-objc-gc i386-linux

>Description:
Under -fPIC, an asm block which declares it clobbers ebx doesn't
provoke an error, unlike the way using that register as an output
does.

>How-To-Repeat:
A program foo.c

        int
        main (void)
        {
          asm volatile ("movl $0, %%ebx" : : : "ebx");
          return 0;
        }

compiled with

        gcc -fPIC foo.c

is silently accepted.

I think it should provoke an error like

        bar.c: In function `main':
        bar.c:5: Invalid `asm' statement:
        bar.c:5: fixed or forbidden register 3 (bx) was spilled for class BREG.

which is what the following bar.c gives,

        int
        main (void)
        {
          int  x;
          asm ("movl $0, %%ebx" : "=b" (x));
          return x;
        }

For what it's worth the same happens in both gcc 3.0 and 2.95.4.

I struck this when wanting a "cpuid;rdtsc" combination (the cpuid
being to serialize execution) giving outputs eax and edx and clobbers
ebx and ecx.  Unfortunately in PIC mode that ebx clobber was neither
respected nor rejected, the code generated just went on assuming it
had the GOT pointer, with predictably disasterous consequences.
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-prs mailing list