Page 1 of 1
Cross compiler can't find newlib crt0.o
Posted: Wed Feb 01, 2017 11:15 am
by codyd51
Hello!
I apologize if this is a simple question, but I can't seem to figure it out; I ported Newlib to my OS following the guide on the wiki, and am trying to compile a file with i686-elf-gcc. This is the command I'm compiling with:
Code: Select all
./i686-toolchain/bin/i686-elf-gcc -I$SYSROOT/usr/include -L$SYSROOT/usr/lib -lc -lgcc $SYSROOT/usr/lib/crt0.o test.c -o test.elf
When I run this, i686-elf/bin/ld complains "cannot find crt0.o: No such file or directory".
$SYSROOT/usr/lib/ctr0.o exists, as you'd expect. It doesn't seem to have any trouble finding $SYSROOT/usr/lib/libc.a, which as you can see I'm linking against.
Am I missing something simple? Thanks!
Re: Cross compiler can't find newlib crt0.o
Posted: Wed Feb 01, 2017 7:05 pm
by dchapiesky
How did you port newlib to your OS without creating a newlib/libc/sys/TARGET directory?
Where TARGET is your os name...?
Examine newlib/libc/sys/rtems for an example of an crt0.c
files in newlib/libc/sys are compiled only when you use a triplet such as i686-elf-rtems....
also - did you compile you cross compiler with --with-newlib?
Re: Cross compiler can't find newlib crt0.o
Posted: Thu Feb 02, 2017 1:03 pm
by codyd51
dchapiesky wrote:How did you port newlib to your OS without creating a newlib/libc/sys/TARGET directory?
Where TARGET is your os name...?
Examine newlib/libc/sys/rtems for an example of an crt0.c
files in newlib/libc/sys are compiled only when you use a triplet such as i686-elf-rtems....
also - did you compile you cross compiler with --with-newlib?
I did create a newlib/libc/sys/{my os} directory; I ported newlib by following this wiki page:
http://wiki.osdev.org/Porting_Newlib
I did not compile my cross compiler with --with-newlib.
Re: Cross compiler can't find newlib crt0.o
Posted: Thu Feb 02, 2017 4:11 pm
by dchapiesky
Thank you for the extra information....
The simplest solution is to simply compile an empty crt0.c and include it in your link line. This implies that you are using a ld script and an elf loader for your kernel where either _start() or main() are specified as your entry point.
The next solution is to modify your ld script to not include crt0.o as part of the link....
Another solution is to add a crt0.c to your newlib sys directory newlib/libc/sys/myos - this is worth while as it allows you to have an entry point _start() while giving you control of how main() is called - useful for setting up stdin/stdout etc.... make sure you run the autotools to properly reconfigure your build scripts
finally the hardest solution - but well worth it - is to go full
http://wiki.osdev.org/OS_Specific_Toolchain where in the section called
gcc/config/myos.h you can customize your start file specs using STARTFILE_SPEC
This is by far the most useful of all examples as it allows you to compile other software packages you didn't develop without having to hack their makefiles to add your ld script.