[uClibc]The constructor of global variable cann't be executed in C++
kjlin
kj.lin at viditec-netmedia.com.tw
Mon Nov 19 03:51:14 UTC 2001
Dear Erik,
Thanks for your support.
I had tried the newest uClibc/libc/sysdeps/linux/mipsel/crt0.c, but it did
not
help.
I think this is due to that my x-compiler(mips-linux-gcc) doesn't generate a
subroutine to deal with the lists in .ctors
and .dtors sections, though we added the __CTOR_LIST__ and __DTOR_LIST__ in
the crt0.c.
Therefore, i add the handler to do the .ctors and .dtors lists in crt0.c by
referring the GNU glibc.
I don't know whether it is a good method, but it works fine in my MIPS
board.
Perhaps you have better methods or ideas?
uClibc/libc/sysdeps/linux/mips/crt0.c:
static void (*const __CTOR_LIST__[1]) (void)
__attribute__ ((section (".ctors")))
= { (void (*) (void)) -1 };
static void (*const __DTOR_LIST__[1]) (void)
__attribute__ ((section (".dtors")))
= { (void (*) (void)) -1 };
extern void __uClibc_main(int argc,void *argv,void *envp);
extern int atexit (void (*__func) (void));
void __do_global_ctors(void);
asm(
".text\n"
"\t.global\t_start\n"
"\t.type\t_start, at function\n"
"\n"
".text\n"
"_start:\n"
"\t.cpload\t$25\n"
"\tmove\t$30, $0\n" /* zero frame pointer */
"\tlw\t$4, 0($29)\n" /* $4 = argc */
"\taddu\t$5, $29, 4\n" /* $5 = argv */
"\tmove\t$6, $4\n" /* $6 = envp = (argc+1)*4+argv */
"\tadd\t$6, 1\n"
"\tsll\t$6, 2\n"
"\taddu\t$6, $6, $5\n"
"\n"
/* Handler for .ctors and .dtors */
"\tjal\t__do_global_ctors\n"
/* Ok, now run uClibc's main() -- shouldn't return */
"\tjal\t__uClibc_main\n"
);
static inline void
run_hooks (void (*const list[]) (void))
{
while (*++list)
(**list) ();
}
void __do_global_dtors (void)
{
run_hooks (__DTOR_LIST__);
}
void __do_global_ctors(void)
{
run_hooks (__CTOR_LIST__);
atexit (__do_global_dtors);
}
KJ
----- Original Message -----
From: "Erik Andersen" <andersen at codepoet.org>
To: "kjlin" <kj.lin at viditec-netmedia.com.tw>
Cc: <uclibc at uclibc.org>
Sent: Thursday, November 15, 2001 5:14 PM
Subject: Re: [uClibc]The constructor of global variable cann't be executed
in C++
> On Thu Nov 15, 2001 at 03:55:36PM +0800, kjlin wrote:
> > Hi all,
> >
> > I am using uclinux-2.4.1+MIPS and compiler is gcc-2.96 20000731.
> > All the APs which written by C code are executed very well in my
uclinux+MIPS.
> > Howerer, the APs made by C++ are not so fine.
> > The C++ problem is that the constructor of a global object will not be
executed,
> > but the constructor of a local object is executed normally.
>
> I just put in some untested support for global constructors and
> destructors in uClibc/libc/sysdeps/linux/mipsel/crt0.c
> Could you check is that helps?
>
> -Erik
>
> --
> Erik B. Andersen http://codepoet-consulting.com/
> --This message was written using 73% post-consumer electrons--
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: crt0.c
Type: application/octet-stream
Size: 1108 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/uclibc/attachments/20011119/5a245d49/attachment.obj
More information about the uClibc
mailing list