diff --git a/buildscripts/Makefile b/buildscripts/Makefile index f92b65ae..3ed1269b 100644 --- a/buildscripts/Makefile +++ b/buildscripts/Makefile @@ -2,5 +2,5 @@ install: cp base_rules $(DEVKITA64)/ cp base_tools $(DEVKITA64)/ cp switch_rules $(DEVKITA64)/ - cp lib/switch.ld $(DEVKITA64)/lib/ - cp lib/switch.specs $(DEVKITA64)/lib/ + cp lib/switch.ld $(DEVKITA64)/aarch64-none-elf/lib/ + cp lib/switch.specs $(DEVKITA64)/aarch64-none-elf/lib/ diff --git a/buildscripts/lib/switch.ld b/buildscripts/lib/switch.ld index 727d0ed1..d96a01d8 100644 --- a/buildscripts/lib/switch.ld +++ b/buildscripts/lib/switch.ld @@ -63,10 +63,13 @@ SECTIONS *(.data.*) *(.gnu.linkonce.d*) CONSTRUCTORS - *(.got) . = ALIGN(4); + __got_start__ = .; + *(.got) + __got_end__ = .; } : data + .tdata ALIGN(4) : { __tdata_lma = .; diff --git a/crt0/switch_crt0.s b/crt0/switch_crt0.s index 6413d200..f6d6b120 100644 --- a/crt0/switch_crt0.s +++ b/crt0/switch_crt0.s @@ -1,40 +1,47 @@ .section ".crt0","ax" .global _start, _sysexit, main _start: - b startup + bl startup .word 0x454d4f48 .word 0x57455242 startup: - mov x4, x30 + // get aslr base + sub x30, x30, #4 // clear .bss - ldr x0, =__bss_start__ - ldr x1, =__bss_end__ - sub x1, x1, x0 - bl ClearMem + ldr x0, =__bss_start__ + ldr x1, =__bss_end__ + sub x1, x1, x0 + add x1, x1, #7 + bic x1, x1, #7 + mov x2, #0 - mov x0, #0 // argc - mov x1, #0 // argv +bss_loop: + str x2, [x0], #8 + subs x1, x1, #8 + bne bss_loop - ldr x3, =main - blr x3 + // relocate .got + ldr x0, =__got_start__ + ldr x1, =__got_end__ + sub x1, x1, x0 + add x1, x1, #3 + bic x1, x1, #3 + +got_loop: + ldr x2, [x0] + add x2, x2, x30 + str x2, [x0], #8 + subs x1, x1, #8 + bne got_loop + + mov x0, #0 // argc + mov x1, #0 // argv + + ldr x3, =main + blr x3 _sysexit: - svc 0x7 - -ClearMem: - mov x2, #3 // Round down to nearest word boundary - add x1, x1, x2 // Shouldn't be needed - bics x1, x1, x2 // Clear 2 LSB (and set Z) - beq ClearMem_end // Quit if copy size is 0 - - mov x2, #0 -ClrLoop: - str x2, [x0], #4 - subs x1, x1, #4 - bne ClrLoop - -ClearMem_end: - ret + svc 0x7