Skip to content

Commit

Permalink
sysdeps/{linux,managarm}: Set RISC-V gp from .preinit_array
Browse files Browse the repository at this point in the history
  • Loading branch information
avdgrinten committed Nov 29, 2024
1 parent c7bb359 commit c112513
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 24 deletions.
23 changes: 17 additions & 6 deletions sysdeps/linux/riscv64/crt-src/Scrt1.S
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
.weak __global_pointer$
.hidden __global_pointer$

.section .text
.global _start
_start:
.weak __global_pointer$
.hidden __global_pointer$
.option push
.option norelax
# Load gp.
.option push
.option norelax
lla gp, __global_pointer$
.option pop
.option pop

mv a0, sp
la a1, main
call __mlibc_entry@plt
unimp

# Load gp from .preinit_array since it may be used by the executable's .init_array.
# We still load it in _start to account for static binaries. This matches glibc's behavior.
load_gp:
.option push
.option norelax
lla gp, __global_pointer$
.option pop

.section .preinit_array,"aw"
.dword load_gp

.section .note.GNU-stack,"",%progbits

26 changes: 20 additions & 6 deletions sysdeps/linux/riscv64/crt-src/crt1.S
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
.weak __global_pointer$
.hidden __global_pointer$

.section .text
.global _start
_start:
.weak __global_pointer$
.hidden __global_pointer$
.option push
.option norelax
# Load gp.
.option push
.option norelax
lla gp, __global_pointer$
.option pop
.option pop

mv a0, sp
la a1, main
call __mlibc_entry
.section .note.GNU-stack,"",%progbits
unimp

# Load gp from .preinit_array since it may be used by the executable's .init_array.
# We still load it in _start to account for static binaries. This matches glibc's behavior.
load_gp:
.option push
.option norelax
lla gp, __global_pointer$
.option pop

.section .preinit_array,"aw"
.dword load_gp

.section .note.GNU-stack,"",%progbits
23 changes: 17 additions & 6 deletions sysdeps/managarm/riscv64/crt-src/Scrt1.S
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
.weak __global_pointer$
.hidden __global_pointer$

.section .text
.global _start
_start:
.weak __global_pointer$
.hidden __global_pointer$
.option push
.option norelax
# Load gp.
.option push
.option norelax
lla gp, __global_pointer$
.option pop
.option pop

mv a0, sp
la a1, main
call __mlibc_entry@plt
unimp

# Load gp from .preinit_array since it may be used by the executable's .init_array.
# We still load it in _start to account for static binaries. This matches glibc's behavior.
load_gp:
.option push
.option norelax
lla gp, __global_pointer$
.option pop

.section .preinit_array,"aw"
.dword load_gp

.section .note.GNU-stack,"",%progbits

26 changes: 20 additions & 6 deletions sysdeps/managarm/riscv64/crt-src/crt0.S
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
.weak __global_pointer$
.hidden __global_pointer$

.section .text
.global _start
_start:
.weak __global_pointer$
.hidden __global_pointer$
.option push
.option norelax
# Load gp.
.option push
.option norelax
lla gp, __global_pointer$
.option pop
.option pop

mv a0, sp
la a1, main
call __mlibc_entry
.section .note.GNU-stack,"",%progbits
unimp

# Load gp from .preinit_array since it may be used by the executable's .init_array.
# We still load it in _start to account for static binaries. This matches glibc's behavior.
load_gp:
.option push
.option norelax
lla gp, __global_pointer$
.option pop

.section .preinit_array,"aw"
.dword load_gp

.section .note.GNU-stack,"",%progbits

0 comments on commit c112513

Please sign in to comment.