|
From: <sv...@va...> - 2005-11-08 02:25:41
|
Author: sewardj
Date: 2005-11-08 02:25:37 +0000 (Tue, 08 Nov 2005)
New Revision: 5035
Log:
memcheck: make --partial-loads-ok=3Dyes work again, but now make it
the non-default (it's a hack after all).
Modified:
trunk/memcheck/docs/mc-manual.xml
trunk/memcheck/mac_shared.c
trunk/memcheck/mc_main.c
Modified: trunk/memcheck/docs/mc-manual.xml
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/docs/mc-manual.xml 2005-11-08 01:24:23 UTC (rev 5034)
+++ trunk/memcheck/docs/mc-manual.xml 2005-11-08 02:25:37 UTC (rev 5035)
@@ -46,9 +46,6 @@
<computeroutput>memcpy()</computeroutput> and related
functions</para>
</listitem>
- <listitem>
- <para>Some misuses of the POSIX pthreads API</para>
- </listitem>
</itemizedlist>
=20
</sect1>
@@ -159,19 +156,25 @@
=20
<listitem id=3D"partial">
<para><computeroutput>--partial-loads-ok=3Dyes</computeroutput>
- [default]</para>
- <para><computeroutput>--partial-loads-ok=3Dno</computeroutput></para=
>
- <para>Controls how Memcheck handles word (4-byte) loads from
+ </para>
+ <para><computeroutput>--partial-loads-ok=3Dno</computeroutput>[defau=
lt]
+ </para>
+ <para>Controls how Memcheck handles word-sized, word-aligned loads f=
rom
addresses for which some bytes are addressible and others are
- not. When <computeroutput>yes</computeroutput> (the
- default), such loads do not elicit an address error.
+ not. When <computeroutput>yes</computeroutput>,
+ such loads do not elicit an address error.
Instead, the loaded V bytes corresponding to the illegal
- addresses indicate undefined, and those corresponding to
+ addresses indicate Undefined, and those corresponding to
legal addresses are loaded from shadow memory, as usual.</para>
- <para>When <computeroutput>no</computeroutput>, loads from
- partially invalid addresses are treated the same as loads
- from completely invalid addresses: an illegal-address error
+ <para>When <computeroutput>no</computeroutput>(the default),=20
+ loads from partially invalid addresses are treated the same as=20
+ loads from completely invalid addresses: an illegal-address error
is issued, and the resulting V bytes indicate valid data.</para>
+ <para>Note that code that behaves in this way is in violation of
+ the the ISO C/C++ standards, and should be considered broken.
+ If at all possible, such code should be fixed. This flag should
+ be used only as a last resort.
+ </para>
</listitem>
=20
<listitem id=3D"strlen">
Modified: trunk/memcheck/mac_shared.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/mac_shared.c 2005-11-08 01:24:23 UTC (rev 5034)
+++ trunk/memcheck/mac_shared.c 2005-11-08 02:25:37 UTC (rev 5035)
@@ -58,7 +58,7 @@
/*--- Command line options ---*/
/*------------------------------------------------------------*/
=20
-Bool MAC_(clo_partial_loads_ok) =3D True;
+Bool MAC_(clo_partial_loads_ok) =3D False;
Int MAC_(clo_freelist_vol) =3D 5000000;
LeakCheckMode MAC_(clo_leak_check) =3D LC_Summary;
VgRes MAC_(clo_leak_resolution) =3D Vg_LowRes;
@@ -100,7 +100,7 @@
" --leak-check=3Dno|summary|full search for memory leaks at exit?=
[summary]\n"
" --leak-resolution=3Dlow|med|high how much bt merging in leak chec=
k [low]\n"
" --show-reachable=3Dno|yes show reachable blocks in leak ch=
eck? [no]\n"
-" --partial-loads-ok=3Dno|yes too hard to explain here; see ma=
nual [yes]\n"
+" --partial-loads-ok=3Dno|yes too hard to explain here; see ma=
nual [no]\n"
" --freelist-vol=3D<number> volume of freed blocks queue [50=
00000]\n"
" --workaround-gcc296-bugs=3Dno|yes self explanatory [no]\n"
);
Modified: trunk/memcheck/mc_main.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/mc_main.c 2005-11-08 01:24:23 UTC (rev 5034)
+++ trunk/memcheck/mc_main.c 2005-11-08 02:25:37 UTC (rev 5035)
@@ -417,7 +417,7 @@
SizeT i =3D szB-1;
SizeT n_addrs_bad =3D 0;
Addr ai;
- Bool aok;
+ Bool aok, partial_load_exemption_applies;
UWord abit, vbyte;
=20
PROF_EVENT(30, "mc_LOADVn_slow");
@@ -436,7 +436,25 @@
i--;
}
=20
- if (n_addrs_bad > 0)
+ /* This is a hack which avoids producing errors for code which
+ insists in stepping along byte strings in aligned word-sized
+ chunks, and there is a partially defined word at the end. (eg,
+ optimised strlen). Such code is basically broken at least WRT
+ semantics of ANSI C, but sometimes users don't have the option
+ to fix it, and so this option is provided. Note it is now
+ defaulted to not-engaged.
+
+ A load from a partially-addressible place is allowed if:
+ - the command-line flag is set
+ - it's a word-sized, word-aligned load
+ - at least one of the addresses in the word *is* valid
+ */
+ partial_load_exemption_applies
+ =3D MAC_(clo_partial_loads_ok) && szB =3D=3D VG_WORDSIZE=20
+ && VG_IS_WORD_ALIGNED(a)=20
+ && n_addrs_bad < VG_WORDSIZE;
+
+ if (n_addrs_bad > 0 && !partial_load_exemption_applies)
MAC_(record_address_error)( VG_(get_running_tid)(), a, szB, False =
);
=20
return vw;
|