]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Merge from the trunk, a bunch of improvements for exp-ptrcheck:
authorJulian Seward <jseward@acm.org>
Mon, 26 Jan 2009 15:45:59 +0000 (15:45 +0000)
committerJulian Seward <jseward@acm.org>
Mon, 26 Jan 2009 15:45:59 +0000 (15:45 +0000)
8908  Add some more system calls to ptrcheck.

9027  Ptrcheck: More aggressive suppression of error reports from ld.so.

9056  Handle a few more syscalls, as per #179618.

9059  Prior to this commit, exp-ptrcheck would assert if the DWARF3
      data for global or stack blocks described overlapping blocks

9060  Intercept and replace calls to calls to strnlen in glibc, for the
      usual reasons.

9061  Minor refinements:
      * h_main.c: handle a few more syscalls
      * exp-ptrcheck.supp: ignore errors in glibc's getenv
        -- is highly optimised
      * pc_common.c: fix small error in error message printing

9062  Remove function that was made redundant by r9059.

git-svn-id: svn://svn.valgrind.org/valgrind/branches/VALGRIND_3_4_BRANCH@9077

exp-ptrcheck.supp
exp-ptrcheck/h_intercepts.c
exp-ptrcheck/h_main.c
exp-ptrcheck/pc_common.c
exp-ptrcheck/sg_main.c
exp-ptrcheck/tests/bad_percentify.stderr.exp-glibc28-amd64

index 8cc93c1f16595ac4d102dee6a15f2dfb85465040..2b51ca3c9bb0fd930ef50c0b221ceb890fed7fc8 100644 (file)
@@ -25,8 +25,6 @@
    exp-ptrcheck:SorG
    obj:/*lib*/ld-2.*so*
    obj:/*lib*/ld-2.*so*
-   obj:/*lib*/ld-2.*so*
-   obj:/*lib*/ld-2.*so*
 }
 
 # I'm pretty sure this is a false positive caused by the sg_ stuff
@@ -44,3 +42,9 @@
    obj:/*lib*/ld-2.*so*
    obj:/*lib*/ld-2.*so*
 }
+
+{
+   I think this is glibc's ultra optimised getenv doing 2 byte reads
+   exp-ptrcheck:SorG
+   fun:getenv
+}
index 48819d4c6f2a9e7d0102028141a4d7c386016061..3ae8c6222ed0b88c6e5f2d0a3b82c1d6601d3f04 100644 (file)
 
 
 
+#define STRNLEN(soname, fnname) \
+   SizeT VG_REPLACE_FUNCTION_ZU(soname,fnname) ( const char* str, SizeT n ); \
+   SizeT VG_REPLACE_FUNCTION_ZU(soname,fnname) ( const char* str, SizeT n ) \
+   { \
+      SizeT i = 0; \
+      while (i < n && str[i] != 0) i++; \
+      return i; \
+   }
+
+STRNLEN(m_libc_soname, strnlen)
+
+
 // Note that this replacement often doesn't get used because gcc inlines
 // calls to strlen() with its own built-in version.  This can be very
 // confusing if you aren't expecting it.  Other small functions in this file
index 8272ce5d34013934c28902e344bd25ed2a8aea78..e335c0597eb6748f40c8b5c46cfc0944e2e2de8f 100644 (file)
@@ -2179,6 +2179,7 @@ static void setup_post_syscall_table ( void )
       ADD(0, __NR_accept);
 #     endif
       ADD(0, __NR_access);
+      ADD(0, __NR_alarm);
 #     if defined(__NR_bind)
       ADD(0, __NR_bind);
 #     endif
@@ -2187,6 +2188,9 @@ static void setup_post_syscall_table ( void )
 #     endif
       ADD(0, __NR_chmod);
       ADD(0, __NR_chown);
+#     if defined(__NR_chown32)
+      ADD(0, __NR_chown32);
+#     endif
       ADD(0, __NR_clock_getres);
       ADD(0, __NR_clock_gettime);
       ADD(0, __NR_clone);
@@ -2194,6 +2198,7 @@ static void setup_post_syscall_table ( void )
 #     if defined(__NR_connect)
       ADD(0, __NR_connect);
 #     endif
+      ADD(0, __NR_creat);
       ADD(0, __NR_dup);
       ADD(0, __NR_dup2);
       ADD(0, __NR_execve); /* presumably we see this because the call failed? */
@@ -2210,6 +2215,7 @@ static void setup_post_syscall_table ( void )
       ADD(0, __NR_fcntl64);
 #     endif
       ADD(0, __NR_fdatasync);
+      ADD(0, __NR_flock);
       ADD(0, __NR_fstat);
 #     if defined(__NR_fstat64)
       ADD(0, __NR_fstat64);
@@ -2246,12 +2252,14 @@ static void setup_post_syscall_table ( void )
       ADD(0, __NR_getresgid);
       ADD(0, __NR_getresuid);
       ADD(0, __NR_getrlimit);
+      ADD(0, __NR_getrusage);
 #     if defined(__NR_getsockname)
       ADD(0, __NR_getsockname);
 #     endif
 #     if defined(__NR_getsockopt)
       ADD(0, __NR_getsockopt);
 #     endif
+      ADD(0, __NR_gettid);
       ADD(0, __NR_gettimeofday);
       ADD(0, __NR_getuid);
 #     if defined(__NR_getuid32)
@@ -2262,6 +2270,7 @@ static void setup_post_syscall_table ( void )
       ADD(0, __NR_inotify_init);
       ADD(0, __NR_inotify_rm_watch);
       ADD(0, __NR_ioctl); // ioctl -- assuming no pointers returned
+      ADD(0, __NR_ioprio_get);
       ADD(0, __NR_kill);
       ADD(0, __NR_link);
 #     if defined(__NR_listen)
@@ -2274,6 +2283,7 @@ static void setup_post_syscall_table ( void )
 #     endif
       ADD(0, __NR_madvise);
       ADD(0, __NR_mkdir);
+      ADD(0, __NR_mlock);
       ADD(0, __NR_mprotect);
       ADD(0, __NR_munmap); // die_mem_munmap already called, segment remove);
       ADD(0, __NR_nanosleep);
@@ -2301,11 +2311,24 @@ static void setup_post_syscall_table ( void )
       ADD(0, __NR_sched_getaffinity);
       ADD(0, __NR_sched_getparam);
       ADD(0, __NR_sched_getscheduler);
+      ADD(0, __NR_sched_setaffinity);
       ADD(0, __NR_sched_setscheduler);
       ADD(0, __NR_sched_yield);
       ADD(0, __NR_select);
+#     if defined(__NR_semctl)
+      ADD(0, __NR_semctl);
+#     endif
+#     if defined(__NR_semget)
+      ADD(0, __NR_semget);
+#     endif
+#     if defined(__NR_semop)
+      ADD(0, __NR_semop);
+#     endif
 #     if defined(__NR_sendto)
       ADD(0, __NR_sendto);
+#     endif
+#     if defined(__NR_sendmsg)
+      ADD(0, __NR_sendmsg);
 #     endif
       ADD(0, __NR_set_robust_list);
 #     if defined(__NR_set_thread_area)
@@ -2326,6 +2349,7 @@ static void setup_post_syscall_table ( void )
 #     if defined(__NR_shutdown)
       ADD(0, __NR_shutdown);
 #     endif
+      ADD(0, __NR_sigaltstack);
 #     if defined(__NR_socket)
       ADD(0, __NR_socket);
 #     endif
index 26c81270f35679b92b386d628c6807ecdbbae0ea..7d73f35c413ee2f3f4edd7fb57365dc0c0333ea9 100644 (file)
@@ -397,7 +397,7 @@ void pc_pp_Error ( Error* err )
          VG_(pp_ExeContext)( VG_(get_error_where)(err) );
 
          VG_(message)(Vg_UserMsg, " Address %#lx is %ld bytes inside a "
-                                  "%ld-byte block alloc'd",
+                                  "%ld-byte block free'd",
                                   lo, lo-Seg__addr(seglo),
                                   Seg__size(seglo) );
          VG_(pp_ExeContext)(Seg__where(seglo));
index e5c82bd1aff95d5ab78e246a2b320eb3fbab4e37..0213dfa05348d4cd656c4fe174be36aa742c9758 100644 (file)
@@ -220,23 +220,19 @@ static Word StackBlocks__cmp ( XArray* fb1s, XArray* fb2s )
    return 0;
 }
 
-static void pp_StackBlock ( StackBlock* sb )
-{
-   VG_(printf)("StackBlock{ off %ld szB %lu spRel:%c isVec:%c \"%s\" }",
-               sb->base, sb->szB, sb->spRel ? 'Y' : 'N',
-               sb->isVec ? 'Y' : 'N', &sb->name[0] );
-}
-
 static void pp_StackBlocks ( XArray* sbs )
 {
    Word i, n = VG_(sizeXA)( sbs );
-   VG_(printf)("<<< STACKBLOCKS\n" );
+   VG_(message)(Vg_DebugMsg, "<<< STACKBLOCKS" );
    for (i = 0; i < n; i++) {
-      VG_(printf)("   ");
-      pp_StackBlock( (StackBlock*)VG_(indexXA)( sbs, i ) );
-      VG_(printf)("\n");
+      StackBlock* sb = (StackBlock*)VG_(indexXA)( sbs, i );
+      VG_(message)(Vg_DebugMsg,
+         "   StackBlock{ off %ld szB %lu spRel:%c isVec:%c \"%s\" }",
+         sb->base, sb->szB, sb->spRel ? 'Y' : 'N',
+         sb->isVec ? 'Y' : 'N', &sb->name[0] 
+      );
    }
-   VG_(printf)(">>> STACKBLOCKS\n" );
+   VG_(message)(Vg_DebugMsg, ">>> STACKBLOCKS" );
 }
 
 
@@ -332,14 +328,33 @@ static XArray* /* of StackBlock */
      }
    }
 
-   /* A rather poor sanity check on the results. */
+   /* If there are any blocks which overlap and have the same
+      fpRel-ness, junk the whole descriptor; it's obviously bogus.
+      Icc11 certainly generates bogus info from time to time.
+
+      This check is pretty weak; really we ought to have a stronger
+      sanity check. */
    { Word i, n = VG_(sizeXA)( orig );
+     static Int moans = 3;
      for (i = 0; i < n-1; i++) {
        StackBlock* sb1 = (StackBlock*)VG_(indexXA)( orig, i );
        StackBlock* sb2 = (StackBlock*)VG_(indexXA)( orig, i+1 );
-       if (sb1->base == sb2->base)
-          pp_StackBlocks(orig);
-       tl_assert(sb1->base != sb2->base);
+       if (sb1->spRel == sb2->spRel
+           && (sb1->base >= sb2->base
+               || sb1->base + sb1->szB > sb2->base)) {
+          if (moans > 0 && !VG_(clo_xml)) {
+             moans--;
+             VG_(message)(Vg_UserMsg, "Warning: bogus DWARF3 info: "
+                                      "overlapping stack blocks");
+             if (VG_(clo_verbosity) >= 2)
+                pp_StackBlocks(orig);
+             if (moans == 0)
+                VG_(message)(Vg_UserMsg, "Further instances of this "
+                                         "message will not be shown" );
+          }
+          VG_(dropTailXA)( orig, VG_(sizeXA)( orig ));
+          break;
+       }
      }
    }
 
@@ -674,6 +689,7 @@ static void add_block_to_GlobalTree (
    Bool already_present;
    GlobalTreeNode *nyu, *nd;
    UWord keyW, valW;
+   static Int moans = 3;
 
    tl_assert(descr->szB > 0);
    nyu = sg_malloc( "di.sg_main.abtG.1", sizeof(GlobalTreeNode) );
@@ -718,13 +734,25 @@ static void add_block_to_GlobalTree (
    already_present = VG_(addToFM)( gitree, (UWord)nyu, 0 );
    /* The interval can't already be there; else we have
       overlapping global blocks. */
-   if (already_present) {
-      GlobalTree__pp( gitree, "add_block_to_GlobalTree: non-exact duplicate" );
-      VG_(printf)("Overlapping block: ");
-      GlobalTreeNode__pp(nyu);
-      VG_(printf)("\n");
+   /* Unfortunately (25 Jan 09) at least icc11 has been seen to
+      generate overlapping block descriptions in the Dwarf3; clearly
+      bogus. */
+   if (already_present && moans > 0 && !VG_(clo_xml)) {
+      moans--;
+      VG_(message)(Vg_UserMsg, "Warning: bogus DWARF3 info: "
+                               "overlapping global blocks");
+      if (VG_(clo_verbosity) >= 2) {
+         GlobalTree__pp( gitree,
+                         "add_block_to_GlobalTree: non-exact duplicate" );
+         VG_(printf)("Overlapping block: ");
+         GlobalTreeNode__pp(nyu);
+         VG_(printf)("\n");
+      }
+      if (moans == 0)
+         VG_(message)(Vg_UserMsg, "Further instances of this "
+                                  "message will not be shown" );
    }
-   tl_assert(!already_present);
+   /* tl_assert(!already_present); */
 }
 
 static Bool del_GlobalTree_range ( /*MOD*/WordFM* gitree,
index 01c0b9fe4aaef3142a19a49287879a70ae0851a6..572da507d3585a203f86dd43f0f0f7e5f31edeb5 100644 (file)
@@ -1,6 +1,6 @@
 
 Invalid read of size 1
-   at 0x........: strlen (h_intercepts.c:85)
+   at 0x........: strlen (h_intercepts.c:97)
    by 0x........: ...
    by 0x........: ...
    by 0x........: VG_print_translation_stats (bad_percentify.c:88)
@@ -10,7 +10,7 @@ Invalid read of size 1
  Actual:   unknown
 
 Invalid read of size 1
-   at 0x........: strlen (h_intercepts.c:85)
+   at 0x........: strlen (h_intercepts.c:97)
    by 0x........: ...
    by 0x........: ...
    by 0x........: VG_print_translation_stats (bad_percentify.c:93)
@@ -20,7 +20,7 @@ Invalid read of size 1
  Actual:   unknown
 
 Invalid read of size 1
-   at 0x........: strlen (h_intercepts.c:85)
+   at 0x........: strlen (h_intercepts.c:97)
    by 0x........: ...
    by 0x........: ...
    by 0x........: VG_print_translation_stats (bad_percentify.c:98)