Hi list, I want to use LLVM to compile the C code to arm. Host: Mac OS X 10.10 Target: Pandaboard, armv7l, ubuntu I found some useful information but not worked yet. I tried like this: $ clang -fomit-frame-pointer -ggdb -emit-llvm --target=armv7l-unknown-linux-eabi -mcpu=cortex-a9 —mfpu=neon -mfloat-abi=softfp --sysroot=/... test.c -c -o test.bc --> clang-3.5: error: no such file or directory: '—mfpu=neon' clang-3.5: error: -emit-llvm cannot be used when linking clang-3.5: error: no such file or directory: '—-sysroot=...' when I tried like this: $ clang -fomit-frame-pointer -ggdb -emit-llvm --target=armv7l-unknown-linux-eabi -mcpu=cortex-a9 test.c -c -o test.bc It worked. Then I did: $ llc test.bc -o test.s And sent the test.s to the pandaboard. On the board, I did: $ as -o test.o test.s $ ld -e main -o a.out test.o $ ./a.out --> Segmentation fault (core dumped) This is what I got. The test.c is very simple. Even like int main(){ int i=0; return 0; } Still no work. BTW, someone said: Toolchain on host : sudo apt-get install gcc-arm-linux-gnueabi How to realize this in MacOS?(port or brew)? I also found something here: https://launchpad.net/gcc-arm-embedded/+download . Is this the same thing or not? Does anyone know how to cross-compile from MacOS to arm? Or tell me what's wrong with my operations! Any suggestion or information is appreciated! Thanks, Hanbing -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20141106/767b6e8c/attachment.html>
Hi Hanbing, On 6 November 2014 09:21, Hanbing Li <hanbing.li at inria.fr> wrote:> clang-3.5: error: no such file or directory: '—mfpu=neon' > clang-3.5: error: no such file or directory: '—-sysroot=...'I suspect these are copy/paste errors, with some overzealous tool converting an ASCII hyphen to some kind of unicode n-dash (U+2013) or similar. Then LLVM thinks they're files rather than options.> clang-3.5: error: -emit-llvm cannot be used when linkingAs you discovered, "-c" is the solution here (or one solution anyway). I'm not quite sure why you're trying to do it in so many steps though; for educational purposes? Another point is that the triple you're using looks weird. LLVM is certainly ignoring the "v7l" part (it doesn't know anything about 'l' as a variant). Also, the usual Linux triples are "armv7-linux-gnueabi" (which does softfp automatically) and "armv7-linux-gnueabihf" (which uses the hard-float ABI). While you could probably create a "linux-eabi" system, I'm not aware of any (it affects things like the names of compiler support functions).> $ ld -e main -o a.out test.oIf you are running on Linux, main is almost certainly not the entry point. Usually there's a function _start in one of the crt*.o files that performs necessary setup and tidying. Skipping it could well account for the segfault. The compiler normally knows how to tell the linker what to do about this. So I'd put one on the panda board itself and use that: $ gcc test.o -o a.out (or clang, of course!)> Does anyone know how to cross-compile from MacOS to arm? Or tell me what's > wrong with my operations!You'll probably have a bit of an up hill struggle (most cross-Linux developers use Linux, so that's what the documentation, such as it is, assumes). Have you considered using a Linux virtual machine on your Mac for this project?> Any suggestion or information is appreciated!I'd probably suggest letting clang do the entire compilation in one step: $ clang -target armv7-linux-gnueabi test.c -o a.out You'll need a full target toolchain for this to work (the gcc-arm-linux-gnueabi someone mentioned to you), so it's initially harder than just getting a .s out of clang and doing the rest on the Panda. But you're going to hit those problems anyway as soon as you want to "#include <stdio.h>": the version that comes with your Mac will almost certainly make things go horribly wrong in weird ways. Cheers. Tim.
Hi Tim, Thank you very much. Following your suggestion, I have gotten an executable a.out on pandaboard! Thank you. Sincerely, Hanbing ----- Mail original -----> De: "Tim Northover" <t.p.northover at gmail.com> > À: "Hanbing Li" <hanbing.li at inria.fr> > Cc: "LLVM Developers Mailing List" <llvmdev at cs.uiuc.edu> > Envoyé: Jeudi 6 Novembre 2014 18:46:47 > Objet: Re: [LLVMdev] Cross-compiler to arm > > Hi Hanbing, > > On 6 November 2014 09:21, Hanbing Li <hanbing.li at inria.fr> wrote: > > clang-3.5: error: no such file or directory: '—mfpu=neon' > > clang-3.5: error: no such file or directory: '—-sysroot=...' > > I suspect these are copy/paste errors, with some overzealous tool > converting an ASCII hyphen to some kind of unicode n-dash (U+2013) or > similar. Then LLVM thinks they're files rather than options. > > > clang-3.5: error: -emit-llvm cannot be used when linking > > As you discovered, "-c" is the solution here (or one solution anyway). > I'm not quite sure why you're trying to do it in so many steps though; > for educational purposes? > > Another point is that the triple you're using looks weird. LLVM is > certainly ignoring the "v7l" part (it doesn't know anything about 'l' > as a variant). > > Also, the usual Linux triples are "armv7-linux-gnueabi" (which does > softfp automatically) and "armv7-linux-gnueabihf" (which uses the > hard-float ABI). While you could probably create a "linux-eabi" > system, I'm not aware of any (it affects things like the names of > compiler support functions). > > > $ ld -e main -o a.out test.o > > If you are running on Linux, main is almost certainly not the entry > point. Usually there's a function _start in one of the crt*.o files > that performs necessary setup and tidying. Skipping it could well > account for the segfault. > > The compiler normally knows how to tell the linker what to do about > this. So I'd put one on the panda board itself and use that: > > $ gcc test.o -o a.out > > (or clang, of course!) > > > Does anyone know how to cross-compile from MacOS to arm? Or tell me what's > > wrong with my operations! > > You'll probably have a bit of an up hill struggle (most cross-Linux > developers use Linux, so that's what the documentation, such as it is, > assumes). Have you considered using a Linux virtual machine on your > Mac for this project? > > > Any suggestion or information is appreciated! > > I'd probably suggest letting clang do the entire compilation in one step: > > $ clang -target armv7-linux-gnueabi test.c -o a.out > > You'll need a full target toolchain for this to work (the > gcc-arm-linux-gnueabi someone mentioned to you), so it's initially > harder than just getting a .s out of clang and doing the rest on the > Panda. But you're going to hit those problems anyway as soon as you > want to "#include <stdio.h>": the version that comes with your Mac > will almost certainly make things go horribly wrong in weird ways. > > Cheers. > > Tim. >