mirror of
https://github.com/switchbrew/libnx.git
synced 2025-08-05 16:09:24 +02:00
First attempt at GOT
This commit is contained in:
parent
b39773b1d4
commit
a2c7efe618
@ -2,5 +2,5 @@ install:
|
|||||||
cp base_rules $(DEVKITA64)/
|
cp base_rules $(DEVKITA64)/
|
||||||
cp base_tools $(DEVKITA64)/
|
cp base_tools $(DEVKITA64)/
|
||||||
cp switch_rules $(DEVKITA64)/
|
cp switch_rules $(DEVKITA64)/
|
||||||
cp lib/switch.ld $(DEVKITA64)/lib/
|
cp lib/switch.ld $(DEVKITA64)/aarch64-none-elf/lib/
|
||||||
cp lib/switch.specs $(DEVKITA64)/lib/
|
cp lib/switch.specs $(DEVKITA64)/aarch64-none-elf/lib/
|
||||||
|
@ -63,10 +63,13 @@ SECTIONS
|
|||||||
*(.data.*)
|
*(.data.*)
|
||||||
*(.gnu.linkonce.d*)
|
*(.gnu.linkonce.d*)
|
||||||
CONSTRUCTORS
|
CONSTRUCTORS
|
||||||
*(.got)
|
|
||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
|
__got_start__ = .;
|
||||||
|
*(.got)
|
||||||
|
__got_end__ = .;
|
||||||
} : data
|
} : data
|
||||||
|
|
||||||
|
|
||||||
.tdata ALIGN(4) :
|
.tdata ALIGN(4) :
|
||||||
{
|
{
|
||||||
__tdata_lma = .;
|
__tdata_lma = .;
|
||||||
|
@ -1,40 +1,47 @@
|
|||||||
.section ".crt0","ax"
|
.section ".crt0","ax"
|
||||||
.global _start, _sysexit, main
|
.global _start, _sysexit, main
|
||||||
_start:
|
_start:
|
||||||
b startup
|
bl startup
|
||||||
|
|
||||||
.word 0x454d4f48
|
.word 0x454d4f48
|
||||||
.word 0x57455242
|
.word 0x57455242
|
||||||
|
|
||||||
startup:
|
startup:
|
||||||
mov x4, x30
|
// get aslr base
|
||||||
|
sub x30, x30, #4
|
||||||
|
|
||||||
// clear .bss
|
// clear .bss
|
||||||
ldr x0, =__bss_start__
|
ldr x0, =__bss_start__
|
||||||
ldr x1, =__bss_end__
|
ldr x1, =__bss_end__
|
||||||
sub x1, x1, x0
|
sub x1, x1, x0
|
||||||
bl ClearMem
|
add x1, x1, #7
|
||||||
|
bic x1, x1, #7
|
||||||
|
mov x2, #0
|
||||||
|
|
||||||
mov x0, #0 // argc
|
bss_loop:
|
||||||
mov x1, #0 // argv
|
str x2, [x0], #8
|
||||||
|
subs x1, x1, #8
|
||||||
|
bne bss_loop
|
||||||
|
|
||||||
ldr x3, =main
|
// relocate .got
|
||||||
blr x3
|
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:
|
_sysexit:
|
||||||
svc 0x7
|
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
|
|
||||||
|
Loading…
Reference in New Issue
Block a user