Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What goes to the __init_array?

Tags:

c

gcc

ld

libc

newlib

I have a Cortex-M3 project compiled with GCC. The startup_LPC177x_8x.s code copies the initialized data from flash to RAM, initializes the bss, calls the clock initialization SystemInit. Before calling the _main function the code also calls the function _libc_init_array.

The __libc_init_array function calls all initialization routines that are defined in the __preinit_array, calls the _init function, and all routines that are defined in the __init_array:

void __libc_init_array (void)
{
    size_t count;
    size_t i;

    count = __preinit_array_end - __preinit_array_start;
    for (i = 0; i < count; i++)
        __preinit_array_start[i] ();

    _init ();

    count = __init_array_end - __init_array_start;
    for (i = 0; i < count; i++)
        __init_array_start[i] ();
}

With GDB I could find that the __preinit_array is empty (start==end), and that the second call to __init_array_start[i] () crashes.

I have no idea what functions are included in this array. The linker script causes all .init.array.* section to be located here. But how do I find the corresponding .o and source files?

.init_array :
{
    PROVIDE_HIDDEN (__init_array_start = .);
    KEEP (*(SORT(.init_array.*)))
    KEEP (*(.init_array*))
    PROVIDE_HIDDEN (__init_array_end = .);
} >FLASH
like image 689
harper Avatar asked Nov 23 '25 02:11

harper


1 Answers

Maybe I can help you here -

run

objdump -D -j .init_array <your-application>

and you will recieve a list of adresses, like

Disassembly of section .init_array:

c1008db4 <.init_array>:
c1008db4:   c1000000    .word   0xc1000000
c1008db8:   c1000a68    .word   0xc1000a68
c1008dbc:   c1000b64    .word   0xc1000b64
c1008dc0:   c1000c04    .word   0xc1000c04
c1008dc4:   c1000c68    .word   0xc1000c68

now, if you have compiled this thing yourself, you can now run

addr2line 0xc1000a68 -e <your-application>

to get filename and line number of the functions in question.

Does that help?

like image 173
Andreas Grapentin Avatar answered Nov 24 '25 21:11

Andreas Grapentin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!