Author Topic: Cross-compiling  (Read 8779 times)

0 Members and 1 Guest are viewing this topic.

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9448
Re: Cross-compiling
« Reply #15 on: April 11, 2011, 10:12:38 PM »
Ah, thats too bad Paul.

Well, i just got both Windows and Linux GNU versions working. I tested on some existing C++ code (I didnt even try any Qt stuff though). 2.9 works awesome for straight C++ so i may just keep using it as my main compiler for C++ (but im not you guys though).

The whole concept behind/about LLVM is still a bit "magical"# for me (especially when it comes to this "intermediate representation" and "JIT" stuff) but im really kind of excited to learn a bit more.

# I mean "magical" as in: "magic all up in this b|7c4".
*lol* Ive been waiting to use this link (I peed myself a little when I saw this):

http://www.youtube.com/watch?v=_-agl0pOQfs
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

pkohut

  • Bull Frog
  • Posts: 433
Re: Cross-compiling
« Reply #16 on: April 12, 2011, 01:42:21 AM »
I haven't kept up with LLVM much because I kept hoping that Apple would release a newer version of GCC with XCode, Then a couple months ago I heard / read that Apple was no longer going to support GCC past 4.2 (article might have been at least a year old). That prompted me to do some research about LLVM, however at the time 2.8 had just been released. So hope turned to waiting for Apple to turn on the C++0x features, and still waiting. Here is some resent benchmarks between GCC 4.5.2, GCC 4.6.0rc2, LLVM 2.9svn, and Dragon Egg svn. http://www.phoronix.com/scan.php?page=article&item=gcc_46_llvm29&num=1
Note that Dragon Egg has some serious optimization going on for some of the tests, while Clang/LLVM is a slug in some (and could not build the 7 Zip package).

In the meantime, for checking newer snapshots of GCC, I run a modified script of gcc-config.mk (http://www.advogato.org/person/redi/diary.html?start=229). The original script works well in Linux Mint 10, Fedora 14 (that's what I use). For OS X 10.6x it needs modification because of incompatible versions of zcat. For OS X, change "zcat" to "gzcat" (available via source code or MacPorts), then use "make -f [**your configuration***]".

This will download a snapshot of GCC and the required dependencies GMP, MPFR, MPC. Then build it all. Really simplifies the whole process, especially the dependency part as that is a hell to try and get setup correctly with the trial and error method.

I've modified the script some more to download the latest from the GCC SVN trunk. Basically
Code: [Select]
GCC_VERSION := 4.6.0
CONFIGARGS :=--prefix=/home/paul/gcc4.6-bin --program-suffix=-4.6.0-ns
MIRROR := ftp://mirrors.ecvps.com/gnu/gcc
url_gcc_release_  := ${MIRROR}/gcc-${GCC_VERSION}
url_mpfr_ := http://ftp.heanet.ie/mirrors/ftp.gnu.org/gnu/mpfr/
program suffix x.x.x-ns is to remind me the version is not stable.
changed url_mpfr to a mirror as the site was recently down for a while.
Afterwards, run "gmake -f", and again with the gzcat mod it will work in OS X too.

On my Q6600 with the -j4 option for gmake, it takes about 20 minutes to complete from scratch. Snagging resent updates and compiling takes just a couple minutes.
« Last Edit: April 12, 2011, 01:49:52 AM by pkohut »

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9448
Re: Cross-compiling
« Reply #17 on: April 12, 2011, 08:46:56 AM »
Makefiles are cool.

Off topic: Ive been reading the LLVM/Clang docs last night and today and i really wish i was that articulate. These guys are really good.  Ive heard that they have something like a 2:1 (documentation:coding) rule but i dont know how they can get all these meeting notes, tutorials, docs, and code done. The amount of documentation is INSANE!
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9448
Re: Cross-compiling
« Reply #18 on: April 12, 2011, 10:34:30 PM »
Could someone give this a try (I created this in C++ and compiled this on Linux with llvm-2.9).  In the zip attached is the "assembly" file produced from LLVM/Clang. It is a simple HelloWorld app (std::cout << "HelloWorld!").

Compile it like:
g++ HelloWorld.s -o Hello

Use it like:
./Hello
> Hello World!

./Hello -h
> blah, blah, blah

./Hello -l
> more blah, blah, blah
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

pkohut

  • Bull Frog
  • Posts: 433
Re: Cross-compiling
« Reply #19 on: April 12, 2011, 10:56:01 PM »
No worky <<edit: tried with 32 and 64 bit switches. Also, tried with "as" and "ld", which failed to link (output below) >>
<<edit2: gasm will not assemble with 64 bit switch while 32 bit  switch will. This OS is 64 bit and does not have the 32 bit libs to link against>>

Code: [Select]
paul@minty ~/Downloads/Seven $ g++ --version
g++ (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

paul@minty ~/Downloads/Seven $ g++ HelloWorld.s -o Hello
HelloWorld.s: Assembler messages:
HelloWorld.s:11: Error: invalid instruction suffix for `call'
HelloWorld.s:15: Error: invalid instruction suffix for `call'
HelloWorld.s:34: Error: invalid instruction suffix for `call'
HelloWorld.s:38: Error: invalid instruction suffix for `call'
HelloWorld.s:41: Error: invalid instruction suffix for `call'
HelloWorld.s:44: Error: invalid instruction suffix for `call'
HelloWorld.s:47: Error: invalid instruction suffix for `call'
HelloWorld.s:50: Error: invalid instruction suffix for `call'
HelloWorld.s:53: Error: invalid instruction suffix for `call'
HelloWorld.s:56: Error: invalid instruction suffix for `call'
HelloWorld.s:59: Error: invalid instruction suffix for `call'
HelloWorld.s:62: Error: invalid instruction suffix for `call'
HelloWorld.s:86: Error: invalid instruction suffix for `call'
HelloWorld.s:93: Error: invalid instruction suffix for `call'
HelloWorld.s:102: Error: invalid instruction suffix for `call'
HelloWorld.s:105: Error: invalid instruction suffix for `call'
HelloWorld.s:133: Error: invalid instruction suffix for `call'
HelloWorld.s:151: Error: invalid instruction suffix for `call'
HelloWorld.s:172: Error: invalid instruction suffix for `call'
HelloWorld.s:174: Error: invalid instruction suffix for `call'
HelloWorld.s:178: Error: invalid instruction suffix for `call'
HelloWorld.s:180: Error: invalid instruction suffix for `call'
HelloWorld.s:186: Error: invalid instruction suffix for `call'
HelloWorld.s:190: Error: invalid instruction suffix for `call'
HelloWorld.s:192: Error: invalid instruction suffix for `call'
HelloWorld.s:204: Error: invalid instruction suffix for `push'
HelloWorld.s:219: Error: invalid instruction suffix for `call'
HelloWorld.s:223: Error: invalid instruction suffix for `call'
HelloWorld.s:228: Error: invalid instruction suffix for `call'
HelloWorld.s:231: Error: invalid instruction suffix for `call'
HelloWorld.s:234: Error: invalid instruction suffix for `pop'
HelloWorld.s:255: Error: invalid instruction suffix for `call'
HelloWorld.s:270: Error: invalid instruction suffix for `push'
HelloWorld.s:274: Error: invalid instruction suffix for `pop'
HelloWorld.s:296: Error: invalid instruction suffix for `call'
HelloWorld.s:348: Error: invalid instruction suffix for `call'

Code: [Select]
paul@minty ~/Downloads/Seven $ as --32 -o Hello.o HelloWorld.s
paul@minty ~/Downloads/Seven $ ld -melf_i386 -o Hello Hello.o
ld: warning: cannot find entry symbol _start; defaulting to 00000000080480a0
Hello.o: In function `__cxx_global_var_init':
HelloWorld.bc:(.text+0xb): undefined reference to `std::ios_base::Init::Init()'
HelloWorld.bc:(.text+0x13): undefined reference to `__dso_handle'
HelloWorld.bc:(.text+0x22): undefined reference to `std::ios_base::Init::~Init()'
HelloWorld.bc:(.text+0x27): undefined reference to `__cxa_atexit'
Hello.o: In function `print_version(char const*)':
HelloWorld.bc:(.text+0x46): undefined reference to `std::cout'
HelloWorld.bc:(.text+0x4b): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
HelloWorld.bc:(.text+0x5b): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
HelloWorld.bc:(.text+0x6b): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
HelloWorld.bc:(.text+0x7b): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
HelloWorld.bc:(.text+0x8b): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
Hello.o:HelloWorld.bc:(.text+0x9b): more undefined references to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' follow
Hello.o: In function `print_version(char const*)':
HelloWorld.bc:(.text+0xab): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char)'
HelloWorld.bc:(.text+0xba): undefined reference to `std::cout'
HelloWorld.bc:(.text+0xbf): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
HelloWorld.bc:(.text+0xce): undefined reference to `std::cout'
HelloWorld.bc:(.text+0xd3): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
HelloWorld.bc:(.text+0xe2): undefined reference to `std::cout'
HelloWorld.bc:(.text+0xe7): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
Hello.o: In function `print_char_array(char**)':
HelloWorld.bc:(.text+0x11b): undefined reference to `std::cout'
HelloWorld.bc:(.text+0x120): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char)'
HelloWorld.bc:(.text+0x139): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
HelloWorld.bc:(.text+0x151): undefined reference to `std::cout'
HelloWorld.bc:(.text+0x156): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char)'
HelloWorld.bc:(.text+0x166): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char)'
Hello.o: In function `main':
HelloWorld.bc:(.text+0x194): undefined reference to `std::cout'
HelloWorld.bc:(.text+0x199): undefined reference to `std::cout'
HelloWorld.bc:(.text+0x200): undefined reference to `getopt_long'
HelloWorld.bc:(.text+0x236): undefined reference to `exit'
HelloWorld.bc:(.text+0x24e): undefined reference to `exit'
HelloWorld.bc:(.text+0x263): undefined reference to `exit'
HelloWorld.bc:(.text+0x272): undefined reference to `std::cout'
HelloWorld.bc:(.text+0x277): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
HelloWorld.bc:(.text+0x283): undefined reference to `exit'
« Last Edit: April 12, 2011, 11:21:24 PM by pkohut »

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9448
Re: Cross-compiling
« Reply #20 on: April 13, 2011, 07:02:15 AM »
Damn! There goes that idea. Thanks for trying.
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org