This is the mail archive of the
newlib@sources.redhat.com
mailing list for the newlib project.
Re: CRT0 questions
- From: Jeff Johnston <jjohnstn at redhat dot com>
- To: Chien-Lung Wu <cwu at deltartp dot com>
- Cc: "'newlib at sources dot redhat dot com'" <newlib at sources dot redhat dot com>
- Date: Tue, 30 Mar 2004 17:23:48 -0500
- Subject: Re: CRT0 questions
- References: <A4E787A2467EF849B00585F14C900559068C16@18.172.in-addr.arpa>
Chien-Lung Wu wrote:
Hi, everyone:
I created cross-compiler for our embedded project, using Powerpc (MPC8250).
It is fine to compile all my application files using cross-compiler with
newlib C-library.
But I got linking stage error when link all object files. I have several
questions about newlib. Can anyone help me out?
Before you go any further, I suggest you look in libgloss/rs6000. You will find
a number of sets of ld scripts for the powerpc. When you compile/link, you need
to specify the -T option with a .ld script. For example, powerpc-elf-gcc
-Tmbx.ld my.c ....
There is already a crt0.S file there which may suit your needs. You might need
to tweak one of the ld scripts to match your board. I would start by trying
the existing ones first.
Q. crt0
When I generate newlib C library, I believe that the crt0 also been
generated. Since I used company-designed hardware, I need to re-write crt0.
Are there information to write crt0? Anything I got to take care when I
write the crt0?
There is some information in the libgloss docs (make info in the libgloss
directory or just look at the sourcefile: libgloss/doc/porting.texi).
1. what does crt0?
2. How many things got to do (init) within crt0?
The doc should tell you what you need to know. Basically, you need to
initialize the state so that calling main et al works. Usually, this minimally
entails setting up the stack pointer and clearing the bss area, however, you
might need to other things as well (for example, you might have to initialize a
frame pointer register). It all depends on the platform. I would imagine the
crt0.S in the rs6000 directory should be adequate or very close to what you need.
3. After I finish "initialize", what is the "hook" to connect with
C-library? What function I got to
call so that the program can connect with "main()"? for example, I used
diab4.4b compiler before.
I know that the crt0 finally call __init_main to connect with program's main
function. What is the exact function for newlib C-library?)
newlib doesn't have a main hook. In some cases, you may want to call a __main
to do extra stuff like running the C++ constructors but this would also be in
libgloss. If you are just using C, you don't need __main and can call main()
directly. Once main() returns you need to call exit(). You can see this when
you look at the libgloss/rs6000/crt0.S file.
Thanks for your help.
Chien-Lung