Page 2 of 2
Re: Cross-compiler
Posted: Tue Oct 04, 2011 5:40 pm
by gfmoore
It seems from further research that crt0.o is a system file used by the compiler. My standard gcc will compile fine. So has the later version of cygwin moved it, or have I lost the path to it somehow.
I tried to find it, but there's an awful lot of stuff to look through from root! If I did find it, what then?
yawn...bed time.
edit: of course I could easily look for it from windows - doh. I did but couldn't find it, so it is missing?
So how repair fix this issue? What might I have done wrong? Missed some library?
Re: Cross-compiler
Posted: Tue Oct 04, 2011 7:14 pm
by gerryg400
crt0.o is the startup code. It's a little bit of code that initialises the c environment (argc, argv, environ etc.) before calling main. It also usually handles the return from main and calls exit() or similar.
Anyway, if you don't have a c lib and are building an operating system you don't want it. Or you will supply your own. To prevent gcc from looking for the default one you need to use GCC options like this
Re: Cross-compiler
Posted: Tue Oct 04, 2011 11:50 pm
by Solar
The file crt0.o is the platform-dependent support file for user-space executables. Since in OSDev you are building your own platform, and cannot support user-space executables, it is appropriate that the compiler tells you you are in error if you try to build one.
Somewhere down the road of developing your own OS, you will reach the point where you can support user-space executables, and at that point, it will also be very clear to you what exactly your crt0.o needs to do.
Re: Cross-compiler
Posted: Wed Oct 05, 2011 12:44 am
by gfmoore
Excellent. I had tried each switch separately, but not together.
Note for followers of this thread: I also get a warning: cannot find entry symbol _start; defaulting to 08048054.
This seems reasonable, but when I look at the output object using bvi (binary vi) There is a:
!This program cannot be run in DOS mode.
and a lot of other stuff, I'm not sure I want that!
Clearly I need to do more research as to what I'm expecting the cross compiler to produce, because I was expecting pure machine code.
edit: er, I'm being dense. The cross compiler is producing code in ELF format not pure machine code (I think?) Don't bother answering, just being a noob.
Thanks for the help and explanations
Re: Cross-compiler
Posted: Wed Oct 05, 2011 1:36 am
by Solar
gfmoore wrote:!This program cannot be run in DOS mode.
You are looking at an executable
not built by your cross-compiler, as this is a message from the standard Windows runtime files. Check your command line.
Clearly I need to do more research as to what I'm expecting the cross compiler to produce, because I was expecting pure machine code.
Nope. Whether you generate preprocessed source, object code, or executable code; whether you do this with or without userspace runtime etc. is
completely up to the command line options you're using. Check the Wiki and the GCC manuals for details.
What the cross-compiler does is targetting a different
platform. For example, your cross-compiler won't link that code in that says "This program cannot be run in DOS mode" (as it wouldn't know where to find that in the first place). It also doesn't use PE object / executable format, which is the standard for Windows, but ELF (at least if you followed the tutorial). That won't run on Windows, but it's better understood by GRUB, and most of all easily reproducable on other host platforms (i.e. Linuxers here can build the very same object code / executable using
their cross-compilers).
Re: Cross-compiler
Posted: Wed Oct 05, 2011 6:12 am
by gfmoore
doh!
It looks much better when I look at the right executable. Has an ELF in the first few bytes
Sorry for the mistake and thanks for the other help. It is very much appreciated.
I am now reading the next article Bare Bones which makes it much clearer what I am doing, as well as doing more reading about ELF and Multiboot and grub and ...
All this for Hello Gordon lol