blocks if needed.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@422
maximum portability.
</li><br><p>
+ <li><code>--alignment=<number></code> [default: 4]<br> <p>By
+ default valgrind's <code>malloc</code>, <code>realloc</code>,
+ etc, return 4-byte aligned addresses. These are suitable for
+ any accesses on x86 processors.
+ Some programs might however assume that <code>malloc</code> et
+ al return 8- or more aligned memory.
+ These programs are broken and should be fixed, but
+ if this is impossible for whatever reason the alignment can be
+ increased using this parameter. The supplied value must be
+ between 4 and 4096 inclusive, and must be a power of two.</li><br><p>
+
<li><code>--trace-children=no</code> [the default]</br>
<code>--trace-children=yes</code>
<p>When enabled, Valgrind will trace into child processes. This
maximum portability.
</li><br><p>
+ <li><code>--alignment=<number></code> [default: 4]<br> <p>By
+ default valgrind's <code>malloc</code>, <code>realloc</code>,
+ etc, return 4-byte aligned addresses. These are suitable for
+ any accesses on x86 processors.
+ Some programs might however assume that <code>malloc</code> et
+ al return 8- or more aligned memory.
+ These programs are broken and should be fixed, but
+ if this is impossible for whatever reason the alignment can be
+ increased using this parameter. The supplied value must be
+ between 4 and 4096 inclusive, and must be a power of two.</li><br><p>
+
<li><code>--trace-children=no</code> [the default]</br>
<code>--trace-children=yes</code>
<p>When enabled, Valgrind will trace into child processes. This
--leak-resolution=high) vgopts="$vgopts $arg"; shift;;
--sloppy-malloc=no) vgopts="$vgopts $arg"; shift;;
--sloppy-malloc=yes) vgopts="$vgopts $arg"; shift;;
+ --alignment=*) vgopts="$vgopts $arg"; shift;;
--trace-children=no) vgopts="$vgopts $arg"; shift;;
--trace-children=yes) vgopts="$vgopts $arg"; shift;;
--workaround-gcc296-bugs=no) vgopts="$vgopts $arg"; shift;;
echo " amount of bt merging in leak check [low]"
echo " --show-reachable=no|yes show reachable blocks in leak check? [no]"
echo " --sloppy-malloc=no|yes round malloc sizes to next word? [no]"
+ echo " --alignment=<number> set minimum alignment of allocations [4]"
echo " --trace-children=no|yes Valgrind-ise child processes? [no]"
echo " --logfile-fd=<number> file descriptor for messages [2=stderr]"
echo " --freelist-vol=<number> volume of freed blocks queue [1000000]"
align, size );
# endif
- if (align == 0)
+ vg_assert(align >= 4);
+ if (align == 4)
p = (Addr)VG_(malloc)(VG_AR_CLIENT, size);
else
p = (Addr)VG_(malloc_aligned)(VG_AR_CLIENT, align, size);
return VG_(malloc) ( VG_AR_CLIENT, size );
}
- sc = client_malloc_shadow ( tst, 0, size, kind );
+ sc = client_malloc_shadow ( tst, VG_(clo_alignment), size, kind );
VGP_POPCC;
return (void*)(sc->data);
}
return ptrV;
} else {
/* new size is bigger */
- sc_new = client_malloc_shadow ( tst, 0, size_new, Vg_AllocMalloc );
+ sc_new = client_malloc_shadow ( tst, VG_(clo_alignment),
+ size_new, Vg_AllocMalloc );
for (i = 0; i < sc->size; i++)
((UChar*)(sc_new->data))[i] = ((UChar*)(sc->data))[i];
VGM_(copy_address_range_perms) (
/* Round malloc sizes upwards to integral number of words? default:
NO */
extern Bool VG_(clo_sloppy_malloc);
+/* Minimum alignment in functions that don't specify alignment explicitly.
+ default: 0, i.e. use default of the machine (== 4) */
+extern Int VG_(clo_alignment);
/* Allow loads from partially-valid addresses? default: YES */
extern Bool VG_(clo_partial_loads_ok);
/* Simulate child processes? default: NO */
Bool VG_(clo_show_reachable);
Int VG_(clo_leak_resolution);
Bool VG_(clo_sloppy_malloc);
+Int VG_(clo_alignment);
Bool VG_(clo_partial_loads_ok);
Bool VG_(clo_trace_children);
Int VG_(clo_logfile_fd);
VG_(clo_show_reachable) = False;
VG_(clo_leak_resolution) = 2;
VG_(clo_sloppy_malloc) = False;
+ VG_(clo_alignment) = 4;
VG_(clo_partial_loads_ok) = True;
VG_(clo_trace_children) = False;
VG_(clo_logfile_fd) = 2; /* stderr */
else if (STREQ(argv[i], "--sloppy-malloc=no"))
VG_(clo_sloppy_malloc) = False;
+ else if (STREQN(12, argv[i], "--alignment="))
+ VG_(clo_alignment) = (Int)VG_(atoll)(&argv[i][12]);
+
else if (STREQ(argv[i], "--trace-children=yes"))
VG_(clo_trace_children) = True;
else if (STREQ(argv[i], "--trace-children=no"))
if (VG_(clo_verbosity < 0))
VG_(clo_verbosity) = 0;
+ if (VG_(clo_alignment) < 4
+ || VG_(clo_alignment) > 4096
+ || VG_(log2)( VG_(clo_alignment) ) == -1 /* not a power of 2 */) {
+ VG_(message)(Vg_UserMsg, "");
+ VG_(message)(Vg_UserMsg,
+ "Invalid --alignment= setting. "
+ "Should be a power of 2, >= 4, <= 4096.");
+ bad_option("--alignment");
+ }
+
if (VG_(clo_GDB_attach) && VG_(clo_trace_children)) {
VG_(message)(Vg_UserMsg, "");
VG_(message)(Vg_UserMsg,
maximum portability.
</li><br><p>
+ <li><code>--alignment=<number></code> [default: 4]<br> <p>By
+ default valgrind's <code>malloc</code>, <code>realloc</code>,
+ etc, return 4-byte aligned addresses. These are suitable for
+ any accesses on x86 processors.
+ Some programs might however assume that <code>malloc</code> et
+ al return 8- or more aligned memory.
+ These programs are broken and should be fixed, but
+ if this is impossible for whatever reason the alignment can be
+ increased using this parameter. The supplied value must be
+ between 4 and 4096 inclusive, and must be a power of two.</li><br><p>
+
<li><code>--trace-children=no</code> [the default]</br>
<code>--trace-children=yes</code>
<p>When enabled, Valgrind will trace into child processes. This
maximum portability.
</li><br><p>
+ <li><code>--alignment=<number></code> [default: 4]<br> <p>By
+ default valgrind's <code>malloc</code>, <code>realloc</code>,
+ etc, return 4-byte aligned addresses. These are suitable for
+ any accesses on x86 processors.
+ Some programs might however assume that <code>malloc</code> et
+ al return 8- or more aligned memory.
+ These programs are broken and should be fixed, but
+ if this is impossible for whatever reason the alignment can be
+ increased using this parameter. The supplied value must be
+ between 4 and 4096 inclusive, and must be a power of two.</li><br><p>
+
<li><code>--trace-children=no</code> [the default]</br>
<code>--trace-children=yes</code>
<p>When enabled, Valgrind will trace into child processes. This
--leak-resolution=high) vgopts="$vgopts $arg"; shift;;
--sloppy-malloc=no) vgopts="$vgopts $arg"; shift;;
--sloppy-malloc=yes) vgopts="$vgopts $arg"; shift;;
+ --alignment=*) vgopts="$vgopts $arg"; shift;;
--trace-children=no) vgopts="$vgopts $arg"; shift;;
--trace-children=yes) vgopts="$vgopts $arg"; shift;;
--workaround-gcc296-bugs=no) vgopts="$vgopts $arg"; shift;;
echo " amount of bt merging in leak check [low]"
echo " --show-reachable=no|yes show reachable blocks in leak check? [no]"
echo " --sloppy-malloc=no|yes round malloc sizes to next word? [no]"
+ echo " --alignment=<number> set minimum alignment of allocations [4]"
echo " --trace-children=no|yes Valgrind-ise child processes? [no]"
echo " --logfile-fd=<number> file descriptor for messages [2=stderr]"
echo " --freelist-vol=<number> volume of freed blocks queue [1000000]"
align, size );
# endif
- if (align == 0)
+ vg_assert(align >= 4);
+ if (align == 4)
p = (Addr)VG_(malloc)(VG_AR_CLIENT, size);
else
p = (Addr)VG_(malloc_aligned)(VG_AR_CLIENT, align, size);
return VG_(malloc) ( VG_AR_CLIENT, size );
}
- sc = client_malloc_shadow ( tst, 0, size, kind );
+ sc = client_malloc_shadow ( tst, VG_(clo_alignment), size, kind );
VGP_POPCC;
return (void*)(sc->data);
}
return ptrV;
} else {
/* new size is bigger */
- sc_new = client_malloc_shadow ( tst, 0, size_new, Vg_AllocMalloc );
+ sc_new = client_malloc_shadow ( tst, VG_(clo_alignment),
+ size_new, Vg_AllocMalloc );
for (i = 0; i < sc->size; i++)
((UChar*)(sc_new->data))[i] = ((UChar*)(sc->data))[i];
VGM_(copy_address_range_perms) (
/* Round malloc sizes upwards to integral number of words? default:
NO */
extern Bool VG_(clo_sloppy_malloc);
+/* Minimum alignment in functions that don't specify alignment explicitly.
+ default: 0, i.e. use default of the machine (== 4) */
+extern Int VG_(clo_alignment);
/* Allow loads from partially-valid addresses? default: YES */
extern Bool VG_(clo_partial_loads_ok);
/* Simulate child processes? default: NO */
Bool VG_(clo_show_reachable);
Int VG_(clo_leak_resolution);
Bool VG_(clo_sloppy_malloc);
+Int VG_(clo_alignment);
Bool VG_(clo_partial_loads_ok);
Bool VG_(clo_trace_children);
Int VG_(clo_logfile_fd);
VG_(clo_show_reachable) = False;
VG_(clo_leak_resolution) = 2;
VG_(clo_sloppy_malloc) = False;
+ VG_(clo_alignment) = 4;
VG_(clo_partial_loads_ok) = True;
VG_(clo_trace_children) = False;
VG_(clo_logfile_fd) = 2; /* stderr */
else if (STREQ(argv[i], "--sloppy-malloc=no"))
VG_(clo_sloppy_malloc) = False;
+ else if (STREQN(12, argv[i], "--alignment="))
+ VG_(clo_alignment) = (Int)VG_(atoll)(&argv[i][12]);
+
else if (STREQ(argv[i], "--trace-children=yes"))
VG_(clo_trace_children) = True;
else if (STREQ(argv[i], "--trace-children=no"))
if (VG_(clo_verbosity < 0))
VG_(clo_verbosity) = 0;
+ if (VG_(clo_alignment) < 4
+ || VG_(clo_alignment) > 4096
+ || VG_(log2)( VG_(clo_alignment) ) == -1 /* not a power of 2 */) {
+ VG_(message)(Vg_UserMsg, "");
+ VG_(message)(Vg_UserMsg,
+ "Invalid --alignment= setting. "
+ "Should be a power of 2, >= 4, <= 4096.");
+ bad_option("--alignment");
+ }
+
if (VG_(clo_GDB_attach) && VG_(clo_trace_children)) {
VG_(message)(Vg_UserMsg, "");
VG_(message)(Vg_UserMsg,