Bug 55712 - cpuinfo.c doesn't compile for x86-64 with medium memory model
Summary: cpuinfo.c doesn't compile for x86-64 with medium memory model
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.7.2
: P3 normal
Target Milestone: 4.7.3
Assignee: Uroš Bizjak
URL: http://gcc.gnu.org/ml/gcc-patches/201...
Keywords:
Depends on:
Blocks:
 
Reported: 2012-12-16 09:29 UTC by Leif Ekblad
Modified: 2013-01-06 09:15 UTC (History)
0 users

See Also:
Host:
Target: x86_64-*-*
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-12-24 00:00:00


Attachments
Save rbx and use another file for ebx parameter to cpuid (463 bytes, patch)
2012-12-23 22:38 UTC, Leif Ekblad
Details | Diff
Patch that uses other register than rbx for cpuid. (466 bytes, patch)
2012-12-23 22:50 UTC, Leif Ekblad
Details | Diff
Patch that preserves %rbx over cpuid insn (420 bytes, patch)
2012-12-27 08:11 UTC, Uroš Bizjak
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Leif Ekblad 2012-12-16 09:29:50 UTC
Building libgcc with a cross-compiler for x86-64, with -fpic and -mcmodel=medium switches fails.

Error messages:
../../gcc-work/libgcc/. -I../../../gcc-work/libgcc/../gcc -I../../../gcc-work/libgcc/../include 
 -DHAVE_CC_TLS -o cpuinfo.o -MT cpuinfo.o -MD -MP -MF cpuinfo.dep -c 
../../../gcc-work/libgcc/config/i386/cpuinfo.c -fvisibility=hidden -DHIDE_EXPORTS
In file included from ../../../gcc-work/libgcc/config/i386/cpuinfo.c:21:0:
../../../gcc-work/libgcc/config/i386/cpuinfo.c: In function 
'get_available_features':
../../../gcc-work/libgcc/config/i386/cpuinfo.c:236:7: error: inconsistent 
operand constraints in an 'asm'
__cpuid_count (7, 0, eax, ebx, ecx, edx);
^
../../../gcc-work/libgcc/static-object.mk:17: recipe for target `cpuinfo.o' 
failed
make[1]: *** [cpuinfo.o] Error 1
make[1]: Lämnar katalogen "/usr/src/build-gcc-noheader/rdos/libgcc"
Makefile:10619: recipe for target `all-target-libgcc' failed
make: *** [all-target-libgcc] Error 2
Comment 1 Leif Ekblad 2012-12-23 22:38:31 UTC
Created attachment 29038 [details]
Save rbx and use another file for ebx parameter to cpuid
Comment 2 Leif Ekblad 2012-12-23 22:47:13 UTC
Comment on attachment 29038 [details]
Save rbx and use another file for ebx parameter to cpuid

>diff -crNB gcc-4.8-20121216/gcc/config/i386/cpuid.h gcc-work/gcc/config/i386/cpuid.h
>*** gcc-4.8-20121216/gcc/config/i386/cpuid.h	2012-10-26 11:45:46.000000000 +0200
>--- gcc-work/gcc/config/i386/cpuid.h	2012-12-23 23:06:08.000000000 +0100
>***************
>*** 166,171 ****
>--- 166,189 ----
>  	   : "0" (level), "2" (count))
>  #endif
>  #else
>+ 
>+ #if defined(__x86_64__) && defined(__PIC__)
>+ #define __cpuid(level, a, b, c, d)			\
>+   __asm__ ("pushq %%rbx\n\t"        \
>+ 	   "cpuid\n\t"					\
>+ 	   "movl %%ebx, %1\n\t"         \
>+ 	   "popq %%rbx\n\t"             \
>+ 	   : "=a" (a), "=r" (b), "=c" (c), "=d" (d)	\
>+ 	   : "0" (level))
>+ 
>+ #define __cpuid_count(level, count, a, b, c, d)		\
>+   __asm__ ("pushq %%rbx\n\t"        \
>+ 	   "cpuid\n\t"					\
>+ 	   "movl %%ebx, %1\n\t"         \
>+ 	   "popq %%rbx\n\t"             \
>+ 	   : "=a" (a), "=r" (b), "=c" (c), "=d" (d)	\
>+ 	   : "0" (level), "2" (count))
>+ #else
>  #define __cpuid(level, a, b, c, d)			\
>    __asm__ ("cpuid\n\t"					\
>  	   : "=a" (a), "=b" (b), "=c" (c), "=d" (d)	\
>***************
>*** 176,181 ****
>--- 194,200 ----
>  	   : "=a" (a), "=b" (b), "=c" (c), "=d" (d)	\
>  	   : "0" (level), "2" (count))
>  #endif
>+ #endif
>  
>  /* Return highest supported input value for cpuid instruction.  ext can
>     be either 0x0 or 0x8000000 to return highest supported value for
Comment 3 Leif Ekblad 2012-12-23 22:49:53 UTC
Comment on attachment 29038 [details]
Save rbx and use another file for ebx parameter to cpuid

>diff -crNB gcc-4.8-20121216/gcc/config/i386/cpuid.h gcc-work/gcc/config/i386/cpuid.h
>*** gcc-4.8-20121216/gcc/config/i386/cpuid.h	2012-10-26 11:45:46.000000000 +0200
>--- gcc-work/gcc/config/i386/cpuid.h	2012-12-23 23:06:08.000000000 +0100
>***************
>*** 166,171 ****
>--- 166,189 ----
>  	   : "0" (level), "2" (count))
>  #endif
>  #else
>+ 
>+ #if defined(__x86_64__) && defined(__PIC__)
>+ #define __cpuid(level, a, b, c, d)			\
>+   __asm__ ("pushq %%rbx\n\t"        \
>+ 	   "cpuid\n\t"					\
>+ 	   "movl %%ebx, %1\n\t"         \
>+ 	   "popq %%rbx\n\t"             \
>+ 	   : "=a" (a), "=r" (b), "=c" (c), "=d" (d)	\
>+ 	   : "0" (level))
>+ 
>+ #define __cpuid_count(level, count, a, b, c, d)		\
>+   __asm__ ("pushq %%rbx\n\t"        \
>+ 	   "cpuid\n\t"					\
>+ 	   "movl %%ebx, %1\n\t"         \
>+ 	   "popq %%rbx\n\t"             \
>+ 	   : "=a" (a), "=r" (b), "=c" (c), "=d" (d)	\
>+ 	   : "0" (level), "2" (count))
>+ #else
>  #define __cpuid(level, a, b, c, d)			\
>    __asm__ ("cpuid\n\t"					\
>  	   : "=a" (a), "=b" (b), "=c" (c), "=d" (d)	\
>***************
>*** 176,181 ****
>--- 194,200 ----
>  	   : "=a" (a), "=b" (b), "=c" (c), "=d" (d)	\
>  	   : "0" (level), "2" (count))
>  #endif
>+ #endif
>  
>  /* Return highest supported input value for cpuid instruction.  ext can
>     be either 0x0 or 0x8000000 to return highest supported value for
Comment 4 Leif Ekblad 2012-12-23 22:50:51 UTC
Created attachment 29039 [details]
Patch that uses other register than rbx for cpuid.
Comment 5 Uroš Bizjak 2012-12-24 15:43:02 UTC
Please try patch at [1]

[1] http://gcc.gnu.org/ml/gcc-patches/2012-12/msg01391.html
Comment 6 Leif Ekblad 2012-12-24 17:53:00 UTC
Confirmed to work with medium memory model (x86_64-pc-rdos).
Comment 7 Uroš Bizjak 2012-12-27 08:11:40 UTC
Created attachment 29053 [details]
Patch that preserves %rbx over cpuid insn

Alternative patch that avoids changing %rbx PIC register.
Comment 8 uros 2013-01-03 17:16:30 UTC
Author: uros
Date: Thu Jan  3 17:16:08 2013
New Revision: 194862

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=194862
Log:
	PR target/55712
	* config/i386/i386-c.c (ix86_target_macros_internal): Depending on
	selected code model, define __code_mode_small__, __code_model_medium__,
	__code_model_large__, __code_model_32__ or __code_model_kernel__.
	* config/i386/cpuid.h (__cpuid, __cpuid_count) [__i386__]: Prefix
	xchg temporary register with %k.  Declare temporary register as
	early clobbered.
	[__x86_64__]: For medium and large code models, preserve %rbx register.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/cpuid.h
    trunk/gcc/config/i386/i386-c.c
Comment 9 uros 2013-01-06 08:45:48 UTC
Author: uros
Date: Sun Jan  6 08:45:43 2013
New Revision: 194937

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=194937
Log:
	Backport from mainline
	2013-01-03  Uros Bizjak  <ubizjak@gmail.com>

	PR target/55712
	* config/i386/i386-c.c (ix86_target_macros_internal): Depending on
	selected code model, define __code_mode_small__, __code_model_medium__,
	__code_model_large__, __code_model_32__ or __code_model_kernel__.
	* config/i386/cpuid.h (__cpuid, __cpuid_count) [__i386__]: Prefix
	xchg temporary register with %k.  Declare temporary register as
	early clobbered.
	[__x86_64__]: For medium and large code models, preserve %rbx register.


Modified:
    branches/gcc-4_7-branch/gcc/ChangeLog
    branches/gcc-4_7-branch/gcc/config/i386/cpuid.h
    branches/gcc-4_7-branch/gcc/config/i386/i386-c.c
Comment 10 Uroš Bizjak 2013-01-06 09:15:43 UTC
Fixed.