When I compile a program, will the binary be CPU dependant?

The place to post if you need help or advice

Moderators: ChrisThornett, LXF moderators

When I compile a program, will the binary be CPU dependant?

Postby Haakin » Tue Jun 21, 2005 9:49 am

Hello!

This is my first entry in this forum and English is not my mother tongue so, please, be indulgent.

I have this silly question. When I compile a program usually I do:

./configure
make
checkinstall

instead of make install. I'll do that to create an RPM because it will be a lot easier to remove the program in the future. When I compile a program in my PC (1 GHz AMD CPU, ./configure says that it is an i686), will it work in a PC with a different CPU?

Thanks in advance,

Javier
User avatar
Haakin
LXF regular
 
Posts: 287
Joined: Tue Jun 21, 2005 9:40 am
Location: Lleida (Spain, Europe)

RE: When I compile a program, will the binary be CPU dependa

Postby M-Saunders » Tue Jun 21, 2005 9:55 am

It should do, if it's just configuring for general 686 instructions -- eg -march=i686 instead of -march=athlon-4 or whatever. You can set the CFLAGS and CXXFLAGS environment variables before the ./configure step to make sure:

# export CFLAGS="-O2 -march=i686"
# export CXXFLAGS="-O2 -march=i686"

That'll make all C and C++ code compiled with common 686 CPU instructions rather than anything specific. You could even change that to 'i386' above for absolute maximum compatibility -- will be a slight performance drop though.

M
User avatar
M-Saunders
LXF regular
 
Posts: 2893
Joined: Mon Apr 11, 2005 12:14 pm

RE: When I compile a program, will the binary be CPU dependa

Postby jjmac » Tue Jun 21, 2005 11:59 am

Just to follow on the above,

You cpu will be compatable with anything compiled to its' level and below. But not to something compiled for a cpu above its' level. So for yours , an i686 compatible amd processor, that would be ...

i386, i486, i586 and i586

Are you thinking of any particular processor ?


jm
http://counter.li.org
#313537

The FVWM wm -=- www.fvwm.org -=-

Somebody stole my air guitar, It happened just the other day,
But it's ok, 'cause i've got a spare ...
jjmac
LXF regular
 
Posts: 1996
Joined: Fri Apr 08, 2005 1:32 am
Location: Sydney, Australia

RE: When I compile a program, will the binary be CPU dependa

Postby Haakin » Tue Jun 21, 2005 2:15 pm

No, I'm not. It's pure and simple curiosity.

I compile software when I cannot find a binary for my distro (SUSE 9.2), as Octave. I don't share these binaries.

In my box I need several hours to compile Octave. So, I was thinking if the RPM I got will be compatible with other CPUs. In that case I could just install my RPM instead of compiling it in every machine.

After running ./configure, one of the outputs is:
"Octave is now configured for i686-pc-linux-gnu"

So, I understand that the program will be compatible with i686 CPUs. To make sure that is compatible with i586 I should use:

# export CFLAGS="-O2 -march=i586"
# export CXXFLAGS="-O2 -march=i586"

Have I understood it?

Thanks for your help,

Javier
English is not my mother tongue. So, be ready to read bad grammar and limited vocabulary :-(
User avatar
Haakin
LXF regular
 
Posts: 287
Joined: Tue Jun 21, 2005 9:40 am
Location: Lleida (Spain, Europe)

RE: When I compile a program, will the binary be CPU dependa

Postby jjmac » Fri Jun 24, 2005 12:18 pm

The rpms' are usually compiled down to i586 generally anyway, as i remember it. I think some distros will do "-mcpu=i686 -march=i586", deb likes to set it all at "i386" ... If you pipe the compiler output to a file "make 2>&1 |tee make-out" the clis' used should reveal whats going on there. The hint can be seen in the rpm name as well. In that, the file should have its' compile level expressed as part of its' name.

The main thing though is that a cpu is designed to be backward compatable. So, an i686 should run anthing up to and including i686. Which gives you the whole rang. An i585 processor, like a standard pentium, will likely have problems with a program compiled for an i686, but will do i386 to i586.

The "-march=" switch is the sensitive one, if the "-mcpu=" switch isn't given, it will imply it. It will determine the type of cpu level native code to assemple for. So an earlier processor will likely not have the instuctions that the program will want to use, if the compile is above the earlier processors level.

The "-cpu=" swich sets the scheduling level to use. If the processor dosen't have those scheduling levels/coded facilities, then they just wont be used. But it wont interfer with the programming being run. But if they are available, then they can be taken advantage.

If i'm remembering correctly, i think thats why some distros will compile their rpms for a i586 "-march=", but will schedule for an i686 "-mcpu=". That used to confuse me a bit, i would have thought the "-mcpu=" switch was referening to the assembled instuction set, but i was wrong, it is the "-march=" one.

There are other switches that may be used that will imply both. Such as "-mpentium" or is i, "-pentium=" for an i586, "-mathlon", -"athlonk7" etc.

The man and info pages have a lot of stuff on this, but, if you can navigate through those files with getting really irratated, you will be doing well :)


>>
So, I understand that the program will be compatible with i686 CPUs. To make sure that is compatible with i586 I should use:

# export CFLAGS="-O2 -march=i586"
# export CXXFLAGS="-O2 -march=i586"
>>

That will set the assemble micro-code to be of that used by a standard "pentium", it will run on a i586, i686, or any of the athlons. It wont be suitable for anything below an i586, such as i486 or i386. It will also imply the "-mcpu=" scheduling level used should also be for the i586.



jm
http://counter.li.org
#313537

The FVWM wm -=- www.fvwm.org -=-

Somebody stole my air guitar, It happened just the other day,
But it's ok, 'cause i've got a spare ...
jjmac
LXF regular
 
Posts: 1996
Joined: Fri Apr 08, 2005 1:32 am
Location: Sydney, Australia


Return to Help!

Who is online

Users browsing this forum: Exabot [Bot] and 1 guest