Porting GCC to my OS
Porting GCC to my OS
Hi
I just tried to port GCC to my OS, so first read the article about it on the wiki page and i have some questions about it.
My first and biggest question is that when i compile the native compiler with the cross comiler (compiled before) i specify the --with-headers option to the configure with the directory of the headers of my C library (that works on my OS) but how do i tell to the compile progress to link the new GCC with my C library that runs on my OS?
Thanks for the answers,
giszo
I just tried to port GCC to my OS, so first read the article about it on the wiki page and i have some questions about it.
My first and biggest question is that when i compile the native compiler with the cross comiler (compiled before) i specify the --with-headers option to the configure with the directory of the headers of my C library (that works on my OS) but how do i tell to the compile progress to link the new GCC with my C library that runs on my OS?
Thanks for the answers,
giszo
Try OS Specific Toolchain. It'll tell you how to generate a gcc cross-compiler for your os that automatically links with your os's libc. You could then use that (e.g. CC=i586-pc-myos-gcc ./configure ...) to build a native gcc for your os.
Regards,
John.
Regards,
John.
- AndrewAPrice
- Member
- Posts: 2309
- Joined: Mon Jun 05, 2006 11:00 pm
- Location: USA (and Australia)
GCC != newlibSpeewave wrote:what do you mean. like a modified gcc? or your own compiler.I'm not planning to use newlibc because i have my own implementation
to figure out how gcc works wikipedia gcc
Newlib is only an implementation of the C Standard Library.
GCC is a compiler.
A GCC package may come with a standard library, but it would be effectively useless in OSDeving as you'd have to provide your own anyway.
@giszo: You should be able to follow the instructions and just skip the newlib section. I'm not porting any C or C+ library yet (only my API).
My OS is Perception.
As long as your cross-compiler is configured without the option --without-headers, it should expect a c library to be present on the target system, usually in $PREFIX/$TARGET/lib/libc.a, and any attempt to link a program with your cross compiler should include libc by default. If you can get that working, e.g. by compiling a few simple test cases that use the c library, you can then compile gcc to run on your os with similar steps, by using the --host=$TARGET --target=$TARGET options to configure. Note that specifying --without-headers implies that you have a full c library, with all the required header files.
Regards,
John.
Regards,
John.
As i run througt on the page again that jnc100 told me, i got an idea...
I may change the linker scripts in the cross compiler and add my libc to the libraries that has to be linked to the application, so when i compile my native compiler it will be linked with my own libc?
It this is true one more question: what should i do if i'd use dynamic linking?
I may change the linker scripts in the cross compiler and add my libc to the libraries that has to be linked to the application, so when i compile my native compiler it will be linked with my own libc?
It this is true one more question: what should i do if i'd use dynamic linking?
Gizo: The way to do this is make two compilers.
1. Build a cross-compiler toolchain for your OS. What I mean by this is: Build a cross-compile toolchain that when run on your HOST or DEVELOPMENT system, produces a binary which can be run on your OWN os.. To do this you need to do several things:
- Obviously build the toolchain. Put it in somewhere out of the way, like /usr/myos-cross.
- cd into /usr/myos-cross/lib/gcc-4.0.1/ (that is an approximate directory name: go into /usr/myos-cross/lib/ and follow the trail of directories until you find a load of .o files: crt0.o etc).
- Copy your own libc.a, libm.a, libg.a, crt0.o, crtbegin.o/crtend.o (you can just make these blank files)
- Test it! Get it compiling a test program, copy the resulting binary across to your OS and run it.
2. This is the next stage. You already have a compiler that will product native binaries and link with your own libraries, now you want one which will do that self-hosted.
- Build another toolchain! Put it somewhere like /usr/myos-native, and this time before calling ../gcc-4.0.1/configure, do this:
- When that's compiled, you're done! You can take /usr/myos-native/bin/gcc and /usr/myos-native/bin/ld and copy them over to your own OS (don't forget cc1 and collect2 and all the other executables in that directory) and run them! hey presto!
Any questions, just ask
JamesM
1. Build a cross-compiler toolchain for your OS. What I mean by this is: Build a cross-compile toolchain that when run on your HOST or DEVELOPMENT system, produces a binary which can be run on your OWN os.. To do this you need to do several things:
- Obviously build the toolchain. Put it in somewhere out of the way, like /usr/myos-cross.
- cd into /usr/myos-cross/lib/gcc-4.0.1/ (that is an approximate directory name: go into /usr/myos-cross/lib/ and follow the trail of directories until you find a load of .o files: crt0.o etc).
- Copy your own libc.a, libm.a, libg.a, crt0.o, crtbegin.o/crtend.o (you can just make these blank files)
- Test it! Get it compiling a test program, copy the resulting binary across to your OS and run it.
2. This is the next stage. You already have a compiler that will product native binaries and link with your own libraries, now you want one which will do that self-hosted.
- Build another toolchain! Put it somewhere like /usr/myos-native, and this time before calling ../gcc-4.0.1/configure, do this:
Code: Select all
export CC=/usr/myos-cross/bin/gcc
export CFLAGS=<any extra flags you may need to build on your OS>
export LDFAGS=<any extra flags you may need to link on your OS: extra libraries etc>
Any questions, just ask
JamesM
I'm just finished compiling the cross compiler toolchain, so now i have i586-pc-giszOS-gcc, i586-pc-giszOS-ld and so on...
I also added the bin directory of my cross dir to path and tried to compile a really simple .c file with an empty main() and i got the following:
/home/giszo/gcc_giszOS_cross/bin/../lib/gcc/i586-pc-giszOS/4.2.2/../../../../i586-pc-giszOS/bin/ld: crt0.o: No such file: No such file or directory
collect2: ld returned 1 exit status
Where should crt0.o be? I haven't found it in the subtree of my cross dir. I found crtbegin and crtend only.
I also added the bin directory of my cross dir to path and tried to compile a really simple .c file with an empty main() and i got the following:
/home/giszo/gcc_giszOS_cross/bin/../lib/gcc/i586-pc-giszOS/4.2.2/../../../../i586-pc-giszOS/bin/ld: crt0.o: No such file: No such file or directory
collect2: ld returned 1 exit status
Where should crt0.o be? I haven't found it in the subtree of my cross dir. I found crtbegin and crtend only.
What parameters should i use to configure and compile binutils with the cross compiler toolchain?
I tried several commands:
#1: CC=i586-pc-giszOS-gcc ./configure --target=i586-pc-giszOS --prefix=/home/giszo/gcc_giszOS_native --disable-nls
This fails with the following message: checking whether the C compiler works... configure: error: cannot run C compiled programs.
#2: CC=i586-pc-giszOS-gcc ./configure --host=i686-pc-linux --target=i586-pc-giszOS --prefix=/home/giszo/gcc_giszOS_native --disable-nls
Configure finished without error but i'm not sure if it's correct to add the --host parameters but this one also fails during make.
giszo
I tried several commands:
#1: CC=i586-pc-giszOS-gcc ./configure --target=i586-pc-giszOS --prefix=/home/giszo/gcc_giszOS_native --disable-nls
This fails with the following message: checking whether the C compiler works... configure: error: cannot run C compiled programs.
#2: CC=i586-pc-giszOS-gcc ./configure --host=i686-pc-linux --target=i586-pc-giszOS --prefix=/home/giszo/gcc_giszOS_native --disable-nls
Configure finished without error but i'm not sure if it's correct to add the --host parameters but this one also fails during make.
giszo
Code: Select all
./configure --target=i586-pc-gizOS --host=i586-pc-gizOS
Indeed Acutally I meant "Note that _not_ specifying --without-headers..."giszo wrote:You mean --with-headers ?jnc100 wrote:Note that specifying --without-headers implies that you have a full c library, with all the required header files.
Regards,
John.