mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
[ld.so] Add a minimal dynamic linker
This commit includes a number of changes to enable loading of PIE executables: - The loader in srv.init checks for a `PT_INTERP` segment in the program its loading, and if it exists, loads the specified interpreter and passes control to it instead of the program itself. - Added ld.so the dynamic linker executable and set it as the interpreter for all user-target programs. - Program initial stack changed again to now contain a number of possible tagged structures, including a new one for ld.so's arguments, and for passing handles tagged with protocol ids. - Added a stub for a new VFS protocol. Unused so far, but srv.init will need to serve VFS requests from ld.so once I transition libraries to shared libs for user-target programs. (Right now all executables are PIE but statically linked, so they only need internal relocations.) - Added 16 and 8 bit variants of `util::bitset`. This ended up not being used, but could be useful.
This commit is contained in:
33
src/user/ld.so/start.s
Normal file
33
src/user/ld.so/start.s
Normal file
@@ -0,0 +1,33 @@
|
||||
extern ldso_init
|
||||
extern _GLOBAL_OFFSET_TABLE_
|
||||
|
||||
global _ldso_start:function hidden (_ldso_start.end - _ldso_start)
|
||||
_ldso_start:
|
||||
mov rbp, rsp
|
||||
|
||||
; Save off anything that might be a function arg
|
||||
push rdi
|
||||
push rsi
|
||||
push rdx
|
||||
push rcx
|
||||
push r8
|
||||
push r9
|
||||
|
||||
; Call ldso_init with the loader-provided stack data and
|
||||
; also the address of the GOT, since clang refuses to take
|
||||
; the address of it, only dereference it.
|
||||
mov rdi, rbp
|
||||
lea rsi, [rel _GLOBAL_OFFSET_TABLE_]
|
||||
call ldso_init
|
||||
; The real program's entrypoint is now in rax
|
||||
|
||||
; Put the function call params back
|
||||
pop r9
|
||||
pop r8
|
||||
pop rcx
|
||||
pop rdx
|
||||
pop rsi
|
||||
pop rdi
|
||||
|
||||
jmp rax
|
||||
.end:
|
||||
Reference in New Issue
Block a user