Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Nov 2008 23:03:31 GMT
From:      Peter Wemm <peter@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 152911 for review
Message-ID:  <200811122303.mACN3Vd5088839@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=152911

Change 152911 by peter@peter_hammer on 2008/11/12 23:02:51

	Attempt to cover both cases of running 32 bit binaries on 64 bit hosts.
	We may be using ld-elf32.so.1, which wants $LD_32_PRELOAD.  Or it might
	be a regular i386 ld-elf.so.1 in a chroot, which will want $LD_PRELOAD.
	Cover both scenarios.

Affected files ...

.. //depot/projects/valgrind/coregrind/m_initimg/initimg-freebsd.c#5 edit

Differences ...

==== //depot/projects/valgrind/coregrind/m_initimg/initimg-freebsd.c#5 (text+ko) ====

@@ -217,12 +217,17 @@
 static HChar** setup_client_env ( HChar** origenv, const HChar* toolname)
 {
    HChar* preload_core    = "vgpreload_core";
-   HChar* ld_preload;
+   HChar* ld_preload      = "LD_PRELOAD=";
    HChar* v_launcher      = VALGRIND_LAUNCHER "=";
-   Int    ld_preload_len;
+   Int    ld_preload_len  = VG_(strlen)( ld_preload );
    Int    v_launcher_len  = VG_(strlen)( v_launcher );
    Bool   ld_preload_done = False;
    Int    vglib_len       = VG_(strlen)(VG_(libdir));
+#if defined(VGP_x86_freebsd)
+   HChar* ld_32_preload    = "LD_32_PRELOAD=";
+   Int    ld_32_preload_len = VG_(strlen)( ld_32_preload );
+   Bool   ld_32_preload_done = False;
+#endif
 
    HChar** cpp;
    HChar** ret;
@@ -277,15 +282,6 @@
    
    vg_assert(envc == (cpp - ret));
 
-   ld_preload      = "LD_PRELOAD=";
-   ld_preload_len  = VG_(strlen)( ld_preload );
-#if defined(VGP_x86_freebsd)
-   if (VG_(is32on64)())
-      ld_preload      = "LD_32_PRELOAD=";
-   else
-#endif
-      ld_preload      = "LD_PRELOAD=";
-   ld_preload_len  = VG_(strlen)( ld_preload );
    /* Walk over the new environment, mashing as we go */
    for (cpp = ret; cpp && *cpp; cpp++) {
       if (VG_(memcmp)(*cpp, ld_preload, ld_preload_len) == 0) {
@@ -313,6 +309,37 @@
       ret[envc++] = cp;
    }
 
+#if defined(VGP_x86_freebsd)
+   /* If we're running a 32 bit binary, ld-elf32.so.1 may be looking for
+    * a different variable name.  Or it might be a 32 bit ld-elf.so.1 in a
+    * chroot.  Cover both cases. */
+   if (VG_(is32on64)()) {
+      for (cpp = ret; cpp && *cpp; cpp++) {
+	 if (VG_(memcmp)(*cpp, ld_32_preload, ld_32_preload_len) == 0) {
+	    Int len = VG_(strlen)(*cpp) + preload_string_len;
+	    HChar *cp = VG_(malloc)("initimg-linux.sce.4a", len);
+	    vg_assert(cp);
+
+	    VG_(snprintf)(cp, len, "%s%s:%s",
+			  ld_32_preload, preload_string, (*cpp)+ld_32_preload_len);
+
+	    *cpp = cp;
+
+	    ld_32_preload_done = True;
+	 }
+      }
+      if (!ld_32_preload_done) {
+	 Int len = ld_32_preload_len + preload_string_len;
+	 HChar *cp = VG_(malloc) ("initimg-linux.sce.5a", len);
+	 vg_assert(cp);
+
+	 VG_(snprintf)(cp, len, "%s%s", ld_32_preload, preload_string);
+
+	 ret[envc++] = cp;
+      }
+   }
+#endif
+
    /* ret[0 .. envc-1] is live now. */
    /* Find and remove a binding for VALGRIND_LAUNCHER. */
    for (i = 0; i < envc; i++)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200811122303.mACN3Vd5088839>