Opened 10 years ago

Last modified 3 years ago

#2675 closed defect

x86_x64.cpp fails to build with -fpie on i386 — at Initial Version

Reported by: pstumpf Owned by:
Priority: Should Have Milestone: Alpha 18
Component: Core engine Keywords: patch
Cc: Patch:

Description

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.orig.port Tue Dec 27 15:12:31 2011 +++ x86_x64.cpp Sun Jul 13 22:47:33 2014 @@ -49,10 +49,20 @@

#if defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 150030729 VC10+ and VC9 SP1: cpuidex is already available #elif GCC_VERSION

+# if defined(i386) && defined(PIC)

# define cpuidex(regsArray, level, index)\

+ asm volatile ("pushl %%ebx\n" \ + " cpuid\n"\ + "mov %%ebx,%1\n" \ + "popl %%ebx" \ + : "=a" ((regsArray)[0]), "=r" ((regsArray)[1]), "=c" ((regsArray)[2]), "=d" ((regsArray)[3])\ + : "0" (level), "2" (index)); +# else +# define cpuidex(regsArray, level, index)\

asm volatile ("cpuid"\ : "=a" ((regsArray)[0]), "=b" ((regsArray)[1]), "=c" ((regsArray)[2]), "=d" ((regsArray)[3])\ : "0" (level), "2" (index));

+# endif

#else # error "compiler not supported" #endif

Change History (1)

by pstumpf, 10 years ago

Attachment: diff added
Note: See TracTickets for help on using tickets.