[uClinux-dev] The constructor of global variable cann't be executed in C++

kjlin kj.lin at viditec-netmedia.com.tw
Thu Nov 15 02:47:47 EST 2001


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.
For example:

#include <stdio.h>
class A{
public:
            A(int id) { printf("The constructor ID=%d!\n", id); };
};

A out(0);                        // global 

int main()
{
    A in(1);                      // local
    return 0;
}

The output is:
# The constructor ID=1

Only the constructor of the local variable "in" was executed.
Is it the problem of compiler or my uClibc or linker script??
My elf2flt.ld is as following:

ENTRY(_start)
MEMORY {
        flatmem : ORIGIN = 0x0, LENGTH = 0x2000000
}

SECTIONS {
        .text 0 : {
                . = ALIGN(0x4) ;
                _stext = . ;
                                _start = . ;
                *(.text)
                *(.text.*)
                *(.gnu.warning)
                *(.stub)
                *(.gnu.linkonce.t*)
                *(.init)
                . = ALIGN(0x10) ;
                _etext = . ;
        } > flatmem
        .data : {
                . = ALIGN(0x4) ;
                _sdata = . ;
                                __data_start = . ;
                                data_start = . ;
                                /* Do not change _gp value */
                                _gp = . + 0x7ff0;
                                *(.rela.got)
                                *(.rel.got)
                                *(.got.plt)
                                *(.got)
                                LONG(-1)
                *(.rodata)
                *(.rodata.*)
                *(.gnu.linkonce.r*)
                *(.rodata1)
                *(.data)
                *(.data.*)
                *(.gnu.linkonce.d*)
                *(.data1)
                *(.eh_frame)
                *(.gcc_except_table)
                *(.sdata)
                *(.sdata.*)
                *(.gnu.linkonce.s.*)
                                . = ALIGN(4) ;
                                *(.ctors.*)
                                *(.ctors)
                                LONG(0)
                                *(.dtors.*)
                                *(.dtors)
                                LONG(0)
                . = ALIGN(0x10) ;
                _edata = . ;
        } > flatmem
        .lit8 : { *(.lit8) } >flatmem
        .lit4 : { *(.lit4) } >flatmem
        .bss : {
                . = ALIGN(0x4) ;
                _sbss = ALIGN(0x4) ;
                                __bss_start = . ;
                *(.dynsbss)
                *(.sbss)
                *(.sbss.*)
                *(.scommon)
                *(.dynbss)
                *(.bss)
                *(.bss.*)
                *(COMMON)
                . = ALIGN(0x10) ;
                _ebss = . ;
                                _end = . ;
                                end = . ;
        } > flatmem
        .reginfo : { *(.reginfo) } > flatmem
        .rel.dyn : { *(.rel.dyn) } > flatmem
}

Thanks very much for any of your hints!

KJ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.uclinux.org/pipermail/uclinux-dev/attachments/20011115/813610c9/attachment.html>


More information about the uClinux-dev mailing list