From: Philippe Waroquiers Date: Wed, 19 Apr 2017 20:15:50 +0000 (+0000) Subject: Have a cleaner way to remove the massif preload from LD_PRELOAD. X-Git-Tag: svn/VALGRIND_3_13_0~128 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0282832312e2de76b2f3a5d3f22bf34749d5979a;p=thirdparty%2Fvalgrind.git Have a cleaner way to remove the massif preload from LD_PRELOAD. The previous code was removing the massif preload (when --pages-as-heap=yes) by replacing the entry with spaces. This is not very clear, and I suspect this gives problems with the android linker, which seems to use such a space entry as a real entry to load (and then fails to start the application). This patch really removes the entry, by shifting the characters. Tested on amd64/debian. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16306 --- diff --git a/massif/ms_main.c b/massif/ms_main.c index cda4635265..2d5091aa02 100644 --- a/massif/ms_main.c +++ b/massif/ms_main.c @@ -1947,8 +1947,6 @@ static void ms_post_clo_init(void) { Int i; HChar* LD_PRELOAD_val; - HChar* s; - HChar* s2; /* We will record execontext up to clo_depth + overestimate and we will store this as ec => we need to increase the backtrace size @@ -1969,35 +1967,42 @@ static void ms_post_clo_init(void) // If --pages-as-heap=yes we don't want malloc replacement to occur. So we // disable vgpreload_massif-$PLATFORM.so by removing it from LD_PRELOAD (or - // platform-equivalent). We replace it entirely with spaces because then - // the linker doesn't complain (it does complain if we just change the name - // to a bogus file). This is a bit of a hack, but LD_PRELOAD is setup well - // before tool initialisation, so this seems the best way to do it. + // platform-equivalent). This is a bit of a hack, but LD_PRELOAD is setup + // well before tool initialisation, so this seems the best way to do it. if (clo_pages_as_heap) { + HChar* s1; + HChar* s2; + clo_heap_admin = 0; // No heap admin on pages. LD_PRELOAD_val = VG_(getenv)( VG_(LD_PRELOAD_var_name) ); tl_assert(LD_PRELOAD_val); + VERB(2, "clo_pages_as_heap orig LD_PRELOAD '%s'\n", LD_PRELOAD_val); + // Make sure the vgpreload_core-$PLATFORM entry is there, for sanity. - s2 = VG_(strstr)(LD_PRELOAD_val, "vgpreload_core"); - tl_assert(s2); + s1 = VG_(strstr)(LD_PRELOAD_val, "vgpreload_core"); + tl_assert(s1); // Now find the vgpreload_massif-$PLATFORM entry. - s2 = VG_(strstr)(LD_PRELOAD_val, "vgpreload_massif"); - tl_assert(s2); + s1 = VG_(strstr)(LD_PRELOAD_val, "vgpreload_massif"); + tl_assert(s1); + s2 = s1; - // Blank out everything to the previous ':', which must be there because + // Position s1 on the previous ':', which must be there because // of the preceding vgpreload_core-$PLATFORM entry. - for (s = s2; *s != ':'; s--) { - *s = ' '; - } + for (; *s1 != ':'; s1--) + ; - // Blank out everything to the end of the entry, which will be '\0' if - // LD_PRELOAD was empty before Valgrind started, or ':' otherwise. - for (s = s2; *s != ':' && *s != '\0'; s++) { - *s = ' '; - } + // Position s2 on the next ':' or \0 + for (; *s2 != ':' && *s2 != '\0'; s2++) + ; + + // Move all characters from s2 to s1 + while ((*s1++ = *s2++)) + ; + + VERB(2, "clo_pages_as_heap cleaned LD_PRELOAD '%s'\n", LD_PRELOAD_val); } // Print alloc-fns and ignore-fns, if necessary.