Libraries updates and cleanup

* Updating common/lib
 * Updating lib/csu
 * Updating lib/libc
 * Updating libexec/ld.elf_so
 * Corrected test on __minix in featuretest to actually follow the
   meaning of the comment.
 * Cleaned up _REENTRANT-related defintions.
 * Disabled -D_REENTRANT for libfetch
 * Removing some unneeded __NBSD_LIBC defines and tests

Change-Id: Ic1394baef74d11b9f86b312f5ff4bbc3cbf72ce2
This commit is contained in:
2012-11-15 12:06:41 +01:00
parent f6aac1c3b5
commit f14fb60209
1285 changed files with 44244 additions and 14308 deletions

View File

@@ -1,4 +1,4 @@
/* $NetBSD: map_object.c,v 1.41 2010/10/16 10:27:07 skrll Exp $ */
/* $NetBSD: map_object.c,v 1.45 2012/10/13 21:13:07 dholland Exp $ */
/*
* Copyright 1996 John D. Polstra.
@@ -34,11 +34,10 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: map_object.c,v 1.41 2010/10/16 10:27:07 skrll Exp $");
__RCSID("$NetBSD: map_object.c,v 1.45 2012/10/13 21:13:07 dholland Exp $");
#endif /* not lint */
#include <errno.h>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
@@ -56,6 +55,10 @@ __RCSID("$NetBSD: map_object.c,v 1.41 2010/10/16 10:27:07 skrll Exp $");
#define MINIXVERBOSE 0
#if MINIXVERBOSE
#include <stdio.h>
#endif
static int protflags(int); /* Elf flags -> mmap protection */
#define EA_UNDEF (~(Elf_Addr)0)
@@ -86,13 +89,15 @@ _rtld_map_object(const char *path, int fd, const struct stat *sb)
Obj_Entry *obj;
Elf_Ehdr *ehdr;
Elf_Phdr *phdr;
#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)
Elf_Phdr *phtls;
#endif
size_t phsize;
Elf_Phdr *phlimit;
Elf_Phdr *segs[2];
int nsegs;
caddr_t mapbase = MAP_FAILED;
size_t mapsize = 0;
size_t bsssize = 0;
int mapflags;
Elf_Off base_offset;
#ifdef MAP_ALIGNED
@@ -108,10 +113,15 @@ _rtld_map_object(const char *path, int fd, const struct stat *sb)
Elf_Addr data_vlimit;
int data_flags;
caddr_t data_addr;
#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)
Elf_Addr tls_vaddr = 0; /* Noise GCC */
#endif
Elf_Addr phdr_vaddr;
size_t phdr_memsz;
#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)
caddr_t gap_addr;
size_t gap_size;
#endif
int i;
#ifdef RTLD_LOADER
Elf_Addr clear_vaddr;
@@ -120,7 +130,7 @@ _rtld_map_object(const char *path, int fd, const struct stat *sb)
#endif
if (sb != NULL && sb->st_size < (off_t)sizeof (Elf_Ehdr)) {
_rtld_error("%s: unrecognized file format1", path);
_rtld_error("%s: not ELF file (too short)", path);
return NULL;
}
@@ -149,9 +159,12 @@ _rtld_map_object(const char *path, int fd, const struct stat *sb)
goto bad;
}
/* Make sure the file is valid */
if (memcmp(ELFMAG, ehdr->e_ident, SELFMAG) != 0 ||
ehdr->e_ident[EI_CLASS] != ELFCLASS) {
_rtld_error("%s: unrecognized file format2 [%x != %x]", path,
if (memcmp(ELFMAG, ehdr->e_ident, SELFMAG) != 0) {
_rtld_error("%s: not ELF file (magic number bad)", path);
goto bad;
}
if (ehdr->e_ident[EI_CLASS] != ELFCLASS) {
_rtld_error("%s: invalid ELF class %x; expected %x", path,
ehdr->e_ident[EI_CLASS], ELFCLASS);
goto bad;
}
@@ -189,6 +202,9 @@ _rtld_map_object(const char *path, int fd, const struct stat *sb)
* in that order.
*/
phdr = (Elf_Phdr *) ((caddr_t)ehdr + ehdr->e_phoff);
#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)
phtls = NULL;
#endif
phsize = ehdr->e_phnum * sizeof(phdr[0]);
obj->phdr = NULL;
phdr_vaddr = EA_UNDEF;
@@ -206,20 +222,36 @@ _rtld_map_object(const char *path, int fd, const struct stat *sb)
if (nsegs < 2)
segs[nsegs] = phdr;
++nsegs;
dbg(("%s: PT_LOAD %p", obj->path, phdr));
#if ELFSIZE == 64
#define PRImemsz PRIu64
#else
#define PRImemsz PRIu32
#endif
dbg(("%s: %s %p phsize %" PRImemsz, obj->path, "PT_LOAD",
(void *)(uintptr_t)phdr->p_vaddr, phdr->p_memsz));
break;
case PT_PHDR:
phdr_vaddr = phdr->p_vaddr;
phdr_memsz = phdr->p_memsz;
dbg(("%s: PT_PHDR %p phsize %zu", obj->path,
(void *)(uintptr_t)phdr_vaddr, phdr_memsz));
dbg(("%s: %s %p phsize %" PRImemsz, obj->path, "PT_PHDR",
(void *)(uintptr_t)phdr->p_vaddr, phdr->p_memsz));
break;
case PT_DYNAMIC:
obj->dynamic = (void *)(uintptr_t)phdr->p_vaddr;
dbg(("%s: PT_DYNAMIC %p", obj->path, obj->dynamic));
dbg(("%s: %s %p phsize %" PRImemsz, obj->path, "PT_DYNAMIC",
(void *)(uintptr_t)phdr->p_vaddr, phdr->p_memsz));
break;
#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)
case PT_TLS:
phtls = phdr;
dbg(("%s: %s %p phsize %" PRImemsz, obj->path, "PT_TLS",
(void *)(uintptr_t)phdr->p_vaddr, phdr->p_memsz));
break;
#endif
}
++phdr;
@@ -268,6 +300,17 @@ _rtld_map_object(const char *path, int fd, const struct stat *sb)
obj->vaddrbase = base_vaddr;
obj->isdynamic = ehdr->e_type == ET_DYN;
#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)
if (phtls != NULL) {
++_rtld_tls_dtv_generation;
obj->tlsindex = ++_rtld_tls_max_index;
obj->tlssize = phtls->p_memsz;
obj->tlsalign = phtls->p_align;
obj->tlsinitsize = phtls->p_filesz;
tls_vaddr = phtls->p_vaddr;
}
#endif
obj->phdr_loaded = false;
for (i = 0; i < nsegs; i++) {
if (phdr_vaddr != EA_UNDEF &&
@@ -355,25 +398,18 @@ _rtld_map_object(const char *path, int fd, const struct stat *sb)
_rtld_error("mmap of data failed: %s", xstrerror(errno));
goto bad;
}
#endif
#ifndef __minix
bsssize= base_vlimit - data_vlimit;
if(bsssize > 0) {
/* Overlay the bss segment onto the proper region. */
if (mmap(mapbase + data_vlimit - base_vaddr, bsssize,
if (mmap(mapbase + data_vlimit - base_vaddr, base_vlimit - data_vlimit,
data_flags, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0) ==
MAP_FAILED) {
_rtld_error("mmap of bss (at 0x%lx, 0x%lx bytes) failed: %s",
mapbase + data_vlimit - base_vaddr, bsssize, xstrerror(errno));
_rtld_error("mmap of bss failed: %s", xstrerror(errno));
goto bad;
}
}
/* Unmap the gap between the text and data. */
gap_addr = mapbase + round_up(text_vlimit - base_vaddr);
gap_size = data_addr - gap_addr;
if (gap_size != 0 && mprotect(gap_addr, gap_size, PROT_NONE) == -1) {
_rtld_error("mprotect of text -> data gap failed: %s",
xstrerror(errno));
@@ -390,6 +426,11 @@ _rtld_map_object(const char *path, int fd, const struct stat *sb)
/* Non-file portion of BSS mapped above. */
#endif
#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)
if (phtls != NULL)
obj->tlsinit = mapbase + tls_vaddr;
#endif
obj->mapbase = mapbase;
obj->mapsize = mapsize;
obj->relocbase = mapbase - base_vaddr;
@@ -419,6 +460,10 @@ _rtld_obj_free(Obj_Entry *obj)
{
Objlist_Entry *elm;
#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)
if (obj->tls_done)
_rtld_tls_offset_free(obj);
#endif
xfree(obj->path);
while (obj->needed != NULL) {
Needed_Entry *needed = obj->needed;