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
Created attachment 29038 [details] Save rbx and use another file for ebx parameter to cpuid
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
Created attachment 29039 [details] Patch that uses other register than rbx for cpuid.
Please try patch at [1] [1] http://gcc.gnu.org/ml/gcc-patches/2012-12/msg01391.html
Confirmed to work with medium memory model (x86_64-pc-rdos).
Created attachment 29053 [details] Patch that preserves %rbx over cpuid insn Alternative patch that avoids changing %rbx PIC register.
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
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
Fixed.