jameswalmsley
Posts: 35
Joined: Thu Nov 08, 2012 3:26 pm

Linker script nightmare -- please help!

Thu May 21, 2015 5:52 pm

Hi All,

I've been suffering with a bug in a linker script for a really long time, and I have no idea how to fix it or what causes it.
Here's my linker script... (cut for context, but the real thing is much longer, but simply adds more sections.

Code: Select all

ENTRY(bt_reset)
_STACK_SIZE = DEFINED(_STACK_SIZE) ? _STACK_SIZE : 0x100;
_IRQ_STACK_SIZE = DEFINED(_IRQ_STACK_SIZE) ? _IRQ_STACK_SIZE : 0x0;
_ABORT_STACK_SIZE = DEFINED(_ABORT_STACK_SIZE) ? _ABORT_STACK_SIZE : 0;
_SUPERVISOR_STACK_SIZE = DEFINED(_SUPERVISOR_STACK_SIZE) ? _SUPERVISOR_STACK_SIZE : 0;
MEMORY
{
 SRAM (rwx) : ORIGIN = 0x8000 + 0x0, LENGTH = 0x00100000 - 0x0
}
SECTIONS
{
    .bt.init : {							// This is the kernel HEAD section.
		__bt_init_start = .;
        KEEP(*(.bt.init))
        KEEP(*(.bt.init*))
		KEEP(*(.bt.init.vectors))
		KEEP(*(.bt.init.vectors.*))
		KEEP(*(.init))
		__bt_init_end = .;
    } > BT_LINKER_INIT_SECTION

    .bt.arch.init : {
	    __bt_arch_init_start = .;
		KEEP(*(.bt.arch.init))
		KEEP(*(.bt.arch.init.*))
		__bt_arch_init_end = .;
	} > BT_LINKER_INIT_SECTION
...
}
Now the problem is that .bt.arch.init overwrites .bt.init and I have no idea why. All subsequent sections work correctly.

Heres the list file...

Code: Select all

Disassembly of section .bt.init:

00008000 <__bt_init_start>:
    8000:       e59ff270        ldr     pc, [pc, #624]  ; 8278 <__gnu_ldivmod_helper+0xc>
    8004:       e59ff018        ldr     pc, [pc, #24]   ; 8024 <__bt_init_start+0x24>
    8008:       e59ff018        ldr     pc, [pc, #24]   ; 8028 <__bt_init_start+0x28>
    800c:       e59ff018        ldr     pc, [pc, #24]   ; 802c <__bt_init_start+0x2c>
    8010:       e59ff018        ldr     pc, [pc, #24]   ; 8030 <__bt_arch_init_end>
    8014:       e59ff018        ldr     pc, [pc, #24]   ; 8034 <__bt_arch_init_end+0x4>
    8018:       e59ff018        ldr     pc, [pc, #24]   ; 8038 <__bt_arch_init_end+0x8>
    801c:       e59ff018        ldr     pc, [pc, #24]   ; 803c <__bt_arch_init_end+0xc>
    8020:       00008080        andeq   r8, r0, r0, lsl #1
    8024:       00008198        muleq   r0, r8, r1
    8028:       000081cc        andeq   r8, r0, ip, asr #3
    802c:       0000819c        muleq   r0, ip, r1
    8030:       000081a8        andeq   r8, r0, r8, lsr #3
    8034:       000081bc                        ; <UNDEFINED> instruction: 0x000081bc
    8038:       0000b454        andeq   fp, r0, r4, asr r4
    803c:       000081b8                        ; <UNDEFINED> instruction: 0x000081b8

00008040 <_bt_vector_second_table>:
    8040:       e59ff230        ldr     pc, [pc, #560]  ; 8278 <__gnu_ldivmod_helper+0xc>
    8044:       e59ff018        ldr     pc, [pc, #24]   ; 8064 <gpio_driver+0x4>
    8048:       e59ff018        ldr     pc, [pc, #24]   ; 8068 <gpio_driver+0x8>
    804c:       e59ff018        ldr     pc, [pc, #24]   ; 806c <gpio_driver+0xc>
    8050:       e59ff018        ldr     pc, [pc, #24]   ; 8070 <__bt_arch_drivers_end>
    8054:       e59ff018        ldr     pc, [pc, #24]   ; 8074 <__bt_arch_drivers_end+0x4>
    8058:       e59ff018        ldr     pc, [pc, #24]   ; 8078 <__bt_loaders_end>
    805c:       e59ff018        ldr     pc, [pc, #24]   ; 807c <__bt_loaders_end+0x4>
    8060:       00008080        andeq   r8, r0, r0, lsl #1
    8064:       00008198        muleq   r0, r8, r1
    8068:       000081cc        andeq   r8, r0, ip, asr #3
    806c:       0000819c        muleq   r0, ip, r1
    8070:       000081a8        andeq   r8, r0, r8, lsr #3
    8074:       000081bc                        ; <UNDEFINED> instruction: 0x000081bc
    8078:       0000b454        andeq   fp, r0, r4, asr r4
    807c:       000081b8                        ; <UNDEFINED> instruction: 0x000081b8

00008080 <bt_reset>:
    8080:       e10f9000        mrs     r9, CPSR
    8084:       e3899080        orr     r9, r9, #128    ; 0x80
    8088:       e121f009        msr     CPSR_c, r9
    808c:       e1a07001        mov     r7, r1
    8090:       e1a08002        mov     r8, r2
    8094:       e59f01e0        ldr     r0, [pc, #480]  ; 827c <__gnu_ldivmod_helper+0x10>
    8098:       ee0c0f10        mcr     15, 0, r0, cr12, cr0, {0}
    809c:       eb000047        bl      81c0 <_bt_startup_init_hook>
    80a0:       e59fd1d8        ldr     sp, [pc, #472]  ; 8280 <__gnu_ldivmod_helper+0x14>
    80a4:       ee110f10        mrc     15, 0, r0, cr1, cr0, {0}
    80a8:       e3c00001        bic     r0, r0, #1
    80ac:       ee010f10        mcr     15, 0, r0, cr1, cr0, {0}
    80b0:       e59f31cc        ldr     r3, [pc, #460]  ; 8284 <__gnu_ldivmod_helper+0x18>
    80b4:       e3a02000        mov     r2, #0
    80b8:       e59f01c8        ldr     r0, [pc, #456]  ; 8288 <__gnu_ldivmod_helper+0x1c>

...

Disassembly of section .bt.arch.init:

00008000 <__bt_arch_init_start>:
    8000:       00000401        andeq   r0, r0, r1, lsl #8
    8004:       00010180        andeq   r0, r1, r0, lsl #3
    8008:       07735940        ldrbeq  r5, [r3, -r0, asr #18]!
    800c:       0000a020        andeq   sl, r0, r0, lsr #32
    8010:       00009ffc        strdeq  r9, [r0], -ip
    8014:       00000000        andeq   r0, r0, r0
    8018:       00010550        andeq   r0, r1, r0, asr r5
    801c:       00010580        andeq   r0, r1, r0, lsl #11
        ...
Does anyone know why the cursor gets reset?

Thanks for any help in advance.

James

tufty
Posts: 1456
Joined: Sun Sep 11, 2011 2:32 pm

Re: Linker script nightmare -- please help!

Thu May 21, 2015 6:36 pm

Is BT_LINKER_INIT_SECTION being defined somewhere?

jameswalmsley
Posts: 35
Joined: Thu Nov 08, 2012 3:26 pm

Re: Linker script nightmare -- please help!

Fri May 22, 2015 11:56 am

Thanks for the help.
Yes its replaced with SRAM by a pre-processor.

I just solved the problem by merging the .bt.init and .bt.arch.init into a single section.
Maybe there's something weird with the section names that I don't understand.

James

kriss
Posts: 66
Joined: Thu Apr 02, 2015 8:53 pm
Location: france for now ...

Re: Linker script nightmare -- please help!

Thu Jun 04, 2015 8:22 am

does ld -T option not working ?

Return to “Bare metal, Assembly language”