#2675 closed defect (fixed)
[PATCH] x86_x64.cpp fails to build with -fpie on i386
Reported by: | pstumpf | Owned by: | historic_bruno |
---|---|---|---|
Priority: | Should Have | Milestone: | Alpha 18 |
Component: | Core engine | Keywords: | patch |
Cc: | Patch: |
Description (last modified by )
The cpuid assembler stuff does not compile when using PIE on i386 due to register constraints. One must save and restore the PIC register (%ebx) before and after the call. See also cpuid.h as provided by GCC or Clang.
In all other cases (amd64 and !PIE i386), use the regular code.
Compile and runtime tested on OpenBSD/i386, which uses -fpie by default.
-
x86_x64.cpp
49 49 #if defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 150030729 50 50 // VC10+ and VC9 SP1: __cpuidex is already available 51 51 #elif GCC_VERSION 52 # if defined(__i386__) && defined(__PIC__) 52 53 # define __cpuidex(regsArray, level, index)\ 54 __asm__ __volatile__ ("pushl %%ebx\n" \ 55 " cpuid\n"\ 56 "mov %%ebx,%1\n" \ 57 "popl %%ebx" \ 58 : "=a" ((regsArray)[0]), "=r" ((regsArray)[1]), "=c" ((regsArray)[2]), "=d" ((regsArray)[3])\ 59 : "0" (level), "2" (index)); 60 # else 61 # define __cpuidex(regsArray, level, index)\ 53 62 __asm__ __volatile__ ("cpuid"\ 54 63 : "=a" ((regsArray)[0]), "=b" ((regsArray)[1]), "=c" ((regsArray)[2]), "=d" ((regsArray)[3])\ 55 64 : "0" (level), "2" (index)); 65 # endif 56 66 #else 57 67 # error "compiler not supported" 58 68 #endif
Attachments (1)
Change History (9)
by , 10 years ago
comment:1 by , 10 years ago
Keywords: | unanswered added |
---|
comment:2 by , 10 years ago
Description: | modified (diff) |
---|---|
Keywords: | patch review added; unanswered removed |
Milestone: | Backlog → Alpha 18 |
Summary: | x86_x64.cpp fails to build with -fpie on i386 → [PATCH] x86_x64.cpp fails to build with -fpie on i386 |
comment:3 by , 10 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:5 by , 10 years ago
Keywords: | review removed |
---|
Thanks! I used your patch and this ticket as inspiration, and combined with an old cpuid.h from GCC (one that is GPLv2, the newer ones are GPLv3). It also fixes the problem I had with 32-bit builds on OS X 10.6, where PIC is used by default.
comment:7 by , 10 years ago
Does this work with cross compiling? I'm getting errors when targeting i386 (running on iPhone simulator on OS X) though the system and CPU are x86-64. The previous code worked fine.
x86_x64.cpp(203): Function call failed: return value was -130002 (Unknown error (-130002, 0xFFFFFFFFFFFE042E)) Function call failed: return value was -130002 (Unknown error (-130002, 0xFFFFFFFFFFFE042E)) Location: x86_x64.cpp:203 (InitVendor)
vendorString contains some garbage, like "Lg{ineIntel"
.
Hi, please follow the instructions when submitting patches: SubmittingPatches