[libc] Properly call init functions and main through GOT

In the CRT startup code, when linked in a PIC executable, jumps to
`__init_libj6`, `__init_libc`, `main`, and `exit` were not linked
correctly. They needed a bit more support for looking up the GOT, and
getting the symbol address out of it.

Now libutil has a `got.inc` file for inclusion in asm code that needs to
reference symbols from the GOT.
This commit is contained in:
Justin C. Miller
2023-08-31 19:42:14 -07:00
parent fc16ed54b3
commit 97433fc7d1
2 changed files with 17 additions and 4 deletions

View File

@@ -0,0 +1,7 @@
extern _GLOBAL_OFFSET_TABLE_
; Put the address of the given symbol in rax
%macro lookup_GOT 1
lea rax, [rel _GLOBAL_OFFSET_TABLE_]
mov rax, [rax + %1 wrt ..got]
%endmacro