[Openmcl-cvs-notifications] r14572 - /trunk/source/lisp-kernel/pmcl-kernel.c

gb at clozure.com gb at clozure.com
Mon Jan 10 02:12:15 CST 2011


Author: gb
Date: Mon Jan 10 02:12:15 2011
New Revision: 14572

Log:
main->cclmain if CCLSHARED is defined.

Hair up get_r_debug() a lot; most of the code has to do with the
difficulty in finding the executable's dynamic section from a
shared lib.

Modified:
    trunk/source/lisp-kernel/pmcl-kernel.c

Modified: trunk/source/lisp-kernel/pmcl-kernel.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/source/lisp-kernel/pmcl-kernel.c (original)
+++ trunk/source/lisp-kernel/pmcl-kernel.c Mon Jan 10 02:12:15 2011
@@ -43,8 +43,17 @@
 #include <dlfcn.h>
 #include <sys/time.h>
 #include <sys/resource.h>
+#ifdef ANDROID
+#ifdef ARM
+#define ANDROID_ARM_LINKER 1
+#endif
+#include <linker.h>
+#else
 #include <link.h>
+#endif
+#ifndef ANDROID
 #include <elf.h>
+#endif
 =

 /* =

    The version of <asm/cputable.h> provided by some distributions will
@@ -1653,7 +1662,12 @@
 =

 =

 int
-main(int argc, char *argv[]
+#ifdef CCLSHARED
+cclmain
+#else
+main
+#endif
+(int argc, char *argv[]
 #if defined(PPC) && defined(LINUX)
 , char *envp[], void *aux
 #endif
@@ -2198,29 +2212,95 @@
   return windows_find_symbol(handle, name);
 #endif
 }
+#if defined(LINUX) || defined(FREEBSD) || defined(SOLARIS)
+#if WORD_SIZE =3D=3D 64
+typedef Elf64_Dyn Elf_Dyn;
+typedef Elf64_Ehdr Elf_Ehdr;
+typedef Elf64_Shdr Elf_Shdr;
+#else
+typedef Elf32_Dyn Elf_Dyn;
+typedef Elf32_Ehdr Elf_Ehdr;
+typedef Elf32_Shdr Elf_Shdr;
+#endif
+
+Elf32_Dyn *
+get_executable_dynamic_entries()
+{
+#ifndef CCLSHARED
+  extern Elf_Dyn _DYNAMIC[];
+  return _DYNAMIC;
+#else
+#ifdef ANDROID
+  /* Deep, dark secret: the "handle" returned by dlopen() is
+     a pointer to an soinfo structure, as defined in linker.h.
+     We can get the link map from there ...
+  */
+  =

+
+ =

+  /* Woe unto us - and lots of it - if the executable is mapped
+     at an address other than 0x8000.  Todo: parse /proc/self/maps. */
+  char *p;
+  Elf_Ehdr *elf_header;
+  Elf_Shdr *section_header;
+  int i,fd;
+  struct stat _stat;
+  Elf_Dyn *result =3D NULL;
+  =

+  fd =3D open("/proc/self/exe",O_RDONLY);
+  if (fd >=3D 0) {
+    if (fstat(fd,&_stat) =3D=3D 0) {
+      p =3D (char *)mmap(NULL,_stat.st_size,PROT_READ,MAP_PRIVATE,fd,0);
+      if (p !=3D MAP_FAILED) {
+        elf_header =3D (Elf_Ehdr *)p;
+        for (section_header =3D (Elf_Shdr *)(p+elf_header->e_shoff),
+               i =3D 0;
+             i < elf_header->e_shnum;
+             i++,section_header++) {
+          if (section_header->sh_type =3D=3D SHT_DYNAMIC) {
+            result =3D (Elf_Dyn *)section_header->sh_addr;
+            break;
+          }
+        }
+        munmap(p,_stat.st_size);
+      }
+    }
+    close(fd);
+  }
+  return result;
+#else
+#error need implementation for get_executable_dynamic_entries from dso
+#endif
+#endif
+}
+
+
+void *cached_r_debug =3D NULL;
 =

 void *
 get_r_debug()
 {
-#if defined(LINUX) || defined(FREEBSD) || defined(SOLARIS)
-#if WORD_SIZE =3D=3D 64
-  extern Elf64_Dyn _DYNAMIC[];
-  Elf64_Dyn *dp;
-#else
-  extern Elf32_Dyn _DYNAMIC[];
-  Elf32_Dyn *dp;
-#endif
   int tag;
-
-  for (dp =3D _DYNAMIC; (tag =3D dp->d_tag) !=3D 0; dp++) {
-    if (tag =3D=3D DT_DEBUG) {
-      return (void *)(dp->d_un.d_ptr);
-    }
-  }
-#endif
+  Elf_Dyn *dp;
+
+  if (cached_r_debug =3D=3D NULL) {
+    for (dp =3D get_executable_dynamic_entries(); (tag =3D dp->d_tag) !=3D=
 0; dp++) {
+      if (tag =3D=3D DT_DEBUG) {
+        cached_r_debug =3D (void *)(dp->d_un.d_ptr);
+        break;
+      }
+    }
+  }
+  return cached_r_debug;
+}
+
+#else
+void *
+get_r_debug()
+{
   return NULL;
 }
-
+#endif
 =

 #ifdef DARWIN
 void



More information about the Openmcl-cvs-notifications mailing list