LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 05-25-2010, 11:27 AM   #1
Dweeb2010
LQ Newbie
 
Registered: May 2010
Posts: 29

Rep: Reputation: 1
GCC and G++ build results if the -march=TYPE is not specified


Hi. I'm sure this has been covered somewhere before, but I couldn't find anything and so figured I would post here.

I have been using Linux OSes for the past couple of years and also using GCC/G++ for application development. However, I have almost always been on x86 systems and never gained much experience using the wide range of optimization options available.

My question is, if I do not specify the -march=PROCTYPE option, will GCC still be able to detect the current architecture and build the code accordingly? I primarily ask this because I am working with an x86_64 system, and specifying -march=x86_64 in my makefiles generates errors about it being an unknown processor type, even though the CPU and OS are X86_64.

I know this sounds like a newbie question, but it's just ground I've never had to cover before until now. Any advice is appreciated!

Thanks!
 
Old 05-25-2010, 11:37 AM   #2
alunduil
Member
 
Registered: Feb 2005
Location: San Antonio, TX
Distribution: Gentoo
Posts: 684

Rep: Reputation: 61
x86_64 isn't a proper arch type for the march option. If you're using a GCC newer than 4.3 you should be able to use -march=native. For more information on how -march and -m work together I've written a small article on the matter: http://www.alunduil.com/2009/12/18/o...gentoo-cflags/.

Regards,

Alunduil
 
Old 05-25-2010, 11:38 AM   #3
alunduil
Member
 
Registered: Feb 2005
Location: San Antonio, TX
Distribution: Gentoo
Posts: 684

Rep: Reputation: 61
x86_64 isn't a proper arch type for the march option. If you're using a GCC newer than 4.3 you should be able to use -march=native. For more information on how -march and -m work together I've written a small article on the matter: http://www.alunduil.com/2009/12/18/o...gentoo-cflags/.

Regards,

Alunduil
 
Old 05-25-2010, 12:07 PM   #4
Dweeb2010
LQ Newbie
 
Registered: May 2010
Posts: 29

Original Poster
Rep: Reputation: 1
Alunduil, thanks for the swift response! The info and the link were definitely helpful. I believe my previous source that told me x86_64 was valid was outdated.

Something else I was wondering: what happens if the -march option is not specified at all? The code still builds fine without it, but I have no way of telling if it is 32 or 64 bit.

Thanks again!
 
Old 05-25-2010, 01:31 PM   #5
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: washington U.S.
Distribution: Damn Small Linux, KateOs, M$ Ickdows Vista, My own OS
Posts: 2,094

Rep: Reputation: 104Reputation: 104
Try
Code:
file <compiled program>
 
Old 05-25-2010, 02:12 PM   #6
ForzaItalia2006
Member
 
Registered: Dec 2009
Location: Walldorf, Germany
Distribution: (X)Ubuntu, Arch, Gentoo
Posts: 205

Rep: Reputation: 67
Quote:
Originally Posted by Dweeb2010 View Post
Something else I was wondering: what happens if the -march option is not specified at all? The code still builds fine without it, but I have no way of telling if it is 32 or 64 bit.
Assuming that your gcc's backend is x86_64 and you specified the -m64 option to generate 64-bit code, if you don't use the -march= option for gcc/g++, you'll get code generated for a common subset of x86_64 CPUs, meaning that it should run on a wide range (all) of x86_64 systems, but you possibly don't get all the optimizations/features which your specifc (local) CPU provides.

So, gcc always has a default path even if the user doesn't specify a concrete option. :-)

Right, the file command is absolute correct. It will display the ABI used. Just for your interest, the file command looks at the first bytes of the executable to determine what kind of executable format is used and which ABI is used. The default executable format on Linux is ELF and you'll get the ELF-ABI by using

# readelf -h /usr/bin/gcc
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
OS/ABI: UNIX - System V
Type: EXEC (Executable file)
 
Old 05-25-2010, 02:37 PM   #7
alunduil
Member
 
Registered: Feb 2005
Location: San Antonio, TX
Distribution: Gentoo
Posts: 684

Rep: Reputation: 61
That's all great information but I want to specify that the extra instruction sets that modern CPUs might have available are not going to be used at all to get the common CPU instructions that would run on a generic-x86_64.

Regards,

Alunduil
 
Old 05-25-2010, 04:53 PM   #8
ForzaItalia2006
Member
 
Registered: Dec 2009
Location: Walldorf, Germany
Distribution: (X)Ubuntu, Arch, Gentoo
Posts: 205

Rep: Reputation: 67
Oh, sh**! :-) I went through the code and finally found the mistake. Although it isn't (yet) documented in the man page, the correct switch name is -march=x86-64 to get the default setting. The difference between the dash and underscore was just too marginal to catch it in the first instance.

There already was a discussion on the GCC mailing list about the confusion by x86-64 and x86_64 (http://gcc.gnu.org/ml/gcc/2006-03/msg00229.html), but unfortunately without any result why x86_64 isn't allowed.

I think this needs to be changed in the documentation ...

Last edited by ForzaItalia2006; 05-25-2010 at 06:27 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Ubuntu Lucid (10.04) daily build for March 15, 2010 runs with nomodeset on Inte LXer Syndicated Linux News 0 03-16-2010 10:40 PM
[SOLVED] GCC options: (-m64) vs (-march=native) vs (-march=core2) -- Which one(s) to use? GrapefruiTgirl Linux - Software 5 09-29-2009 08:53 AM
Observation of Assembly code produced by GCC 4.3.2 for various -march parameters Mr_Shameless Programming 1 10-25-2008 06:54 AM
A question on GCC march setting satimis Linux - Distributions 1 08-21-2006 11:35 AM
gcc march agdepus Programming 8 05-26-2004 10:11 AM


All times are GMT -5. The time now is 02:09 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration