Hi,
Well - I finally managed to build a Cross Compiler (2, in fact - one 32 bit elf and one 64 bit elf) thanks to the wiki. All those problems I had before must have been a dodgy cygwin install because the configure process always failed when it tried to read from makefile.in. Still unsure why, though. I just have a couple of questions now, though:
1) Does this mean I don't have to worry about compiler directives such as -fnostartfiles -nostdinc and the like, seeing as I haven't written the start files or got any standard library yet?
2) As I am now using ELF as default, can I forget about a linker script (it doesn't matter wherer everything is linked, as I can just jump to the ELF entry point by reading the appropriate header value)?
3) When I build my standard lib, should it 'just work' as long as I put it in C:\cygwin\usr\cross\i586-elf\lib or do I still have to use the -I directive for g++ and the -L directive for ld to let them know where to find my standard headers and libc.a respectively?
As far as I can see, the above points should be some of the benefits of building a cross compiler so sorry if the answers are obvious.
Cheers,
Adam
Adding Library Support to my Cross-Compiler
Eh.. the 64bit version supports 32bit by compiling with -m32 so you only need one.Well - I finally managed to build a Cross Compiler (2, in fact - one 32 bit elf and one 64 bit elf) thanks to the wiki.
As for your questions. I would treat the cross-compiler the same as a normal compiler. If at one point your cross-compiler becomes your OS native compiler with the library support and RTTI and such, you wont need to change the build scripts.
Author of COBOS
Link script can be dumped. I never used one anyway, just used linux-default.
As long as you configured it correctly (I had to add --with-ld=/usr/jimix/bin/i586-pc-ld for g++ to pick up the correct linker) your X-compiler will pick up your libc. Things to note are some files are NEEDED - if you compile without -nostdlib the link will fail unless ALL of these are present:
* crtbegin.o
* crt0.o
* crtend.o // might be called something different - can't quite remember
* libc.a // all libraries can be .a or .so
* libstdc++.a // If you're using C++
the easiest way is just to 'touch' (i.e. create blank files with these names) them all. crt0.o and libc.a are the ones you'll be interested in - just symlink them to to your working directory et voila!
The best thing about this is it's SOO much easier to port autoconf'd tools - configure.in actually picks a lil' bit of your configuration up instead of printing tons of crap then dying...
As long as you configured it correctly (I had to add --with-ld=/usr/jimix/bin/i586-pc-ld for g++ to pick up the correct linker) your X-compiler will pick up your libc. Things to note are some files are NEEDED - if you compile without -nostdlib the link will fail unless ALL of these are present:
* crtbegin.o
* crt0.o
* crtend.o // might be called something different - can't quite remember
* libc.a // all libraries can be .a or .so
* libstdc++.a // If you're using C++
the easiest way is just to 'touch' (i.e. create blank files with these names) them all. crt0.o and libc.a are the ones you'll be interested in - just symlink them to to your working directory et voila!
The best thing about this is it's SOO much easier to port autoconf'd tools - configure.in actually picks a lil' bit of your configuration up instead of printing tons of crap then dying...
Yes you can, although I wouldn't recommend it for your kernel, otherwise both your kernel and user programs will link with the same start address for the text section (specifically 0x08048000 as specified in emulparams/elf_i386.sh).AJ wrote:2) As I am now using ELF as default, can I forget about a linker script (it doesn't matter wherer everything is linked, as I can just jump to the ELF entry point by reading the appropriate header value)?
JamesM is basically right on the extra files you need. Its useful to have a crt0, crtbegin and crtend once you start compiling user mode programs (and obviously libc is pretty important too). Basically, crtbegin and crtend are included by the default elf_i386 linker script to delimit the start and end of the C++ constructors/destructors, and is usually provided by gcc. crt0 is usually system-provided and is important in setting up the environment for the user mode program (e.g. default signal handlers, the argv array etc). Libstdc++ is useful for C++ (and includes libsupc++ used in exception handling and rtti)
I have provided an example of creating a binutils/gcc/newlib toolchain that you can customise for your os at OS Specific Toolchain. Following those instructions, everything seemed to install itself to the correct directories, so you could link through gcc without any -I or -L options being required. Passing the -nostdlib option to that prevents the use of all these files so is useful for a kernel (although personally I reinclude -lgcc and -lsupc++).
Regards,
John.