Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug
Bug#: 7329
Product:  
Component:  
Status: RESOLVED
Resolution: FIXED
Assigned To: Not yet assigned to anyone <unassigned@gcc.gnu.org>
Host:
Reported against  
Priority:  
Severity:  
Target Milestone:  
 
 
Target:
Reporter: lupus@debian.org
Add CC:
CC:
Remove selected CCs
Build:
URL:
Summary:
Keywords:
Known to work:
Known to fail:

Attachment Description Type Created Size Actions
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 7329 depends on: Show dependency tree
Show dependency graph
Bug 7329 blocks:

Additional Comments:






View Bug Activity   |   Format For Printing   |   Clone This Bug


Description:   Last confirmed: Opened: 2002-07-16 08:26
As part of the mono project we build a library that
needs to detect the x86 processor features. The provided function
is compiled correctly when building a static library, but the compilation 
fails when building a shared library.
Until the bug is fixed it would be nce to know if there is a different
workaround. Thanks.

Release:
3.1.1 20020703 (Debian prerelease) (Debian testing/unstable)

Environment:
System: Linux luna 2.4.19-pre5 #1 Tue Apr 2 11:33:31 CEST 2002 i686 unknown unknown GNU/Linux
Architecture: i686

host: i386-pc-linux-gnu
build: i386-pc-linux-gnu
target: i386-pc-linux-gnu
configured with: /mnt/data/gcc-3.1/gcc-3.1-3.1.1ds2/src/configure -v --enable-languages=c,c++,java,f77,proto,objc,ada --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/g++-v3-3.1 --enable-shared --with-system-zlib --enable-long-long --enable-nls --without-included-gettext --enable-clocale=gnu --enable-__cxa_atexit --enable-threads=posix --enable-java-gc=boehm --enable-objc-gc i386-linux

The same happens also with gcc 2.7.2 and gcc 2.95.4:
gcc -v
Reading specs from /usr/lib/gcc-lib/i386-linux/2.95.4/specs
gcc version 2.95.4 20011002 (Debian prerelease)
gcc272 -v
Reading specs from /usr/lib/gcc-lib/i386-linux/2.7.2.3/specs
gcc version 2.7.2.3

How-To-Repeat:
Save the following code to a file name cp.c and compile enabling PIC:

static int 
cpuid (int id, int* p_eax, int* p_ebx, int* p_ecx, int* p_edx)
{
	__asm__ __volatile__ ("cpuid"
		: "=a" (*p_eax), "=b" (*p_ebx), "=c" (*p_ecx), "=d" (*p_edx)
		: "a" (id));
	return 1;
}

and compile it with:

gcc272 -c -fPIC cp.c
error:
cp.c: In function `cpuid':
cp.c:9: fixed or forbidden register was spilled.
This may be due to a compiler bug or to impossible asm
statements or clauses.

gcc-3.1 -c -fPIC cp.c
error:
cp.c: In function `cpuid':
cp.c:5: can't find a register in class `BREG' while reloading `asm'

gcc-2.95 -c -fPIC cp.c
error:
cp.c: In function `cpuid':
cp.c:7: Invalid `asm' statement:
cp.c:7: fixed or forbidden register 3 (bx) was spilled for class BREG.

------- Comment #1 From lupus@debian.org 2002-07-16 08:26 -------
Fix:

Compile without -fPIC and it builds fine. I tryed compiling with different
-O options to no avail.

------- Comment #2 From Christian Ehrhardt 2002-12-09 16:12 -------
State-Changed-From-To: open->closed
State-Changed-Why: The code is wrong. Your are not allowed to globber %ebx or use it
    as an asm operand if compiling PIC code. %ebx is used by the pic code
    itself to address pc relative data. I think a workaround could be
    to do something like this:
    __asm__ __volatile__ ("xchg %edi,%ebx\n\tcpuid\n\txchg %edi,%ebx":...)
    and use edi for the output operand. gcc probably can't detect the
    save and restore of ebx, however, this might still be illegal code.
    
        regards   Christian

Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug