zte's code,first commit

Change-Id: I9a04da59e459a9bc0d67f101f700d9d7dc8d681b
diff --git a/ap/build/uClibc/libc/misc/elf/Makefile b/ap/build/uClibc/libc/misc/elf/Makefile
new file mode 100644
index 0000000..4bb6872
--- /dev/null
+++ b/ap/build/uClibc/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/ap/build/uClibc/libc/misc/elf/Makefile.in b/ap/build/uClibc/libc/misc/elf/Makefile.in
new file mode 100644
index 0000000..1b4bd8b
--- /dev/null
+++ b/ap/build/uClibc/libc/misc/elf/Makefile.in
@@ -0,0 +1,22 @@
+# 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.
+#
+
+subdirs += libc/misc/elf
+
+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+= CLEAN_libc/misc/elf
+
+CLEAN_libc/misc/elf:
+	$(do_rm) $(addprefix $(MISC_ELF_OUT)/*., o os oS)
diff --git a/ap/build/uClibc/libc/misc/elf/dl-core.c b/ap/build/uClibc/libc/misc/elf/dl-core.c
new file mode 100644
index 0000000..b32dcf8
--- /dev/null
+++ b/ap/build/uClibc/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/ap/build/uClibc/libc/misc/elf/dl-iterate-phdr.c b/ap/build/uClibc/libc/misc/elf/dl-iterate-phdr.c
new file mode 100644
index 0000000..f0233ca
--- /dev/null
+++ b/ap/build/uClibc/libc/misc/elf/dl-iterate-phdr.c
@@ -0,0 +1,85 @@
+/* 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)
+{
+	int ret = 0;
+#ifndef __ARCH_HAS_NO_SHARED__
+	struct elf_resolve *l;
+	struct dl_phdr_info info;
+
+	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;
+	}
+#endif
+	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;
+#if defined(__FDPIC__)
+      info.dlpi_addr.map = NULL;
+      info.dlpi_addr.got_value = NULL;
+#elif defined(__DSBT__)
+      info.dlpi_addr.map = NULL;
+#else
+      info.dlpi_addr = 0;
+#endif
+      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/ap/build/uClibc/libc/misc/elf/dl-support.c b/ap/build/uClibc/libc/misc/elf/dl-support.c
new file mode 100644
index 0000000..f194692
--- /dev/null
+++ b/ap/build/uClibc/libc/misc/elf/dl-support.c
@@ -0,0 +1,70 @@
+/*
+ * 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>
+#if defined(USE_TLS) && USE_TLS
+#include <assert.h>
+#include <tls.h>
+#include <ldsodefs.h>
+#include <string.h>
+#endif
+
+#if defined(USE_TLS) && USE_TLS
+
+void (*_dl_init_static_tls) (struct link_map *) = &_dl_nothread_init_static_tls;
+
+#endif
+
+ElfW(Phdr) *_dl_phdr;
+size_t _dl_phnum;
+
+void internal_function _dl_aux_init (ElfW(auxv_t) *av);
+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;
+}
+
+#if defined(USE_TLS) && USE_TLS
+/* Initialize static TLS area and DTV for current (only) thread.
+   libpthread implementations should provide their own hook
+   to handle all threads.  */
+void
+attribute_hidden
+_dl_nothread_init_static_tls (struct link_map *map)
+{
+# if defined(TLS_TCB_AT_TP)
+  void *dest = (char *) THREAD_SELF - map->l_tls_offset;
+# elif defined(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);
+}
+
+#endif
+