rpi: Rework linker script

* Add some missing stuff, be more exact with
  stack and fill with 0xBEBEBEBE
* Ensure .init_array is called with .ctors to ensure
  static constructors are called.
This commit is contained in:
Alexander von Gluck IV
2012-05-15 10:33:12 -05:00
parent 8d44fff34a
commit 27d3324651
3 changed files with 117 additions and 46 deletions
@@ -4,11 +4,15 @@ _start:
.balign 0x8000, 0 .balign 0x8000, 0
jmp_loader: jmp_loader:
/* Set up 1MB C Stack Space */
mov sp, #0x100000
mov r4, #0
/* Start Haiku loader */ /* Start Haiku loader */
/* For Thumb code? */
/*
ldr r12, =pi_start
mov lr, pc
bx r12
*/
b pi_start b pi_start
/* Cause exception if loader returns */ /* Cause exception if loader returns */
@@ -27,8 +27,12 @@
// GCC defined globals // GCC defined globals
extern void (*__ctor_list)(void); extern void (*__ctor_list)(void);
extern void (*__ctor_end)(void); extern void (*__ctor_end)(void);
extern void (*__dtor_list)(void);
extern void (*__dtor_end)(void);
extern uint8 __bss_start; extern uint8 __bss_start;
extern uint8 _end; extern uint8 __bss_end;
extern uint8 __stack_start;
extern uint8 __stack_end;
extern int main(stage2_args *args); extern int main(stage2_args *args);
void _start(void); void _start(void);
@@ -37,14 +41,20 @@ void _start(void);
static void static void
clear_bss(void) clear_bss(void)
{ {
memset(&__bss_start, 0, &_end - &__bss_start); memset(&__bss_start, 0, &__bss_end - &__bss_start);
}
static void
fill_stack(void)
{
memset(&__stack_start, 0xBEBEBEBE, &__stack_end - &__stack_start);
} }
static void static void
call_ctors(void) call_ctors(void)
{ {
#warning BUG: constructors don't get called!
void (**f)(void); void (**f)(void);
for (f = &__ctor_list; f < &__ctor_end; f++) { for (f = &__ctor_list; f < &__ctor_end; f++) {
@@ -92,6 +102,7 @@ pi_start(void)
stage2_args args; stage2_args args;
clear_bss(); clear_bss();
fill_stack();
call_ctors(); call_ctors();
cpu_init(); cpu_init();
@@ -1,18 +1,40 @@
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm) OUTPUT_ARCH(arm)
ENTRY(_start) ENTRY(_start)
C_STACK_SIZE = 1048576;
IRQ_STACK_SIZE = 0;
FIQ_STACK_SIZE = 0;
SVC_STACK_SIZE = 0;
ABT_STACK_SIZE = 0;
UND_STACK_SIZE = 0;
SECTIONS SECTIONS
{ {
. = BOARD_LOADER_BASE; . = BOARD_LOADER_BASE;
/* text/read-only data */ /* text/read-only data */
.text : { *(.text .gnu.linkonce.t.*) } .text : {
CREATE_OBJECT_SYMBOLS
*(.text .text.* .gnu.linkonce.t.*)
*(.plt)
*(.gnu.warning)
}
. = ALIGN(0x4); . = ALIGN(0x4);
.ctors : {
__ctor_list = .; __ctor_list = .;
.ctors : { *(.ctors) } *(.init_array);
*(.ctors);
__ctor_end = .; __ctor_end = .;
}
.dtors : {
__dtor_list = .;
*(.fini_array);
*(.dtors);
__dtor_end = .;
}
.rodata : { *(.rodata .rodata.*) } .rodata : { *(.rodata .rodata.*) }
@@ -27,14 +49,51 @@ SECTIONS
__exidx_end = .; __exidx_end = .;
/* uninitialized data (in same segment as writable data) */ /* uninitialized data (in same segment as writable data) */
.bss : {
__bss_start = .; __bss_start = .;
.bss : { *(.bss) } *(.shbss)
*(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON)
. = ALIGN(0x4);
__bss_end = .;
}
.stack : {
__stack_start = .;
. += IRQ_STACK_SIZE;
. = ALIGN(0x4);
__irq_stack_top = .;
. += FIQ_STACK_SIZE;
. = ALIGN(0x4);
__fiq_stack_top = .;
. += SVC_STACK_SIZE;
. = ALIGN(0x4);
__svc_stack_top = .;
. += ABT_STACK_SIZE;
. = ALIGN(0x4);
__abt_stack_top = .;
. += UND_STACK_SIZE;
. = ALIGN(0x4);
__und_stack_top = .;
. += C_STACK_SIZE;
. = ALIGN(0x4);
__c_stack_top = .;
__stack_end = .;
}
. = ALIGN(0x1000);
_end = . ; _end = . ;
/* Stabs debugging sections. */ /* Stabs debugging sections. */
.stab 0 : { *(.stab) } .stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) } .stabstr 0 : { *(.stabstr) }
/* DWARF debug sections. /* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */ of the section so we begin them at 0. */
@@ -61,7 +120,4 @@ SECTIONS
.debug_typenames 0 : { *(.debug_typenames) } .debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) } .debug_varnames 0 : { *(.debug_varnames) }
/* These must appear regardless of . */ /* These must appear regardless of . */
/* Strip unnecessary stuff */
/* /DISCARD/ : { *(.comment .note .eh_frame .dtors .stab .stabstr .debug*) }*/
} }