This is the mail archive of the
mailing list for the GCC project.
linking custom executable
- From: "Alexander Gdalevich" <gdalevich at hotmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Tue, 22 Jun 2004 13:49:45 -0400
- Subject: linking custom executable
I am running into a strange problem using a pc-cygwin hosted GCC 3.4.0 cross
compiler for the Hitachi sh4 (sh-elf) target.
I have to build an executable image for an embedded system. I order to call
global constructors, the program has to call __do_global_ctors_aux() at some
point before calling main(). This function (__do_global_ctors_aux) is in
crtend.o. Normally, collect2 will generate the code to do all the
initialization, call global constructors and call main(). However, I cannot
do this since my program has to do some custom hardware initialization
before running any user or library code. Hence, what I am trying to do is
to call __do_global_ctors_aux() directly from my code after I am done with
I am, however, running into trouble linking the program.
ld crtbegin.o crtend.o my_program.o -lgcc
This, however, does not work:
ld ?oformat=binary crtbegin.o crtend.o my_program.o ?lgcc
crtbegin.o(.text+0x54): In function `___do_global_dtors_aux':
: undefined reference to `___deregister_frame_info'
crtbegin.o(.text+0xa8): In function `_frame_dummy':
: undefined reference to `___register_frame_info'
crtbegin.o(.text+0xb8): In function `_frame_dummy':
: undefined reference to `__Jv_RegisterClasses'
Is this a bug???
However, when I call __do_global_ctors_aux() from my program, it does not
link no matter what. When I instructed the linker to produce map with ?M
option, and looked at the file generated, I saw that even so .init, .text,
and other sections from crtbegin.o and crtend.o are being linked in, no
global symbols such as __do_global_ctors_aux and __do_global_dtors_aux
appear in the list.
What am I doing wrong?
Thanks for your time.
"Normal people ... believe that if it ain't broke, don't fix it. Engineers
believe that if it ain't broke, it doesn't have enough features yet."
MSN 9 Dial-up Internet Access fights spam and pop-ups ? now 3 months FREE!