Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Troubles compiling code with -fPIC
Troubles compiling code with -fPIC [message #40190] Sun, 30 June 2013 21:38 Go to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi everyone,

I've hit a problem when trying to compile a shared library using U++ with -fPIC switch:
/home/h/upp-production/uppsrc/Core/Cpu.cpp: In function 'void Upp::sCheckCPU()':
/home/h/upp-production/uppsrc/Core/Cpu.cpp:40:84: error: PIC register clobbered by '%ebx' in 'asm'
  __asm__("movl $1, %%eax\n\tcpuid" : "=d" (info1), "=c" (info2) : : "%eax", "%ebx");

As the error message says, the problem is caused by changing a value of ebx register. After a little googling, I found that the widely used fix in this situation is to store the value of ebx before calling cpuid instruction and restore it afterwards. When I looked into the code of SCheckCpu() to do that, to my great surprise I found the code was already there, just commented out Smile

So my question is, does anyone remember if there was some valid reason to comment this line out? If not, I propose to start using it:
Index: /home/h/upp-production/uppsrc/Core/Cpu.cpp
===================================================================
--- /home/h/upp-production/uppsrc/Core/Cpu.cpp  (revision 6151)
+++ /home/h/upp-production/uppsrc/Core/Cpu.cpp  (working copy)
@@ -15,7 +15,6 @@
        if(done) return;
        done = true;
 #ifdef PLATFORM_OSX11
-//     __asm__("pushl %%ebx\n\tmovl $1, %%eax\n\tcpuid\n\tpopl %%ebx" : "=d" (info1), "=c" (info2) : : "%eax");
        sHasMMX = true;
        sHasSSE = true;
        sHasSSE2 = true;
@@ -37,7 +36,7 @@
 #else
        dword info1;
        dword info2;
-       __asm__("movl $1, %%eax\n\tcpuid" : "=d" (info1), "=c" (info2) : : "%eax", "%ebx");
+       __asm__("pushl %%ebx\n\tmovl $1, %%eax\n\tcpuid\n\tpopl %%ebx" : "=d" (info1), "=c" (info2) : : "%eax");
 #endif
        sHasMMX = ((info1 >> 23) & 0x1);
        sHasSSE = ((info1 >> 25) & 0x1);

With this patch my code compiles and I noticed no difference for other programs.

Best regards,
Honza
Re: Troubles compiling code with -fPIC [message #40191 is a reply to message #40190] Mon, 01 July 2013 08:46 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
This really weird. Not when it was commented out, but my guess is it is commented out since the beginning:

The part of code is for MacOS X, X11 subsystem. Macs always have CPUs that support MMX/SSE/SSE2, so there is no point to call assembler to find out... so all assembly code is #ifdefed out... I doubt that adding some back is the cause of -fPIC problems...

Mirek
Re: Troubles compiling code with -fPIC [message #40192 is a reply to message #40191] Mon, 01 July 2013 08:49 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Ah, now I see - patch moves that line too. Applied.
Re: Troubles compiling code with -fPIC [message #40193 is a reply to message #40192] Mon, 01 July 2013 12:15 Go to previous message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

mirek wrote on Mon, 01 July 2013 08:49

Ah, now I see - patch moves that line too. Applied.

Yes, I deleted it from Mac and used it for i386... Sorry for confusion and thanks for applying the patch.

Honza
Previous Topic: Vector performance on a specific situation
Next Topic: SetSysTime() or SetUtcTime()
Goto Forum:
  


Current Time: Fri Apr 19 08:19:32 CEST 2024

Total time taken to generate the page: 0.03194 seconds