summaryrefslogtreecommitdiffstats
path: root/libc
diff options
context:
space:
mode:
authorCarmelo Amoroso <carmelo.amoroso@st.com>2008-11-18 14:01:35 +0000
committerCarmelo Amoroso <carmelo.amoroso@st.com>2008-11-18 14:01:35 +0000
commit4c3fb592c07248c452a84883017ea06557dce6c2 (patch)
treea4a252cfbb9cc9402515e8eff93a66edc929b874 /libc
parent9f6bbb4ce053041cd5a08a6b50a15653416765e0 (diff)
downloaduClibc-alpine-4c3fb592c07248c452a84883017ea06557dce6c2.tar.bz2
uClibc-alpine-4c3fb592c07248c452a84883017ea06557dce6c2.tar.xz
Mode dl_iterate_phdr from ld.so/libdl.a to libc.so/libc.a
just like glibc does.
Diffstat (limited to 'libc')
-rw-r--r--libc/misc/Makefile.in1
-rw-r--r--libc/misc/elf/Makefile12
-rw-r--r--libc/misc/elf/Makefile.in20
-rw-r--r--libc/misc/elf/dl-core.c20
-rw-r--r--libc/misc/elf/dl-iterate-phdr.c76
-rw-r--r--libc/misc/elf/dl-support.c29
-rw-r--r--libc/misc/internals/__uClibc_main.c16
7 files changed, 171 insertions, 3 deletions
diff --git a/libc/misc/Makefile.in b/libc/misc/Makefile.in
index 104db366e..838081d66 100644
--- a/libc/misc/Makefile.in
+++ b/libc/misc/Makefile.in
@@ -12,6 +12,7 @@ include $(top_srcdir)libc/misc/assert/Makefile.in
include $(top_srcdir)libc/misc/ctype/Makefile.in
include $(top_srcdir)libc/misc/dirent/Makefile.in
include $(top_srcdir)libc/misc/error/Makefile.in
+include $(top_srcdir)libc/misc/elf/Makefile.in
include $(top_srcdir)libc/misc/file/Makefile.in
include $(top_srcdir)libc/misc/fnmatch/Makefile.in
include $(top_srcdir)libc/misc/ftw/Makefile.in
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..f92edb1e6
--- /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..a2bb9e000
--- /dev/null
+++ b/libc/misc/elf/dl-iterate-phdr.c
@@ -0,0 +1,76 @@
+/* Get loaded objects program headers.
+
+ Based on GNU C library (file: libc/elf/dl-iteratephdr.c)
+
+ Copyright (C) 2001,2002,2003,2004,2006,2007 Free Software Foundation, Inc.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2001.
+
+ 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.
+*/
+
+
+#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..3c1d8537d
--- /dev/null
+++ b/libc/misc/elf/dl-support.c
@@ -0,0 +1,29 @@
+/*
+ * Support for dynamic linking code in static libc.
+ * Copyright (C) 1996-2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ *
+ * Partially based on GNU C Library (file: libc/elf/dl-support.c)
+ *
+ * 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.
+ *
+ */
+
+#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;
+}
diff --git a/libc/misc/internals/__uClibc_main.c b/libc/misc/internals/__uClibc_main.c
index 6c0dab7fe..450f56105 100644
--- a/libc/misc/internals/__uClibc_main.c
+++ b/libc/misc/internals/__uClibc_main.c
@@ -72,6 +72,11 @@ uintptr_t __guard attribute_relro;
# endif
# endif
+/*
+ * Needed to initialize _dl_phdr when statically linked
+ */
+
+void internal_function _dl_aux_init (ElfW(auxv_t) *av);
#endif /* !SHARED */
/*
@@ -114,9 +119,8 @@ weak_alias (program_invocation_name, __progname_full)
#endif
/*
- * Declare the __environ global variable and create a strong alias environ.
- * Note: Apparently we must initialize __environ to ensure that the strong
- * environ symbol is also included.
+ * Declare the __environ global variable and create a weak alias environ.
+ * This must be initialized; we cannot have a weak alias into bss.
*/
char **__environ = 0;
weak_alias(__environ, environ)
@@ -310,6 +314,12 @@ void __uClibc_main(int (*main)(int, char **, char **), int argc,
}
aux_dat += 2;
}
+#ifndef SHARED
+ /* Get the program headers (_dl_phdr) from the aux vector
+ It will be used into __libc_setup_tls. */
+
+ _dl_aux_init (auxvt);
+#endif
#endif
/* We need to initialize uClibc. If we are dynamically linked this