[Glibc-bsd-commits] r3035 - in trunk/glibc-ports/kfreebsd: . i386 x86_64

Petr Salinger ps-guest at alioth.debian.org
Mon Apr 26 14:12:34 UTC 2010


Author: ps-guest
Date: 2010-04-26 14:12:31 +0000 (Mon, 26 Apr 2010)
New Revision: 3035

Modified:
   trunk/glibc-ports/kfreebsd/dl-origin.c
   trunk/glibc-ports/kfreebsd/i386/dl-machine.h
   trunk/glibc-ports/kfreebsd/x86_64/dl-machine.h
Log:
$ORIGIN handling is much more complicated ...



Modified: trunk/glibc-ports/kfreebsd/dl-origin.c
===================================================================
--- trunk/glibc-ports/kfreebsd/dl-origin.c	2010-04-22 09:36:30 UTC (rev 3034)
+++ trunk/glibc-ports/kfreebsd/dl-origin.c	2010-04-26 14:12:31 UTC (rev 3035)
@@ -32,6 +32,31 @@
    the path of the application from the /proc/self/exe symlink.  Try this
    first and fall back on the generic method if necessary.  */
 
+
+const char *_self_program_name_from_auxv attribute_hidden;
+
+static int
+_dl_self_name(char *buf, int buflen)
+{
+  int len;
+  
+  len = __readlink("/proc/self/exe", buf, buflen);
+
+  if (len > 0 && buf[0] == '/')
+    return len;
+
+  if (_self_program_name_from_auxv)
+  {
+    strncpy(buf, _self_program_name_from_auxv, buflen);
+    buf[buflen - 1] = 0;
+    return strlen(buf);
+  };
+  
+  return -1;
+}
+
+
+
 const char *
 _dl_get_origin (void)
 {
@@ -39,9 +64,9 @@
   char *result;
   int len;
 
-  len = readlink("/proc/self/exe", linkval, sizeof (linkval));
+  len = _dl_self_name(linkval, sizeof(linkval));
 
-  if (len > 0 && linkval[0] == '/')
+  if (len > 0)
     {
       /* We can use this value.  */
       while (len > 1 && linkval[len - 1] != '/')

Modified: trunk/glibc-ports/kfreebsd/i386/dl-machine.h
===================================================================
--- trunk/glibc-ports/kfreebsd/i386/dl-machine.h	2010-04-22 09:36:30 UTC (rev 3034)
+++ trunk/glibc-ports/kfreebsd/i386/dl-machine.h	2010-04-26 14:12:31 UTC (rev 3035)
@@ -23,6 +23,30 @@
 /* For FreeBSD we redefine an initialization function.
    This is called very early in dl_sysdep_start.  */
 
+#if 0
+Under FreeBSD:
+#define AT_EXECPATH     15      /* Path to the executable. */
+
+Under Linux:
+#define AT_PLATFORM     15      /* String identifying platform.  */
+
+Filled entries from kernel:
+
+        if (args->execfd != -1)
+                AUXARGS_ENTRY(pos, AT_EXECFD, args->execfd);
+        AUXARGS_ENTRY(pos, AT_PHDR, args->phdr);    
+        AUXARGS_ENTRY(pos, AT_PHENT, args->phent);  
+        AUXARGS_ENTRY(pos, AT_PHNUM, args->phnum);  
+        AUXARGS_ENTRY(pos, AT_PAGESZ, args->pagesz);
+        AUXARGS_ENTRY(pos, AT_FLAGS, args->flags);
+        AUXARGS_ENTRY(pos, AT_ENTRY, args->entry);
+        AUXARGS_ENTRY(pos, AT_BASE, args->base);
+        if (imgp->execpathp != 0)
+                AUXARGS_ENTRY(pos, AT_EXECPATH, imgp->execpathp);
+        AUXARGS_ENTRY(pos, AT_NULL, 0);
+                                                                                                                
+#endif
+
 #include_next <dl-machine.h>
 
 #undef  DL_PLATFORM_INIT
@@ -68,14 +92,16 @@
     );
 }
 
+extern const char *_self_program_name_from_auxv attribute_hidden;
+
 static inline void __attribute__ ((unused))
 dl_platform_kfreebsd_i386_init (void)
 {
-    if ((GLRO(dl_platform) == NULL) || (*GLRO(dl_platform) == '\0'))
-    {
 	/* we don't have reasonable AT_PLATFORM from kernel
 	   try to use cpuid to get one, also guess AT_HWCAP */
 
+        _self_program_name_from_auxv = GLRO(dl_platform);
+        
 	int val, hwcap;
 
 	val = try_flip_flags(X86_EFLAGS_AC | X86_EFLAGS_ID);
@@ -118,7 +144,6 @@
 		}
             }
 	}
-    }
 }
 
 #endif

Modified: trunk/glibc-ports/kfreebsd/x86_64/dl-machine.h
===================================================================
--- trunk/glibc-ports/kfreebsd/x86_64/dl-machine.h	2010-04-22 09:36:30 UTC (rev 3034)
+++ trunk/glibc-ports/kfreebsd/x86_64/dl-machine.h	2010-04-26 14:12:31 UTC (rev 3035)
@@ -18,10 +18,7 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */
 
-#ifdef dl_machine_h
 #include_next <dl-machine.h>
-#else
-#include_next <dl-machine.h>
 
 #undef RTLD_START
 
@@ -77,4 +74,64 @@
 .previous\n\
 ");
 
+#if 0
+Under FreeBSD:
+#define AT_EXECPATH     15      /* Path to the executable. */
+
+Under Linux:
+#define AT_PLATFORM     15      /* String identifying platform.  */
+
+Filled entries from kernel:
+
+        if (args->execfd != -1)
+                AUXARGS_ENTRY(pos, AT_EXECFD, args->execfd);
+        AUXARGS_ENTRY(pos, AT_PHDR, args->phdr);    
+        AUXARGS_ENTRY(pos, AT_PHENT, args->phent);  
+        AUXARGS_ENTRY(pos, AT_PHNUM, args->phnum);  
+        AUXARGS_ENTRY(pos, AT_PAGESZ, args->pagesz);
+        AUXARGS_ENTRY(pos, AT_FLAGS, args->flags);
+        AUXARGS_ENTRY(pos, AT_ENTRY, args->entry);
+        AUXARGS_ENTRY(pos, AT_BASE, args->base);
+        if (imgp->execpathp != 0)
+                AUXARGS_ENTRY(pos, AT_EXECPATH, imgp->execpathp);
+        AUXARGS_ENTRY(pos, AT_NULL, 0);
+                                                                                                                
 #endif
+
+#undef  DL_PLATFORM_INIT
+#define DL_PLATFORM_INIT dl_platform_kfreebsd_x86_64_init ()
+
+#ifndef _DL_MACHINE_KFREEBSD
+#define _DL_MACHINE_KFREEBSD
+
+static inline void cpuid(long op, long *rax, long *rdx)
+{
+    __asm__(
+	"push %%rbx\n\t"
+	"cpuid\n\t"
+	"pop %%rbx\n\t"
+	: "=a" (*rax),
+	  "=d" (*rdx)
+	: "0" (op)
+	: "rcx"
+    );
+}
+
+extern const char *_self_program_name_from_auxv attribute_hidden;
+
+                           
+static inline void __attribute__ ((unused))
+dl_platform_kfreebsd_x86_64_init (void)
+{
+	/* we don't have reasonable AT_PLATFORM from kernel
+	   use cpuid to guess AT_HWCAP */
+
+	long val, hwcap;
+
+	cpuid(1, &val, &hwcap);
+	GLRO(dl_hwcap) = hwcap;
+	_self_program_name_from_auxv = GLRO(dl_platform);
+	GLRO(dl_platform) = ELF_MACHINE_NAME;
+}
+
+#endif




More information about the Glibc-bsd-commits mailing list