diff options
author | Carmelo Amoroso <carmelo.amoroso@st.com> | 2008-11-18 12:48:13 +0000 |
---|---|---|
committer | Carmelo Amoroso <carmelo.amoroso@st.com> | 2008-11-18 12:48:13 +0000 |
commit | 827c5f1b826b916a533c082e558fc7c6fc38de6d (patch) | |
tree | 8f4c4e4626d41801ececf13b9f06488e6ae98cb9 /libc/misc/elf | |
parent | 933df87e4e9a8d7f6901dd0417b0006c5b132439 (diff) |
Move _dl_iterate_phdr into libc.so.0 and libc.a (as glibc does).
Currently we have an implementation in ld.so and libdl.a.
Signed-off-by: Carmelo Amoroso <carmelo.amoroso@st.com>
Diffstat (limited to 'libc/misc/elf')
-rw-r--r-- | libc/misc/elf/Makefile | 12 | ||||
-rw-r--r-- | libc/misc/elf/Makefile.in | 20 | ||||
-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 | 38 |
5 files changed, 174 insertions, 0 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..603810d68 --- /dev/null +++ b/libc/misc/elf/Makefile.in @@ -0,0 +1,20 @@ +# 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 -I$(top_srcdir)ldso/ldso/$(TARGET_ARCH) -I$(top_srcdir)ldso/include +CFLAGS-dl-core.c=-I$(top_srcdir)ldso/ldso/$(TARGET_ARCH) -I$(top_srcdir)ldso/include + +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..16de2ecb7 --- /dev/null +++ b/libc/misc/elf/dl-support.c @@ -0,0 +1,38 @@ +/* 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 <link.h> +#include <elf.h> + +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 */ + _dl_phdr = (ElfW(Phdr) *) av[AT_PHDR].a_un.a_val; + + /* Get the number of program headers from the aux vect */ + _dl_phnum = (size_t) av[AT_PHNUM].a_un.a_val; +} |