gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Global constructors don't show up

#95274 - agentq - Fri Jul 28, 2006 3:56 pm

Hi, I've been compiling a program with DevkitArm r19a, and it seems to crash in the global constructors before reaching main(). I commented out the following lines in ds_arm9_crt0.s in order to test this:

Code:
#ldr   r3, =__libc_init_array   @ global constructors
#bl   _call_via_r3


After that, my program's main() function runs fine, but global objects don't have their constructor called.

I now need to know where the global contructors are in the program to find the one that has the problem. I have previously used a map file generated with -Wl,-Map,map.txt and looked in the .ctors section, but this time the section appears to be empty:

Code:
.ctors          0x0217aa3c        0x0
 *crtbegin.o(.ctors)
 *(EXCLUDE_FILE(*crtend.o) .ctors)
 *(SORT(.ctors.*))
 *(.ctors)
                0x0217aa3c                . = ALIGN (0x4)

.dtors          0x0217aa3c        0x0
 *crtbegin.o(.dtors)
 *(EXCLUDE_FILE(*crtend.o) .dtors)
 *(SORT(.dtors.*))
 *(.dtors)
                0x0217aa3c                . = ALIGN (0x4)


Does anyone know why this would be? There are definately global constructors in the program. When I build ScummVM, this section lists the object files which contain global static objects.

Or perhaps anyone knows of a better way to find these?

#95370 - agentq - Sat Jul 29, 2006 2:13 am

I was just being stupid, and looking in the wrong section.

In case anyone's interested, it was .init_array I was after. The .o files listed in here are the ones that have global constructors.

Code:
.init_array     0x0213a73c       0x2c
 *(.init_array)
 .init_array    0x0213a73c        0x4 c:/ndsdev/devkitpro/devkitarm/bin/../lib/gcc/arm-eabi/4.1.1/crtbegin.o
 .init_array    0x0213a740        0x4 cache.o
 .init_array    0x0213a744        0x4 demo.o
 .init_array    0x0213a748        0x4 director.o
 .init_array    0x0213a74c        0x4 extend.o
 .init_array    0x0213a750        0x4 lisp_gc.o
 .init_array    0x0213a754        0x4 main.o
 .init_array    0x0213a758        0x4 specache.o
 .init_array    0x0213a75c        0x4 statbar.o
 .init_array    0x0213a760        0x4 image.o
 .init_array    0x0213a764        0x4 specs.o
                0x0213a768                PROVIDE (__init_array_end, .)
                0x0213a768                PROVIDE (__fini_array_start, .)


Yay for fixing bugs at 2:15 in the morning!