diff options
author | kib <kib@FreeBSD.org> | 2012-03-11 20:03:09 +0000 |
---|---|---|
committer | kib <kib@FreeBSD.org> | 2012-03-11 20:03:09 +0000 |
commit | 95d1e3d11bebe5f0d75da30af98fbc94ee0e5233 (patch) | |
tree | e4eae50ab265adfbfc5e1f5293bdb637284ed4f5 /libexec/rtld-elf/map_object.c | |
parent | dc94d00160d8b61f7484f9b71f42ea04a241739e (diff) | |
download | FreeBSD-src-95d1e3d11bebe5f0d75da30af98fbc94ee0e5233.zip FreeBSD-src-95d1e3d11bebe5f0d75da30af98fbc94ee0e5233.tar.gz |
Add support for preinit, init and fini arrays. Some ABIs, in
particular on ARM, do require working init arrays.
Traditional FreeBSD crt1 calls _init and _fini of the binary, instead
of allowing runtime linker to arrange the calls. This was probably
done to have the same crt code serve both statically and dynamically
linked binaries. Since ABI mandates that first is called preinit
array functions, then init, and then init array functions, the init
have to be called from rtld now.
To provide binary compatibility to old FreeBSD crt1, which calls _init
itself, rtld only calls intializers and finalizers for main binary if
binary has a note indicating that new crt was used for linking. Add
parsing of ELF notes to rtld, and cache p_osrel value since we parsed
it anyway.
The patch is inspired by init_array support for DragonflyBSD, written
by John Marino.
Reviewed by: kan
Tested by: andrew (arm, previous version), flo (sparc64, previous version)
MFC after: 3 weeks
Diffstat (limited to 'libexec/rtld-elf/map_object.c')
-rw-r--r-- | libexec/rtld-elf/map_object.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/libexec/rtld-elf/map_object.c b/libexec/rtld-elf/map_object.c index 6a13692..d240575 100644 --- a/libexec/rtld-elf/map_object.c +++ b/libexec/rtld-elf/map_object.c @@ -86,6 +86,8 @@ map_object(int fd, const char *path, const struct stat *sb) Elf_Word stack_flags; Elf_Addr relro_page; size_t relro_size; + Elf_Addr note_start; + Elf_Addr note_end; hdr = get_elf_header(fd, path); if (hdr == NULL) @@ -104,6 +106,8 @@ map_object(int fd, const char *path, const struct stat *sb) phdr_vaddr = 0; relro_page = 0; relro_size = 0; + note_start = 0; + note_end = 0; segs = alloca(sizeof(segs[0]) * hdr->e_phnum); stack_flags = RTLD_DEFAULT_STACK_PF_EXEC | PF_R | PF_W; while (phdr < phlimit) { @@ -143,6 +147,12 @@ map_object(int fd, const char *path, const struct stat *sb) relro_page = phdr->p_vaddr; relro_size = phdr->p_memsz; break; + + case PT_NOTE: + note_start = (Elf_Addr)obj->relocbase + phdr->p_offset; + note_end = note_start + phdr->p_filesz; + digest_notes(obj, note_start, note_end); + break; } ++phdr; |