Domanda

Using gcc arm-none-eabi 4_8 compiler, I'm getting a problem with my binary after linking. No errors but when I bring it up in debugger I never reach main. Tracing it through it appears the linker is not adding the epilog to the .init section for crt. This causes my code to run past .init into .rodata section and hitting hard fault on undefined instruction.

I'm stumped trying to figure out why this piece of code has this issue when very similar code using the same makefile doesn't. I know this is a broad question but what would be some reasons why the linker is not creating a good .init section?

Bad .map:

*(.init)
.init          0x00001cec        0x4     /usr/local/.../gcc/linux/4_8-2013q4/bin/../lib/gcc/arm-none-eabi/4.8.3/armv6-m/crti.o
            0x00001cec                _init
*(.fini)
.fini          0x00001cf0        0x4 /usr/local/.../gcc/linux/4_8-2013q4/bin/../lib/gcc/arm-none-eabi/4.8.3/armv6-m/crti.o
            0x00001cf0                _fini

Good .map:

*(.init)
.init          0x00015c48        0x4 /usr/local/.../gcc/linux/4_6-2012q4/bin/../lib/gcc/arm-none-eabi/4.6.2/armv6-m/crti.o
            0x00015c48                _init
.init          0x00015c4c        0x8 /usr/local/.../gcc/linux/4_6-2012q4/bin/../lib/gcc/arm-none-eabi/4.6.2/armv6-m/crtn.o
*(.fini)
.fini          0x00015c54        0x4 /usr/local/.../gcc/linux/4_6-2012q4/bin/../lib/gcc/arm-none-eabi/4.6.2/armv6-m/crti.o
            0x00015c54                _fini
.fini          0x00015c58        0x8 /usr/local/.../gcc/linux/4_6-2012q4/bin/../lib/gcc/arm-none-eabi/4.6.2/armv6-m/crtn.o
È stato utile?

Soluzione

Turns out the issue is an out of date linker command file.

Was missing:

           KEEP(*(.init))
           KEEP(*(.fini))
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top