mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-10 06:01:52 +00:00
Refactor exosphère's linker script
To properly separate text/rodata/data+bss, page-alignment needs to be added, as well as some symbol definitions and support code...
This commit is contained in:
parent
d57f4c54a9
commit
ad5be3cae5
1 changed files with 75 additions and 63 deletions
|
@ -1,9 +1,21 @@
|
||||||
OUTPUT_ARCH(aarch64)
|
OUTPUT_ARCH(aarch64)
|
||||||
ENTRY(__start_cold)
|
ENTRY(__start_cold)
|
||||||
|
|
||||||
|
PHDRS
|
||||||
|
{
|
||||||
|
ccrt0 PT_LOAD FLAGS(7) /* Read | Write | Execute */;
|
||||||
|
pk2ldr PT_LOAD FLAGS(7) /* Read | Write | Execute */;
|
||||||
|
wcrt0 PT_LOAD FLAGS(7) /* Read | Write | Execute */;
|
||||||
|
|
||||||
|
code PT_LOAD FLAGS(5) /* Read | Execute */;
|
||||||
|
rodata PT_LOAD FLAGS(4) /* Read */;
|
||||||
|
data PT_LOAD FLAGS(6) /* Read | Write */;
|
||||||
|
|
||||||
|
evt PT_LOAD FLAGS(5) /* Read | Execute */;
|
||||||
|
}
|
||||||
|
|
||||||
MEMORY
|
MEMORY
|
||||||
{
|
{
|
||||||
NULL : ORIGIN = 0, LENGTH = 4K
|
|
||||||
ccrt0 : ORIGIN = 0x040006000, LENGTH = 4K
|
ccrt0 : ORIGIN = 0x040006000, LENGTH = 4K
|
||||||
glob : ORIGIN = 0x040020000, LENGTH = 128K
|
glob : ORIGIN = 0x040020000, LENGTH = 128K
|
||||||
tzram : ORIGIN = 0x07C010000, LENGTH = 64K
|
tzram : ORIGIN = 0x07C010000, LENGTH = 64K
|
||||||
|
@ -12,11 +24,11 @@ MEMORY
|
||||||
Normally the main code immediately follows the warmboot crt0, aligned to 256 bytes.
|
Normally the main code immediately follows the warmboot crt0, aligned to 256 bytes.
|
||||||
We can't ensure or replicate that behavior properly so we'll just give 2K to the warmboot crt0.
|
We can't ensure or replicate that behavior properly so we'll just give 2K to the warmboot crt0.
|
||||||
*/
|
*/
|
||||||
warmboot_crt0 : ORIGIN = ORIGIN(tzram) + 12K, LENGTH = 2K
|
wcrt0 : ORIGIN = ORIGIN(tzram) + 12K, LENGTH = 2K
|
||||||
|
|
||||||
/* 8K are the MMU L2 and L3 tables & 2K from the evt page */
|
/* 8K are the MMU L2 and L3 tables & 2K from the evt page */
|
||||||
main : ORIGIN = 0x1F01E0000 + LENGTH(warmboot_crt0), LENGTH = LENGTH(tzram) - LENGTH(pk2ldr) - LENGTH(evt) - LENGTH(warmboot_crt0) - 10K
|
main : ORIGIN = 0x1F01E0000 + LENGTH(wcrt0), LENGTH = LENGTH(tzram) - LENGTH(pk2ldr) - LENGTH(evt) - LENGTH(wcrt0) - 10K
|
||||||
pk2ldr : ORIGIN = ORIGIN(main) - LENGTH(warmboot_crt0) + LENGTH(tzram), LENGTH = 8K
|
pk2ldr : ORIGIN = ORIGIN(main) - LENGTH(wcrt0) + LENGTH(tzram), LENGTH = 8K
|
||||||
/* The first half of the page are exception entry stacks, the other half are the vectors themselves */
|
/* The first half of the page are exception entry stacks, the other half are the vectors themselves */
|
||||||
evt : ORIGIN = ORIGIN(pk2ldr) + 40K + 2K, LENGTH = 2K
|
evt : ORIGIN = ORIGIN(pk2ldr) + 40K + 2K, LENGTH = 2K
|
||||||
}
|
}
|
||||||
|
@ -24,7 +36,7 @@ MEMORY
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
PROVIDE(__start__ = 0x040006000);
|
PROVIDE(__start__ = 0x040006000);
|
||||||
. = __start__;
|
. = ABSOLUTE(__start__);
|
||||||
|
|
||||||
.cold_crt0 :
|
.cold_crt0 :
|
||||||
{
|
{
|
||||||
|
@ -43,7 +55,7 @@ SECTIONS
|
||||||
coldboot_init.o(.bss* COMMON)
|
coldboot_init.o(.bss* COMMON)
|
||||||
. = ALIGN(64);
|
. = ALIGN(64);
|
||||||
__cold_crt0_end__ = ABSOLUTE(.);
|
__cold_crt0_end__ = ABSOLUTE(.);
|
||||||
} >ccrt0 AT>glob
|
} >ccrt0 AT>glob :ccrt0
|
||||||
|
|
||||||
.pk2ldr :
|
.pk2ldr :
|
||||||
{
|
{
|
||||||
|
@ -53,17 +65,17 @@ SECTIONS
|
||||||
KEEP (package2.o(.text*))
|
KEEP (package2.o(.text*))
|
||||||
package2.o(.rodata*)
|
package2.o(.rodata*)
|
||||||
package2.o(.data*)
|
package2.o(.data*)
|
||||||
. = ALIGN(8);
|
. = ALIGN(32);
|
||||||
} >pk2ldr AT>glob
|
} >pk2ldr AT>glob :pk2ldr
|
||||||
|
|
||||||
.pk2ldr.bss :
|
.pk2ldr.bss (NOLOAD) :
|
||||||
{
|
{
|
||||||
. = ALIGN(8);
|
. = ALIGN(32);
|
||||||
__pk2ldr_bss_start__ = ABSOLUTE(.);
|
__pk2ldr_bss_start__ = ABSOLUTE(.);
|
||||||
package2.o(.bss* COMMON)
|
package2.o(.bss* COMMON)
|
||||||
. = ALIGN(8);
|
. = ALIGN(32);
|
||||||
__pk2ldr_end__ = ABSOLUTE(.);
|
__pk2ldr_end__ = ABSOLUTE(.);
|
||||||
} >pk2ldr AT>glob
|
} >pk2ldr :NONE
|
||||||
|
|
||||||
.vectors :
|
.vectors :
|
||||||
{
|
{
|
||||||
|
@ -73,7 +85,7 @@ SECTIONS
|
||||||
KEEP (*(.vectors*))
|
KEEP (*(.vectors*))
|
||||||
. = ALIGN(8);
|
. = ALIGN(8);
|
||||||
__vectors_end__ = ABSOLUTE(.);
|
__vectors_end__ = ABSOLUTE(.);
|
||||||
} >evt AT>glob
|
} >evt AT>glob :evt
|
||||||
|
|
||||||
.warm_crt0 :
|
.warm_crt0 :
|
||||||
{
|
{
|
||||||
|
@ -92,7 +104,9 @@ SECTIONS
|
||||||
warmboot_init.o(.bss*)
|
warmboot_init.o(.bss*)
|
||||||
. = ALIGN(64);
|
. = ALIGN(64);
|
||||||
__warmboot_crt0_end__ = ABSOLUTE(.);
|
__warmboot_crt0_end__ = ABSOLUTE(.);
|
||||||
} >warmboot_crt0 AT>glob
|
} >wcrt0 AT>glob :wcrt0
|
||||||
|
|
||||||
|
/* =========== CODE section =========== */
|
||||||
|
|
||||||
.text :
|
.text :
|
||||||
{
|
{
|
||||||
|
@ -104,47 +118,64 @@ SECTIONS
|
||||||
*(.text.startup .text.startup.*)
|
*(.text.startup .text.startup.*)
|
||||||
*(.text.hot .text.hot.*)
|
*(.text.hot .text.hot.*)
|
||||||
*(.text .stub .text.* .gnu.linkonce.t.*)
|
*(.text .stub .text.* .gnu.linkonce.t.*)
|
||||||
. = ALIGN(8);
|
. = ALIGN(32);
|
||||||
} >main AT>glob
|
} >main AT>glob :code
|
||||||
|
|
||||||
.init :
|
.init :
|
||||||
{
|
{
|
||||||
KEEP( *(.init) )
|
KEEP( *(.init) )
|
||||||
. = ALIGN(8);
|
. = ALIGN(8);
|
||||||
} >main AT>glob
|
} >main AT>glob :code
|
||||||
|
|
||||||
.plt :
|
.plt :
|
||||||
{
|
{
|
||||||
*(.plt)
|
*(.plt)
|
||||||
*(.iplt)
|
*(.iplt)
|
||||||
. = ALIGN(8);
|
. = ALIGN(8);
|
||||||
} >main AT>glob
|
} >main AT>glob :code
|
||||||
|
|
||||||
|
|
||||||
.fini :
|
.fini :
|
||||||
{
|
{
|
||||||
KEEP( *(.fini) )
|
KEEP( *(.fini) )
|
||||||
. = ALIGN(8);
|
. = ALIGN(8);
|
||||||
} >main AT>glob
|
} >main AT>glob :code
|
||||||
|
|
||||||
|
/* =========== RODATA section =========== */
|
||||||
|
|
||||||
.rodata :
|
.rodata :
|
||||||
{
|
{
|
||||||
*(.rodata .rodata.* .gnu.linkonce.r.*)
|
*(.rodata .rodata.* .gnu.linkonce.r.*)
|
||||||
SORT(CONSTRUCTORS)
|
|
||||||
. = ALIGN(8);
|
. = ALIGN(8);
|
||||||
} >main AT>glob
|
} >main AT>glob :rodata
|
||||||
|
|
||||||
.got : { __got_start__ = ABSOLUTE(.); *(.got) *(.igot) } >main AT>glob
|
.eh_frame_hdr : ONLY_IF_RO { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) } >main AT>glob :rodata
|
||||||
.got.plt : { *(.got.plt) *(.igot.plt) __got_end__ = ABSOLUTE(.);} >main AT>glob
|
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) *(.eh_frame.*) } >main AT>glob :rodata
|
||||||
|
.gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) } >main AT>glob :rodata
|
||||||
|
.gnu_extab : ONLY_IF_RO { *(.gnu_extab*) } >main AT>glob :rodata
|
||||||
|
.exception_ranges : ONLY_IF_RO { *(.exception_ranges .exception_ranges*) } >main AT>glob :rodata
|
||||||
|
|
||||||
.preinit_array :
|
.note.gnu.build-id : { *(.note.gnu.build-id) } >main AT>glob :rodata
|
||||||
|
.hash : { *(.hash) } >main AT>glob :rodata
|
||||||
|
.gnu.hash : { *(.gnu.hash) } >main AT>glob :rodata
|
||||||
|
.gnu.version : { *(.gnu.version) } >main AT>glob :rodata
|
||||||
|
.gnu.version_d : { *(.gnu.version_d) } >main AT>glob :rodata
|
||||||
|
.gnu.version_r : { *(.gnu.version_r) } >main AT>glob :rodata
|
||||||
|
|
||||||
|
/* =========== DATA section =========== */
|
||||||
|
|
||||||
|
.eh_frame_hdr : ONLY_IF_RW { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) } >main AT>glob :data
|
||||||
|
.eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) } >main AT>glob :data
|
||||||
|
.gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) } >main AT>glob :data
|
||||||
|
.gnu_extab : ONLY_IF_RW { *(.gnu_extab*) } >main AT>glob :data
|
||||||
|
.exception_ranges : ONLY_IF_RW { *(.exception_ranges .exception_ranges*) } >main AT>glob :data
|
||||||
|
|
||||||
|
.preinit_array ALIGN(8) :
|
||||||
{
|
{
|
||||||
. = ALIGN(8);
|
|
||||||
PROVIDE (__preinit_array_start = .);
|
PROVIDE (__preinit_array_start = .);
|
||||||
KEEP (*(.preinit_array))
|
KEEP (*(.preinit_array))
|
||||||
PROVIDE (__preinit_array_end = .);
|
PROVIDE (__preinit_array_end = .);
|
||||||
. = ALIGN(8);
|
. = ALIGN(8);
|
||||||
} >main AT>glob
|
} >main AT>glob :data
|
||||||
|
|
||||||
.init_array :
|
.init_array :
|
||||||
{
|
{
|
||||||
|
@ -152,75 +183,56 @@ SECTIONS
|
||||||
KEEP (*(SORT(.init_array.*)))
|
KEEP (*(SORT(.init_array.*)))
|
||||||
KEEP (*(.init_array))
|
KEEP (*(.init_array))
|
||||||
PROVIDE (__init_array_end = .);
|
PROVIDE (__init_array_end = .);
|
||||||
} >main AT>glob
|
} >main AT>glob :data
|
||||||
|
|
||||||
.fini_array :
|
.fini_array :
|
||||||
{
|
{
|
||||||
. = ALIGN(8);
|
|
||||||
PROVIDE (__fini_array_start = .);
|
PROVIDE (__fini_array_start = .);
|
||||||
KEEP (*(.fini_array))
|
KEEP (*(.fini_array))
|
||||||
KEEP (*(SORT(.fini_array.*)))
|
KEEP (*(SORT(.fini_array.*)))
|
||||||
PROVIDE (__fini_array_end = .);
|
PROVIDE (__fini_array_end = .);
|
||||||
. = ALIGN(8);
|
. = ALIGN(8);
|
||||||
} >main AT>glob
|
} >main AT>glob :data
|
||||||
|
|
||||||
.ctors :
|
.ctors :
|
||||||
{
|
{
|
||||||
. = ALIGN(8);
|
|
||||||
KEEP (*crtbegin.o(.ctors)) /* MUST be first -- GCC requires it */
|
KEEP (*crtbegin.o(.ctors)) /* MUST be first -- GCC requires it */
|
||||||
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
|
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
|
||||||
KEEP (*(SORT(.ctors.*)))
|
KEEP (*(SORT(.ctors.*)))
|
||||||
KEEP (*(.ctors))
|
KEEP (*(.ctors))
|
||||||
. = ALIGN(8);
|
. = ALIGN(8);
|
||||||
} >main AT>glob
|
} >main AT>glob :data
|
||||||
|
|
||||||
.dtors ALIGN(8) :
|
.dtors :
|
||||||
{
|
{
|
||||||
. = ALIGN(8);
|
|
||||||
KEEP (*crtbegin.o(.dtors))
|
KEEP (*crtbegin.o(.dtors))
|
||||||
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
|
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
|
||||||
KEEP (*(SORT(.dtors.*)))
|
KEEP (*(SORT(.dtors.*)))
|
||||||
KEEP (*(.dtors))
|
KEEP (*(.dtors))
|
||||||
. = ALIGN(8);
|
. = ALIGN(8);
|
||||||
} >main AT>glob
|
} >main AT>glob :data
|
||||||
|
|
||||||
.data ALIGN(8) :
|
.got : { __got_start__ = ABSOLUTE(.); *(.got) *(.igot) } >main AT>glob :data
|
||||||
|
.got.plt : { *(.got.plt) *(.igot.plt) __got_end__ = ABSOLUTE(.);} >main AT>glob :data
|
||||||
|
|
||||||
|
.data :
|
||||||
{
|
{
|
||||||
*(.data .data.* .gnu.linkonce.d.*)
|
*(.data .data.* .gnu.linkonce.d.*)
|
||||||
CONSTRUCTORS
|
SORT(CONSTRUCTORS)
|
||||||
. = ALIGN(8);
|
. = ALIGN(32);
|
||||||
} >main AT>glob
|
} >main AT>glob :data
|
||||||
|
|
||||||
|
.bss (NOLOAD) :
|
||||||
.eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) } >main AT>glob
|
|
||||||
.eh_frame : { KEEP (*(.eh_frame)) *(.eh_frame.*) } >main AT>glob
|
|
||||||
.gcc_except_table : { *(.gcc_except_table .gcc_except_table.*) } >main AT>glob
|
|
||||||
.gnu_extab : { *(.gnu_extab*) } >main AT>glob
|
|
||||||
.exception_ranges : { *(.exception_ranges .exception_ranges*) } >main AT>glob
|
|
||||||
|
|
||||||
.dynamic : { *(.dynamic) } >main AT>glob
|
|
||||||
.interp : { *(.interp) } >main AT>glob
|
|
||||||
.note.gnu.build-id : { *(.note.gnu.build-id) } >main AT>glob
|
|
||||||
.hash : { *(.hash) } >main AT>glob
|
|
||||||
.gnu.hash : { *(.gnu.hash) } >main AT>glob
|
|
||||||
.gnu.version : { *(.gnu.version) } >main AT>glob
|
|
||||||
.gnu.version_d : { *(.gnu.version_d) } >main AT>glob
|
|
||||||
.gnu.version_r : { *(.gnu.version_r) } >main AT>glob
|
|
||||||
.dynsym : { *(.dynsym) } >main AT>glob
|
|
||||||
.dynstr : { *(.dynstr) } >main AT>glob
|
|
||||||
.rela.dyn : { *(.rela.*); __main_end__ = ABSOLUTE(.);} >main AT>glob
|
|
||||||
|
|
||||||
.bss :
|
|
||||||
{
|
{
|
||||||
. = ALIGN(8);
|
. = ALIGN(32);
|
||||||
__main_bss_start__ = ABSOLUTE(.);
|
__main_bss_start__ = ABSOLUTE(.);
|
||||||
__loaded_end_lma__ = LOADADDR(.bss);
|
__loaded_end_lma__ = LOADADDR(.bss);
|
||||||
*(.dynbss)
|
*(.dynbss)
|
||||||
*(.bss .bss.* .gnu.linkonce.b.*)
|
*(.bss .bss.* .gnu.linkonce.b.*)
|
||||||
*(COMMON)
|
*(COMMON)
|
||||||
. = ALIGN(8);
|
. = ALIGN(32);
|
||||||
__main_end__ = ABSOLUTE(.);
|
__main_end__ = ABSOLUTE(.);
|
||||||
} >main AT>glob
|
} >main :NONE
|
||||||
|
|
||||||
__end__ = ABSOLUTE(.) ;
|
__end__ = ABSOLUTE(.) ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue