[llvm-dev] difference between --target, -mcpu, -march

Eric Christopher via llvm-dev llvm-dev at lists.llvm.org
Fri Mar 18 14:17:08 PDT 2016


On Fri, Mar 18, 2016 at 1:44 PM Rail Shafigulin <rail at esenciatech.com>
wrote:

>
> On Fri, Mar 18, 2016 at 12:49 PM, Eric Christopher <echristo at gmail.com>
> wrote:
>
>>
>>
>> On Wed, Mar 16, 2016 at 2:53 PM Rail Shafigulin via llvm-dev <
>> llvm-dev at lists.llvm.org> wrote:
>>
>>> I'm confused about the clang --target, -mcpu, -march
>>>
>>> Can someone give a clear explanation on what is the difference between
>>> them?
>>>
>>>
>> I can try :)
>>
>>
>>> Originally I thought need to specify -mcpu (which I assume means CPU)
>>> and -march but then I can't figure out how --target fits into the picture.
>>> Sometimes it tells me that -march or -mcpu options is not used. I would
>>> really appreciate any help on this.
>>>
>>>
>> Let's say you're on an x86_64-linux-gnu machine (basically any linux
>> machine) and you want to compile some code for a haswell specific binary,
>> you'd use:
>>
>> clang -march=haswell foo.c
>>
>> Which tells clang to use the current host as the "OS" for your compile
>> and to tell the backend to generate haswell specific code.
>>
>> Let's say you instead want to compile for arm-linux-gnu (just your basic
>> arm linux machine), you'd use:
>>
>> clang -target arm-linux-gnu foo.c <some other options>
>>
>> I'm glossing over this a bit because it's not relevant to what you asked,
>> but the other options there are going to be things like a sysroot where you
>> can get the headers and libraries for an arm-linux-gnu machine, because
>> they're likely not installed on your x86_64-linux-gnu machine.
>>
>> Now, let's say you want to target a specific arm processor as part of
>> your cross compile, you'd do this:
>>
>> clang -target arm-linux-gnu foo.c -mcpu=armv7
>>
>> or you could do this:
>>
>> clang -target armv7-linux-gnu foo.c
>>
>> this is partially because of legacy reasons, and partially because arm is
>> weird here. The -mcpu and -march options are very similar in clang. In
>> general, they're setting the processor you're compiling your code to run
>> on. (Arm is even weirder here so I'm glossing over a lot of details).
>>
>> The reasons behind this are largely historical and option compatibility
>> with gcc. If you've done cross compilation with gcc all that the --target
>> option does in clang is select at runtime the same thing that you'd use
>> --target for on the configure line.
>>
>> Make sense?
>>
>> -eric
>>
>
> It somewhat makes sense. Basically one has to know very well what options
> to use for their specific target. It looks like at the moment there is no
> consistency.
>

-Most- targets use -march.

-eric


>
>
> --
> Rail Shafigulin
> Software Engineer
> Esencia Technologies
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160318/003ac68c/attachment.html>


More information about the llvm-dev mailing list