diff options
Diffstat (limited to 'libc')
-rw-r--r-- | libc/misc/elf/Makefile | 12 | ||||
-rw-r--r-- | libc/misc/elf/Makefile.in | 19 | ||||
-rw-r--r-- | libc/misc/elf/dl-core.c | 20 | ||||
-rw-r--r-- | libc/misc/elf/dl-iterate-phdr.c | 84 | ||||
-rw-r--r-- | libc/misc/elf/dl-support.c | 68 | ||||
-rw-r--r-- | libc/sysdeps/linux/common/__syscall_ipc.c | 17 |
6 files changed, 203 insertions, 17 deletions
diff --git a/libc/misc/elf/Makefile b/libc/misc/elf/Makefile new file mode 100644 index 000000000..4bb6872a1 --- /dev/null +++ b/libc/misc/elf/Makefile @@ -0,0 +1,12 @@ +# Copyright (C) 2008 STMicroelectronics Ltd. +# Author: Carmelo Amoroso <carmelo.amoroso@st.com> + +# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. +# + +top_srcdir=../../../ +top_builddir=../../../ +all: objs +include $(top_builddir)Rules.mak +include Makefile.in +include $(top_srcdir)Makerules diff --git a/libc/misc/elf/Makefile.in b/libc/misc/elf/Makefile.in new file mode 100644 index 000000000..b9cab8eb3 --- /dev/null +++ b/libc/misc/elf/Makefile.in @@ -0,0 +1,19 @@ +# Copyright (C) 2008 STMicroelectronics Ltd. +# Author: Carmelo Amoroso <carmelo.amoroso@st.com> + +# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. +# + +libc_a_CSRC = dl-support.c dl-core.c dl-iterate-phdr.c +CFLAGS-dl-iterate-phdr.c=-D_GNU_SOURCE + +MISC_ELF_OUT:=$(top_builddir)libc/misc/elf +MISC_ELF_OBJ:=$(patsubst %.c,$(MISC_ELF_OUT)/%.o,$(libc_a_CSRC)) + +libc-static-y += $(MISC_ELF_OBJ) +libc-shared-y += $(MISC_ELF_OUT)/dl-iterate-phdr.oS + +objclean-y+= misc_elf_objclean + +misc_elf_objclean: + $(RM) $(MISC_ELF_OUT)/*.{o,os,oS} diff --git a/libc/misc/elf/dl-core.c b/libc/misc/elf/dl-core.c new file mode 100644 index 000000000..b32dcf828 --- /dev/null +++ b/libc/misc/elf/dl-core.c @@ -0,0 +1,20 @@ +/* + * This contains all symbols and functions to support + * dynamic linking into static libc. + + * Copyright (c) 2008 STMicroelectronics Ltd + * Author: Carmelo Amoroso <carmelo.amoroso@st.com> + * + * Based on draft work by Peter S. Mazinger <ps.m@gmx.net> + * + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + * + */ + +#ifdef SHARED +#error "This file is not suitable for linking into dynamic libc" +#else +/* Include ldso symbols and functions used into static libc */ +#include "../../../ldso/ldso/dl-symbols.c" +#endif + diff --git a/libc/misc/elf/dl-iterate-phdr.c b/libc/misc/elf/dl-iterate-phdr.c new file mode 100644 index 000000000..a23ca700d --- /dev/null +++ b/libc/misc/elf/dl-iterate-phdr.c @@ -0,0 +1,84 @@ +/* Get loaded objects program headers. + Copyright (C) 2001,2002,2003,2004,2006,2007 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Jakub Jelinek <jakub@redhat.com>, 2001. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + */ + + +#include <link.h> +#include <ldso.h> + +/* we want this in libc but nowhere else */ +#ifdef __USE_GNU + +extern __typeof(dl_iterate_phdr) __dl_iterate_phdr; + +hidden_proto(__dl_iterate_phdr) +int +__dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info, size_t size, void *data), void *data) +{ + struct elf_resolve *l; + struct dl_phdr_info info; + int ret = 0; + + for (l = _dl_loaded_modules; l != NULL; l = l->next) { + info.dlpi_addr = l->loadaddr; + info.dlpi_name = l->libname; + info.dlpi_phdr = l->ppnt; + info.dlpi_phnum = l->n_phent; + ret = callback (&info, sizeof (struct dl_phdr_info), data); + if (ret) + break; + } + return ret; +} +hidden_def (__dl_iterate_phdr) + +# ifdef SHARED + +weak_alias(__dl_iterate_phdr, dl_iterate_phdr) + +# else + +/* dl-support.c defines these and initializes them early on. */ +extern ElfW(Phdr) *_dl_phdr; +extern size_t _dl_phnum; + +int +dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info, + size_t size, void *data), void *data) +{ + if (_dl_phnum != 0) + { + /* This entry describes this statically-linked program itself. */ + struct dl_phdr_info info; + int ret; + info.dlpi_addr = 0; + info.dlpi_name = ""; + info.dlpi_phdr = _dl_phdr; + info.dlpi_phnum = _dl_phnum; + ret = (*callback) (&info, sizeof (struct dl_phdr_info), data); + if (ret) + return ret; + } + /* Then invoke callback on loaded modules, if any */ + return __dl_iterate_phdr (callback, data); +} + +# endif +#endif diff --git a/libc/misc/elf/dl-support.c b/libc/misc/elf/dl-support.c new file mode 100644 index 000000000..b8f0c07a6 --- /dev/null +++ b/libc/misc/elf/dl-support.c @@ -0,0 +1,68 @@ +/* Support for dynamic linking code in static libc. + Copyright (C) 1996-2002, 2003, 2004, 2005 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* This file defines some things that for the dynamic linker are defined in + rtld.c and dl-sysdep.c in ways appropriate to bootstrap dynamic linking. */ + +#include <assert.h> +#include <tls.h> +#include <link.h> +#include <ldsodefs.h> +#include <string.h> + +void (*_dl_init_static_tls) (struct link_map *) = &_dl_nothread_init_static_tls; + +ElfW(Phdr) *_dl_phdr; +size_t _dl_phnum; + +void +internal_function +_dl_aux_init (ElfW(auxv_t) *av) +{ + /* Get the program headers base address from the aux vect */ + GL(dl_phdr) = (ElfW(Phdr) *) av[AT_PHDR].a_un.a_val; + + /* Get the number of program headers from the aux vect */ + GL(dl_phnum) = (size_t) av[AT_PHNUM].a_un.a_val; +} + +/* Initialize static TLS area and DTV for current (only) thread. + libpthread implementations should provide their own hook + to handle all threads. */ +void +_dl_nothread_init_static_tls (struct link_map *map) +{ +# if TLS_TCB_AT_TP + void *dest = (char *) THREAD_SELF - map->l_tls_offset; +# elif TLS_DTV_AT_TP + void *dest = (char *) THREAD_SELF + map->l_tls_offset + TLS_PRE_TCB_SIZE; +# else +# error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined" +# endif + + /* Fill in the DTV slot so that a later LD/GD access will find it. */ + dtv_t *dtv = THREAD_DTV (); + assert (map->l_tls_modid <= dtv[-1].counter); + dtv[map->l_tls_modid].pointer.val = dest; + dtv[map->l_tls_modid].pointer.is_static = true; + + /* Initialize the memory. */ + memset (mempcpy (dest, map->l_tls_initimage, map->l_tls_initimage_size), + '\0', map->l_tls_blocksize - map->l_tls_initimage_size); +} diff --git a/libc/sysdeps/linux/common/__syscall_ipc.c b/libc/sysdeps/linux/common/__syscall_ipc.c deleted file mode 100644 index decc65ae5..000000000 --- a/libc/sysdeps/linux/common/__syscall_ipc.c +++ /dev/null @@ -1,17 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * __syscall_ipc() for uClibc - * - * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org> - * - * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. - */ - -#include "syscalls.h" - -#ifdef __NR_ipc -#define __NR___syscall_ipc __NR_ipc -#include "../../../misc/sysvipc/ipc.h" -_syscall5(int, __syscall_ipc, unsigned int, call, int, first, int, second, int, - third, void *, ptr); -#endif |