csu: Find the main pointer through the GOT

Use the Global Offset Table to find the location of main in crt1. With
lld the old code would point to main@plt, however ld.bfd fails to link
when main is in a shared library.

Fix this by using the GOT address to find main as it works with both
lld and bfd.

Reviewed by:	jrtc27
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D45259
This commit is contained in:
Andrew Turner 2024-05-22 08:18:10 +00:00
parent 8e82c5e28d
commit 53120fbb68

View file

@ -44,8 +44,8 @@ ENTRY(_start)
add x2, x1, x0, lsl #3 /* env is after argv */
add x2, x2, #8 /* argv is null terminated */
#ifdef PIC
adrp x4, main
add x4, x4, :lo12:main
adrp x4, :got:main
ldr x4, [x4, :got_lo12:main]
#else
ldr x4, =main
#endif