[llvm-dev] beginner problem with cross compilation

fateme Hoseini via llvm-dev llvm-dev at lists.llvm.org
Tue Nov 3 09:40:11 PST 2015


Bruce, Thank you so much for your help. Now it's clear to me. I am stuck in
implementation phase of my project and I have many questions about LLVM. I
apologize for my long and beginner level.questions.

I've seen many documents on cross-compiling. for example, I have a book
named"Getting Started with LLVM
Core Libraries" It has described several pages on how to cross-compile and
there is a document on http://llvm.org/docs/HowToCrossCompileLLVM.html.
Which document and steps do you recommend? I had many problems in
installing LLVM3.7 and I am worried that following wrong steps might mess
with the LLVM tool and I have to go through installation again.

Also, I have another question. In my project I want to do some optimization
on machine code, i.e, I want to write a pass before code emission phase.
This pass reads machine instructions and do some optimizations on it. for
example it tries to find all register dependencies. I want the input of my
pass to be machine instructions in MIPS. Now my question is that, if I
cross compile llvm for mips, then when I am running pass, will the input of
my pass be in MIPS? I mean we run a pass on a bitcode (whithout running the
llc mrach=MIPS), and bitcode is target independant. How LLVM knows it
should be cross compile to MIPS not x86?

Regards,
Fami

On Tue, Nov 3, 2015 at 3:48 AM, Bruce Hoult <bruce at hoult.org> wrote:

> llc will make an object file with MIPS machine code for only the functions
> in your test.bc. You then need to link it with any MIPS libraries it needs
> (usually at least the C runtime library that calls main() for you etc).
>
> The generated code will have exactly the data types (e.g. integer sizes)
> and struct layouts specified in your test.bc. These might or might not be
> correct for MIPS. If you're running on bare hardware then it's probably ok,
> but if you call library functions then you need to be laying out the data
> in the correct way. If you wrote test.bc yourself then that's your job, but
> usually it's the job of e.g. clang, and you need to also tell clang that
> you're compiling for MIPS (and which ABI) so it does that correctly.
>
> A random .bc file for a similar enough machine might work -- same sizes,
> same padding rules and so forth. But unless you know for sure those are the
> same then chances are good that it won't work.
>
>
> On Mon, Nov 2, 2015 at 11:37 PM, fateme Hoseini via llvm-dev <
> llvm-dev at lists.llvm.org> wrote:
>
>> Hi everyone,
>> I am a new commer and I 'm tying to use LLVM to cross compile a code. I
>> want to cross compile to MIPS and the host is the default x86. The more I
>> read the document the more confused I get. I see documents on
>> cross-compiling to ARM. But some install some gcc packages, while some use
>> clang. I don't know where to start and how to do it.
>> Is this just enough to run a command line like this:
>>
>> llc -march=mips test.bc -o testmips
>>
>> will the testmips file be executable for mips?
>> I will appreciate if anyone help me with this problem.
>> Thanks,
>> Fami
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> llvm-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151103/9718807f/attachment.html>


More information about the llvm-dev mailing list