From: Julian Seward Date: Mon, 26 Jan 2009 15:45:59 +0000 (+0000) Subject: Merge from the trunk, a bunch of improvements for exp-ptrcheck: X-Git-Tag: svn/VALGRIND_3_4_1~40 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9490731db6c1aa942f50d40d89ec0f9abb716768;p=thirdparty%2Fvalgrind.git Merge from the trunk, a bunch of improvements for exp-ptrcheck: 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 --- diff --git a/exp-ptrcheck.supp b/exp-ptrcheck.supp index 8cc93c1f16..2b51ca3c9b 100644 --- a/exp-ptrcheck.supp +++ b/exp-ptrcheck.supp @@ -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 +} diff --git a/exp-ptrcheck/h_intercepts.c b/exp-ptrcheck/h_intercepts.c index 48819d4c6f..3ae8c6222e 100644 --- a/exp-ptrcheck/h_intercepts.c +++ b/exp-ptrcheck/h_intercepts.c @@ -69,6 +69,18 @@ +#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 diff --git a/exp-ptrcheck/h_main.c b/exp-ptrcheck/h_main.c index 8272ce5d34..e335c0597e 100644 --- a/exp-ptrcheck/h_main.c +++ b/exp-ptrcheck/h_main.c @@ -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 diff --git a/exp-ptrcheck/pc_common.c b/exp-ptrcheck/pc_common.c index 26c81270f3..7d73f35c41 100644 --- a/exp-ptrcheck/pc_common.c +++ b/exp-ptrcheck/pc_common.c @@ -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)); diff --git a/exp-ptrcheck/sg_main.c b/exp-ptrcheck/sg_main.c index e5c82bd1af..0213dfa053 100644 --- a/exp-ptrcheck/sg_main.c +++ b/exp-ptrcheck/sg_main.c @@ -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, diff --git a/exp-ptrcheck/tests/bad_percentify.stderr.exp-glibc28-amd64 b/exp-ptrcheck/tests/bad_percentify.stderr.exp-glibc28-amd64 index 01c0b9fe4a..572da507d3 100644 --- a/exp-ptrcheck/tests/bad_percentify.stderr.exp-glibc28-amd64 +++ b/exp-ptrcheck/tests/bad_percentify.stderr.exp-glibc28-amd64 @@ -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)