Page 1 of 2
Running GeekOs on a Mac (Qemu, cross-compiler) [SOLVED]
Posted: Thu Oct 25, 2007 9:46 pm
by Pixion
Hi,
Anyone can give me a hand on how to get GeekOs to build and run under Qemu?
I started off with building binutils and gcc (target: i386-pc-elf).
I then tried to compile the bkerndev tutorial (very short nonfunctioning kernel, but ver instructive). All gcc steps went fine, as well as assembling using NASM, but in the final linking step, i386-pc-elf-ld did not recognize the NASM assembled file format (I tried assembling both as aout and elf).
If this linking step is not working, I am sure Geekos won't build.
-Is there a way to check the format of the compiled/assembled *.o files to see if they are in the right (elf) format?
-And/or should I have set the target to i386-elf when building the chain? I noticed some folks talk about the 'i386-elf-gcc compiler'...
Thanks!
Sebastian
Posted: Fri Oct 26, 2007 1:23 am
by JamesM
Hi,
1) What is GeekOS? Is this the codename for your own OS? (you don't mention it anywhere
)
2) Please post the output of the link command, also your compile/link commands themselves, then we can help you.
3) If you liked Bran's dev tutorials, you could possibly try
http://www.jamesmolloy.co.uk, those tutorials initially cover the same stuff in a similar way then move on to other things like paging and a kernel heap (working on a VFS and initrd now). Might help you.
Cheers,
JamesM
Posted: Fri Oct 26, 2007 2:20 am
by ucosty
Posted: Fri Oct 26, 2007 3:08 am
by Combuster
-And/or should I have set the target to i386-elf when building the chain? I noticed some folks talk about the 'i386-elf-gcc compiler'...
I'd have expected i586-elf, since that's used in the
GCC Cross-Compiler tutorial. Even though that one is written against cygwin, it works under linux and might therefore do as well on a mac. It should at least give you the correct configure options etc.
That said, I do use a i386-elf myself (without the -pc-) but its built the same way as in the tutorial above.
Posted: Fri Oct 26, 2007 9:45 am
by Pixion
Thanks for the replies.
I found a number of posts on this site that describe the use of a cross compiler for Brian's kernel tutorials. I will try those points first.
But, a target=i386-pc-elf should give the same build as target=i386-elf for binutils and gcc?
Thanks,
Sebastian
Posted: Fri Oct 26, 2007 9:51 am
by JamesM
The mac linker is notorious for being crap. Are you sure your ported toolchain is actually calling the *ported linker*? If you missed a $PREFIX somewhere it'll just call /usr/bin/ld...
Posted: Fri Oct 26, 2007 10:04 am
by Pixion
JamesM,
I used the following commands for build/install (both for binutils and gcc, the latter with some further restrictions):
./configure --target=i386-pc-elf --pefix=/usr/local/elf
make
make install
All tools are in /usr/local/elf. I added the underying bin to my PATH and I can invoke the Xcompiler using i386-pc-elf-gcc.
However, when compiling an empty prog (no includes, no lib functions, just void main(){}), during the linker step it complains about a missing *.o file. In the error message it says it looked in the /usr/local/elf/bin/../../ directories, so it is probably well installed. I think this could be a required precompiled library or glue(?) code, which I don't have.
Do you think there is a difference between target=i386-pc-elf and target=i386-elf?
Thanks!
Sebastian
Posted: Fri Oct 26, 2007 10:33 am
by JamesM
...well could you post the error message?
Posted: Fri Oct 26, 2007 10:39 am
by Pixion
I will, but need to switch OS first...
Posted: Fri Oct 26, 2007 10:45 am
by Pixion
I will, but need to switch OS first...
Posted: Fri Oct 26, 2007 4:08 pm
by Pixion
JamesM,
Here the error I got after compiling an empty program (void main(){}):
Code: Select all
s-s-computer:~/Desktop ss$ i386-pc-elf-gcc main.c
/usr/local/elf/lib/gcc/i386-pc-elf/4.2.1/../../../../i386-pc-elf/bin/ld: crt0.o: No such file: No such file or directory
collect2: ld returned 1 exit status
I think it has to do with missing glue code (not sure what that is, but I came accross it somewhere).
When compiling with the -c option (no link) and subsequent linking step, I get a valid a.out file. (although the linker defaults the entry point, which should be o.k. I think):
Code: Select all
s-s-computer:~/Desktop ss$ i386-pc-elf-gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -c -o main.o main.c
s-s-computer:~/Desktop ss$ i386-pc-elf-ld main.o
i386-pc-elf-ld: warning: cannot find entry symbol _start; defaulting to 08048074
s-s-computer:~/Desktop ss$ i386-pc-elf-objdump -f a.out
a.out: file format elf32-i386
architecture: i386, flags 0x00000112:
EXEC_P, HAS_SYMS, D_PAGED
start address 0x08048074
Also, I was able to get Brian's kernel tuts up and running (after removing the leading _ in the start.asm file and a diferent linker script as discussed elswhere on this site.
Anyway, thanks for your input, I appreciate that people like you spend time in answering questions and especially, writing great tuts! (I will have to read up on your one.)
Sebastian
Posted: Sat Oct 27, 2007 5:41 am
by AJ
Hi,
I asked a similar question and was told to use -nostdinc and -nostdlib options with LD as well as GCC - seemed to do the trick.
Cheers,
Adam
Posted: Sat Oct 27, 2007 5:51 am
by JamesM
AJ has it right. You're right: the 'glue code' is the problem.
The compiler/linker requires a few things before it will compile 'normal' (not kernel) code properly:
- a C library (@regs: please don't flame me on this, I KNOW you can just 'touch libc.a'.)
- several object files, the most important of which is called crt0.o. Others include crtbegin.o and crtend.o.
Basically the crt0 is the initial code that should be run (before your main() function). The reason for this is the OS needs to set up some standard file descriptors and other things before user code can run. As such GCC expects this file and complains when it is not there.
In a kernel, you don't need this file at all, since you specify yourself what code should run and where the entry point should be. So you can stop GCC looking for it with the flag '-nostdlib'. You should also disable looking for standard header files (which would be linux-based and not healthy) by adding '-nostdinc'.
Hope this helps,
JamesM
Posted: Sat Oct 27, 2007 5:55 pm
by Pixion
Thanks,
I am now up and running, both w. Brian's kernel and GeekOs!
Sebastian
Here is how to do it:
-On Mac, build cross-compiler & binutils (there are some detailed guidelines on the web that describe this for an 'avr toolchain'):
target=i386-pc-elf, prefix=/usr/local/elf
-During building gcc, you probably get an error around 'libssp'. In that case add the following option during the configure step --disable-libssp and build again.
-Another option is to use Darwinports and download the whole preconfigured source using their CVS (search for i386-elf-gcc on their site).
-Once you have the cross compiler built, and added its prefix to your PATH (add /usr/local/elf/bin to PATH), you are set to go. Note that as you don't have appropriate runtime libraries etc. you will not (yet) be able to compile 'standard' c-programs for this target, but as you are building your own kernel, this is o.k. (see discussion in this thread).
-Now you have a working linker (i386-pc-elf-ld) which actually has the option of using a linker script (the ld that ships w. Xcode on Mac is an adapted version....).
-To build GeekOs, you only need to go in the make file and change the tool prefix:
Code: Select all
# ----------------------------------------------------------------------
# Tools -
# This section defines programs that are used to build GeekOS.
# ----------------------------------------------------------------------
# Uncomment if cross compiling
#TARGET_CC_PREFIX := i386-elf-
to
Code: Select all
# ----------------------------------------------------------------------
# Tools -
# This section defines programs that are used to build GeekOS.
# ----------------------------------------------------------------------
# Uncomment if cross compiling
TARGET_CC_PREFIX := i386-pc-elf-
Now make will use your cross-compiler and linker.
-Then get Qemu installed on your Mac
-Set up a standard PC (don't select a large RAM, GeekOs can not deal with that, 8MB is fine, 128MB will crash the kernel)
-Run - and add the code as you go from project to project...
Hope that helps!
Posted: Sat May 24, 2008 4:23 pm
by jinksys
-During building gcc, you probably get an error around 'libssp'. In that case add the following option during the configure step --disable-libssp and build again
Using the steps in the wiki I ran into this. So, what exactly is libssp? A google of libssp returns download links, no real help there. Also, excuse the thread zombification. I'd rather raise an existing related thread to ask my little question, rather than create another.