NetBSD/libexec/ld.elf_so
kamil 4e9bea3d5d Implement and integrate GNU Hashing function
Define Elf_Hash struct that contains ELF/SYSV and GNU hash checksum.
Implement _rtld_gnu_hash() for DT_GNU_HASH.
Adapt existing code to compute all Elf_Hash types, instead of only
the ELF/SYSV one.
Rename _rtld_elf_hash() to _rtld_sysv_hash() to match the GNU toolchain
terminology.

_rtld_gnu_hash() uses Dan Bernstein's string hash function posted eons ago
on comp.lang.c.
2020-02-29 04:23:05 +00:00
..
arch Use existing lo() and hi() macros. Same object code is generated. 2019-12-08 23:49:16 +00:00
compat.c Move compatibility for pre-2.0 ELF binaries into separate file. 2018-10-17 23:36:58 +00:00
debug.c
debug.h Fix DEBUG build. 2013-08-03 13:17:05 +00:00
diagassert.c This version of __diagssert13 is dead. 2012-03-16 11:44:54 +00:00
expand.c Trailing whitespace 2013-05-06 08:02:20 +00:00
headers.c Add support for DT_RUNPATH - it is just the same as we always have treated 2018-12-30 11:55:15 +00:00
ld.elf_so.1 $ORIGIN support is now enabled. 2019-04-15 10:17:01 +00:00
load.c need <sys/stat.h> 2017-01-10 21:08:48 +00:00
Makefile Specify NOLIBCSANITIZER for the ELF loader 2020-02-09 09:11:59 +00:00
map_object.c When loading a non-PIE main binary, the virtual address must match. 2019-01-06 19:44:54 +00:00
paths.c we don't need <sys/mbuf.h> 2016-01-24 01:56:04 +00:00
README.TLS Fix typos 2018-12-01 13:01:57 +00:00
reloc.c Implement and integrate GNU Hashing function 2020-02-29 04:23:05 +00:00
rtld.c Implement and integrate GNU Hashing function 2020-02-29 04:23:05 +00:00
rtld.h Implement and integrate GNU Hashing function 2020-02-29 04:23:05 +00:00
rtldenv.h Trailing whitespace 2013-05-06 08:02:20 +00:00
search.c use strlcpy to ensure termination. 2019-10-13 20:18:42 +00:00
symbol.c Implement and integrate GNU Hashing function 2020-02-29 04:23:05 +00:00
symbols.map Implement __cxa_thread_atexit and __cxa_thread_atexit_impl. This 2017-07-11 15:21:31 +00:00
symver.c convert to SIMPLEQ like the rest of the queues. 2013-05-09 15:38:14 +00:00
sysident.h Actually, descsz should not contain the padding. The note still needs to 2016-02-09 10:20:03 +00:00
tls.c Use alignof and not size_t for platforms with non-natural base 2019-11-05 22:22:42 +00:00
TODO Add TLS support infrastructure. For dynamic binaries, ld.elf_so exports 2011-03-09 23:10:05 +00:00
xmalloc.c don't free cp before we copy it! 2013-01-24 17:57:29 +00:00
xprintf.c Fix typo in a comment. 2019-12-08 22:41:42 +00:00

Steps for adding TLS support for a new platform:

(1) Declare TLS variant in machine/types.h by defining either
__HAVE_TLS_VARIANT_I or __HAVE_TLS_VARIANT_II.

(2) _lwp_makecontext has to set the reserved register or kernel transfer
variable in uc_mcontext to the provided value of 'private'. See
src/lib/libc/arch/$PLATFORM/gen/_lwp.c.

This is not possible on the VAX as there is no free space in ucontext_t.
This requires either a special version of _lwp_create or versioning
everything using ucontext_t. Debug support depends on getting the data from
ucontext_t, so the second option is possibly required.

(3) _lwp_setprivate(2) has to update the same register as
_lwp_makecontext uses for the private area pointer. Normally
cpu_lwp_setprivate is provided by MD to reflect the kernel view and
enabled by defining __HAVE_CPU_LWP_SETPRIVATE in machine/types.h.
cpu_setmcontext is responsible for keeping the MI l_private field
synchronised by calling lwp_setprivate as needed.

cpu_switchto has to update the mapping.

_lwp_setprivate is used for the initial thread, all other threads
created by libpthread use _lwp_makecontext for this purpose.

(4) Provide __tls_get_addr and possible other MD functions for dynamic
TLS offset computation. If such alternative entry points exist (currently
only i386), also add a weak reference to 0 in src/lib/libc/tls/tls.c.

The generic implementation can be found in tls.c and is used with
__HAVE_COMMON___TLS_GET_ADDR. It depends on __lwp_getprivate_fast
(see below).

(5) Implement the necessary relocation records in mdreloc.c.  There are
typically three relocation types found in dynamic binaries:

(a) R_TYPE(TLS_DTPOFF): Offset inside the module.  The common TLS code
ensures that the DTV vector points to offset 0 inside the module TLS block.
This is normally def->st_value + rela->r_addend.

(b) R_TYPE(TLS_DTPMOD): Module index.

(c) R_TYPE(TLS_TPOFF): Static TLS offset.  The code has to check whether
the static TLS offset for this module has been allocated
(defobj->tls_done) and otherwise call _rtld_tls_offset_allocate().  This
may fail if no static space is available and the object has been pulled
in via dlopen(3).

For TLS Variant I, this is typically:

def->st_value + rela->r_addend + defobj->tlsoffset + sizeof(struct tls_tcb)

e.g. the relocation doesn't include the fixed TCB.

For TLS Variant II, this is typically:

def->st_value - defobj->tlsoffset + rela->r_addend

e.g. starting offset is counting down from the TCB.

(6) Implement __lwp_getprivate_fast() in machine/mcontext.h and set
__HAVE___LWP_GETPRIVATE_FAST in machine/types.h.

(7) Test using src/tests/lib/libc/tls.  Make sure with "objdump -R" that
t_tls_dynamic has two TPOFF relocations and h_tls_dlopen.so.1 and
libh_tls_dynamic.so.1 have both two DTPMOD and DTPOFF relocations.