From c9723d7b6821d6124bcf4f63b7035586f9e0fdda Mon Sep 17 00:00:00 2001 From: TuxSH Date: Sun, 27 May 2018 00:59:02 +0200 Subject: [PATCH] Refactor fusee's makefile --- fusee/fusee-primary/linker.ld | 65 +++++++++--------- .../src/exception_handlers_asm.s | 2 +- fusee/fusee-secondary/linker.ld | 66 ++++++++++--------- .../src/exception_handlers_asm.s | 2 +- 4 files changed, 70 insertions(+), 65 deletions(-) diff --git a/fusee/fusee-primary/linker.ld b/fusee/fusee-primary/linker.ld index 980ae2448..b442fd3b6 100644 --- a/fusee/fusee-primary/linker.ld +++ b/fusee/fusee-primary/linker.ld @@ -2,6 +2,13 @@ OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") OUTPUT_ARCH(arm) ENTRY(_start) +PHDRS +{ + crt0 PT_LOAD; + chainloader PT_LOAD; + main PT_LOAD; +} + /* Mostly copied from https://github.com/devkitPro/buildscripts/blob/master/dkarm-eabi/crtls/3dsx.ld */ MEMORY { @@ -19,42 +26,38 @@ SECTIONS PROVIDE(__heap_end__ = 0); . = __start__; - . = ALIGN(32); .crt0 : { - . = ALIGN(32); KEEP( *(.text.start) ) KEEP( *(.init) ) - . = ALIGN(4); - } >main + . = ALIGN(32); + } >main :crt0 .chainloader_loadable : { . = ALIGN(32); - PROVIDE (__chainloader_start__ = .); + PROVIDE (__chainloader_start__ = ABSOLUTE(.)); PROVIDE (__chainloader_lma__ = LOADADDR(.chainloader_loadable)); KEEP(*(.chainloader.text.start)) chainloader.o(.text*) chainloader.o(.rodata*) chainloader.o(.data*) - . = ALIGN(8); + . = ALIGN(32); + } >low_iram AT>main :chainloader - } >low_iram AT>main - - .chainloader_bss : + .chainloader_bss (NOLOAD) : { - . = ALIGN(8); - PROVIDE (__chainloader_bss_start__ = .); + . = ALIGN(32); + PROVIDE (__chainloader_bss_start__ = ABSOLUTE(.)); chainloader.o(.bss* COMMON) - . = ALIGN(8); - PROVIDE (__chainloader_end__ = .); - } >low_iram AT>main + . = ALIGN(32); + PROVIDE (__chainloader_end__ = ABSOLUTE(.)); + } >low_iram :NONE .text : { - . = ALIGN(4); - + . = ALIGN(32); /* .text */ *(.text) *(.text.*) @@ -63,12 +66,11 @@ SECTIONS *(.stub) *(.gnu.warning) *(.gnu.linkonce.t*) - . = ALIGN(4); /* .fini */ KEEP( *(.fini) ) - . = ALIGN(4); - } >main + . = ALIGN(8); + } >main :main .rodata : { @@ -78,10 +80,10 @@ SECTIONS *all.rodata*(*) *(.gnu.linkonce.r*) SORT(CONSTRUCTORS) - . = ALIGN(4); + . = ALIGN(8); } >main - .preinit_array ALIGN(4) : + .preinit_array : { PROVIDE (__preinit_array_start = .); KEEP (*(.preinit_array)) @@ -110,6 +112,7 @@ SECTIONS KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) KEEP (*(SORT(.ctors.*))) KEEP (*(.ctors)) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ } >main .dtors ALIGN(4) : @@ -118,12 +121,11 @@ SECTIONS KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) KEEP (*(SORT(.dtors.*))) KEEP (*(.dtors)) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ } >main - .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >main - __exidx_start = .; - ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } >main - __exidx_end = .; + .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) __exidx_start = ABSOLUTE(.);} >main + ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) __exidx_end = ABSOLUTE(.);} >main .data : { @@ -131,20 +133,21 @@ SECTIONS *(.data.*) *(.gnu.linkonce.d*) CONSTRUCTORS - . = ALIGN(4); + . = ALIGN(32); } >main - .bss : + .bss (NOLOAD) : { - __bss_start__ = ALIGN(32); + . = ALIGN(32); + PROVIDE (__bss_start__ = ABSOLUTE(.)); *(.dynbss) *(.bss) *(.bss.*) *(.gnu.linkonce.b*) *(COMMON) - . = ALIGN(8); - __bss_end__ = .; - } >main + . = ALIGN(32); + PROVIDE (__bss_end__ = ABSOLUTE(.)); + } >main :NONE __end__ = ABSOLUTE(.) ; /* ================== diff --git a/fusee/fusee-primary/src/exception_handlers_asm.s b/fusee/fusee-primary/src/exception_handlers_asm.s index 291b663ff..3a0be6514 100644 --- a/fusee/fusee-primary/src/exception_handlers_asm.s +++ b/fusee/fusee-primary/src/exception_handlers_asm.s @@ -16,7 +16,7 @@ .section .text.exception_handlers_asm, "ax", %progbits .arm -.align 4 +.align 5 _exception_handler_common: mrs r2, spsr diff --git a/fusee/fusee-secondary/linker.ld b/fusee/fusee-secondary/linker.ld index 614b97e77..0d7538c12 100644 --- a/fusee/fusee-secondary/linker.ld +++ b/fusee/fusee-secondary/linker.ld @@ -2,10 +2,16 @@ OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") OUTPUT_ARCH(arm) ENTRY(_start) +PHDRS +{ + crt0 PT_LOAD; + chainloader PT_LOAD; + main PT_LOAD; +} + /* Mostly copied from https://github.com/devkitPro/buildscripts/blob/master/dkarm-eabi/crtls/3dsx.ld */ MEMORY { - NULL : ORIGIN = 0x00000000, LENGTH = 0x1000 main : ORIGIN = 0xF0000000, LENGTH = 0x10000000 low_iram : ORIGIN = 0x40003000, LENGTH = 0x8000 } @@ -19,42 +25,38 @@ SECTIONS PROVIDE(__heap_end__ = 0xF0000000); . = __start__; - . = ALIGN(32); .crt0 : { - . = ALIGN(32); KEEP( *(.text.start) ) KEEP( *(.init) ) - . = ALIGN(4); - } >main + . = ALIGN(32); + } >main :crt0 .chainloader_loadable : { . = ALIGN(32); - PROVIDE (__chainloader_start__ = .); + PROVIDE (__chainloader_start__ = ABSOLUTE(.)); PROVIDE (__chainloader_lma__ = LOADADDR(.chainloader_loadable)); KEEP(*(.chainloader.text.start)) chainloader.o(.text*) chainloader.o(.rodata*) chainloader.o(.data*) - . = ALIGN(8); + . = ALIGN(32); + } >low_iram AT>main :chainloader - } >low_iram AT>main - - .chainloader_bss : + .chainloader_bss (NOLOAD) : { - . = ALIGN(8); - PROVIDE (__chainloader_bss_start__ = .); + . = ALIGN(32); + PROVIDE (__chainloader_bss_start__ = ABSOLUTE(.)); chainloader.o(.bss* COMMON) - . = ALIGN(8); - PROVIDE (__chainloader_end__ = .); - } >low_iram AT>main + . = ALIGN(32); + PROVIDE (__chainloader_end__ = ABSOLUTE(.)); + } >low_iram :NONE .text : { - . = ALIGN(4); - + . = ALIGN(32); /* .text */ *(.text) *(.text.*) @@ -63,12 +65,11 @@ SECTIONS *(.stub) *(.gnu.warning) *(.gnu.linkonce.t*) - . = ALIGN(4); /* .fini */ KEEP( *(.fini) ) - . = ALIGN(4); - } >main + . = ALIGN(8); + } >main :main .rodata : { @@ -78,10 +79,10 @@ SECTIONS *all.rodata*(*) *(.gnu.linkonce.r*) SORT(CONSTRUCTORS) - . = ALIGN(4); + . = ALIGN(8); } >main - .preinit_array ALIGN(4) : + .preinit_array : { PROVIDE (__preinit_array_start = .); KEEP (*(.preinit_array)) @@ -110,6 +111,7 @@ SECTIONS KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) KEEP (*(SORT(.ctors.*))) KEEP (*(.ctors)) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ } >main .dtors ALIGN(4) : @@ -118,12 +120,11 @@ SECTIONS KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) KEEP (*(SORT(.dtors.*))) KEEP (*(.dtors)) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ } >main - .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >main - __exidx_start = .; - ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } >main - __exidx_end = .; + .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) __exidx_start = ABSOLUTE(.);} >main + ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) __exidx_end = ABSOLUTE(.);} >main .data : { @@ -131,20 +132,21 @@ SECTIONS *(.data.*) *(.gnu.linkonce.d*) CONSTRUCTORS - . = ALIGN(4); + . = ALIGN(32); } >main - .bss : + .bss (NOLOAD) : { - __bss_start__ = ALIGN(32); + . = ALIGN(32); + PROVIDE (__bss_start__ = ABSOLUTE(.)); *(.dynbss) *(.bss) *(.bss.*) *(.gnu.linkonce.b*) *(COMMON) - . = ALIGN(8); - __bss_end__ = .; - } >main + . = ALIGN(32); + PROVIDE (__bss_end__ = ABSOLUTE(.)); + } >main :NONE __end__ = ABSOLUTE(.) ; /* ================== diff --git a/fusee/fusee-secondary/src/exception_handlers_asm.s b/fusee/fusee-secondary/src/exception_handlers_asm.s index 291b663ff..3a0be6514 100644 --- a/fusee/fusee-secondary/src/exception_handlers_asm.s +++ b/fusee/fusee-secondary/src/exception_handlers_asm.s @@ -16,7 +16,7 @@ .section .text.exception_handlers_asm, "ax", %progbits .arm -.align 4 +.align 5 _exception_handler_common: mrs r2, spsr