global constructors not working in gcc 3.2.2EE

Discuss the development of software, tools, libraries and anything else that helps make ps2dev happen.

Moderators: cheriff, Herben

Post Reply
tweakoz
Posts: 21
Joined: Tue Feb 17, 2004 10:51 am
Location: Santa Cruz, CA
Contact:

global constructors not working in gcc 3.2.2EE

Post by tweakoz »

my toolchain is hosted on cygwin.
program compiles and links fine, but _init() doesnt seem to do anything

top of main and entire linkfile listed below.

any help would be appreciated

thank,

mtm

Code: Select all

class testclass
{	public:
	int testval;
	testclass()
             : testval( 300 )
	{
	}
	int getval( void ) { return testval; }
};
testclass testinstance;
int main( int argc, char **argv )
{
	MagCheckPoint( "Testval %d\n", testinstance.getval() ); // prints 0
	gdb_stub_main( 0, 0 );
	_init();	// call global / static constructors
	MagCheckPoint( "Testval %d\n", testinstance.getval() ); // prints 0
         
         ... blah blah .....
}
my link file looks like this

Code: Select all

ENTRY(_start);

INPUT( /usr/local/ps2dev/ee/lib/gcc-lib/ee/3.2.2/crtbegin.o )
INPUT( /usr/local/ps2dev/ee/lib/gcc-lib/ee/3.2.2/crtend.o )
INPUT( /usr/local/ps2dev/ee/lib/gcc-lib/ee/3.2.2/crti.o )
INPUT( /usr/local/ps2dev/ee/lib/gcc-lib/ee/3.2.2/crtn.o )

SECTIONS
{
	
	.init 0x00100000:
	{	/* USE GCC's _init() */
		*(.init)
	}
	.fini :
	{	/* USE GCC's _init() */
		*(.fini)
	}
	
	.text :
	{	/* USE PS2LIBS's _start */
		/usr/local/ps2dev/ps2lib/ee/startup/crt0.o(.text)
		*(.text)
		*(.text.*)
    	*(.gnu.linkonce.t*)
	}
	
	.ctors :
	{
		KEEP (*crtbegin.o(.ctors))
		KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
	    KEEP (*(SORT(.ctors.*)))
		KEEP (*(.ctors))	
	}
  	
  	.dtors :
  	{	KEEP (*crtbegin.o(.dtors))
    	KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
		KEEP (*(SORT(.dtors.*)))
    	KEEP (*(.dtors))
  	}
	
	.reginfo ALIGN(128): { KEEP(*(.reginfo)) }

	/***************************************/
	/* Static data.  */
	
	.rodata ALIGN(128):	{ *(.rodata) }
	.data ALIGN(128):
	{
		*(.data)
	    *(.data.*)
    	*(.gnu.linkonce.d*)
	}
	.rdata ALIGN(128):
	{
		*(.rdata)
	}
	.rodata		ALIGN(128):
	{
		*(.rodata)
		*(.rodata.*)
		*(.gnu.linkonce.r*)
	}
	_gp = ALIGN(128) + 0x7ff0;
	.lit4 ALIGN(128): { *(.lit4) }
	.lit8 ALIGN(128): { *(.lit8) }
	.sdata ALIGN(128):
	{
		*(.sdata)
		*(.sdata.*)
		*(.gnu.linkonce.s*)
	}

	/***************************************/
	/* Uninitialized data.  */

	.sbss ALIGN(128) (NOLOAD): {
		_fbss = . ;
		*(.scommon)
		*(.sbss)
	}
	.bss ALIGN(128) (NOLOAD): { *(.bss) }
	.COMMON ALIGN(128) (NOLOAD): { *(COMMON) }
	_end_bss = .;

	/***************************************/

	_end = . ;
	PROVIDE(end = .);

	/***************************************/
	/* Symbols needed by crt0.s.  */

	PROVIDE(_heap_size = -1);
	PROVIDE(_stack = -1);
	PROVIDE(_stack_size = 128 * 1024);
	
	/***************************************/
	
}
MrHTFord
Posts: 35
Joined: Tue Feb 10, 2004 2:04 am
Location: England

Post by MrHTFord »

What you've got there seems ok to me, have you got this before your main function?

Code: Select all

extern "C" {
   extern void _init(void);
};
I'd assume you have as otherwise you'd get linking errors.

My linkfile doesn't explicitly list the crt files as yours does, instead, when linking, I don't specify -nostdlib to gcc (at least, I think that's what I don't do). Posting a disassembly with debugging (-g) would be useful.

Also, does it fail with -O0?

Cheers.
Post Reply