]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Patrick Ohly's --alignment= patch, to increase alignment of malloc'd
authorJulian Seward <jseward@acm.org>
Fri, 14 Jun 2002 10:17:05 +0000 (10:17 +0000)
committerJulian Seward <jseward@acm.org>
Fri, 14 Jun 2002 10:17:05 +0000 (10:17 +0000)
blocks if needed.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@422

12 files changed:
cachegrind/docs/manual.html
coregrind/docs/manual.html
coregrind/valgrind.in
coregrind/vg_clientmalloc.c
coregrind/vg_include.h
coregrind/vg_main.c
docs/manual.html
memcheck/docs/manual.html
valgrind.in
vg_clientmalloc.c
vg_include.h
vg_main.c

index 8c61ce49561baaccbc124e87b0c2957c7ead25ed..873aa5c7a724cba7df184c71d8cd6d5175a70867 100644 (file)
@@ -461,6 +461,17 @@ follows:
       maximum portability.
       </li><br><p>
 
+  <li><code>--alignment=&lt;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
index 8c61ce49561baaccbc124e87b0c2957c7ead25ed..873aa5c7a724cba7df184c71d8cd6d5175a70867 100644 (file)
@@ -461,6 +461,17 @@ follows:
       maximum portability.
       </li><br><p>
 
+  <li><code>--alignment=&lt;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
index 23aa12030473fe387a1a9f05967a64f250374e69..fe31ce6bbc6a1f4448a8df2e527b220627599838 100755 (executable)
@@ -61,6 +61,7 @@ do
     --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;;
@@ -130,6 +131,7 @@ if [ $# = 0 ] || [ z"$dousage" = z1 ]; then
    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]"
index 607c633b989d00e97862962f99a4dbf3392007b7..0292aa404d202550aeed82d87acfc536b7fff395 100644 (file)
@@ -223,7 +223,8 @@ static ShadowChunk* client_malloc_shadow ( ThreadState* tst,
                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);
@@ -271,7 +272,7 @@ void* VG_(client_malloc) ( ThreadState* tst, UInt size, VgAllocKind kind )
       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);
 }
@@ -466,7 +467,8 @@ void* VG_(client_realloc) ( ThreadState* tst, void* ptrV, UInt size_new )
       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) ( 
index fb675b949e6e7d9c3522f5657f66ff2c3b4f8156..6c28cd4e0d9d37dbe2530ba2414d17fb43b14750 100644 (file)
@@ -239,6 +239,9 @@ extern Int   VG_(clo_leak_resolution);
 /* 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 */
index afdcfe68503f206707177f712157d9afd599a2fc..3ed7ee0912e8d2e95036fedee2f9ef8e76fc9556 100644 (file)
@@ -409,6 +409,7 @@ Bool   VG_(clo_leak_check);
 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);
@@ -543,6 +544,7 @@ static void process_cmd_line_options ( void )
    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 */
@@ -757,6 +759,9 @@ static void process_cmd_line_options ( void )
       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"))
@@ -889,6 +894,16 @@ static void process_cmd_line_options ( void )
    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, 
index 8c61ce49561baaccbc124e87b0c2957c7ead25ed..873aa5c7a724cba7df184c71d8cd6d5175a70867 100644 (file)
@@ -461,6 +461,17 @@ follows:
       maximum portability.
       </li><br><p>
 
+  <li><code>--alignment=&lt;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
index 8c61ce49561baaccbc124e87b0c2957c7ead25ed..873aa5c7a724cba7df184c71d8cd6d5175a70867 100644 (file)
@@ -461,6 +461,17 @@ follows:
       maximum portability.
       </li><br><p>
 
+  <li><code>--alignment=&lt;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
index 23aa12030473fe387a1a9f05967a64f250374e69..fe31ce6bbc6a1f4448a8df2e527b220627599838 100755 (executable)
@@ -61,6 +61,7 @@ do
     --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;;
@@ -130,6 +131,7 @@ if [ $# = 0 ] || [ z"$dousage" = z1 ]; then
    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]"
index 607c633b989d00e97862962f99a4dbf3392007b7..0292aa404d202550aeed82d87acfc536b7fff395 100644 (file)
@@ -223,7 +223,8 @@ static ShadowChunk* client_malloc_shadow ( ThreadState* tst,
                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);
@@ -271,7 +272,7 @@ void* VG_(client_malloc) ( ThreadState* tst, UInt size, VgAllocKind kind )
       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);
 }
@@ -466,7 +467,8 @@ void* VG_(client_realloc) ( ThreadState* tst, void* ptrV, UInt size_new )
       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) ( 
index fb675b949e6e7d9c3522f5657f66ff2c3b4f8156..6c28cd4e0d9d37dbe2530ba2414d17fb43b14750 100644 (file)
@@ -239,6 +239,9 @@ extern Int   VG_(clo_leak_resolution);
 /* 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 */
index afdcfe68503f206707177f712157d9afd599a2fc..3ed7ee0912e8d2e95036fedee2f9ef8e76fc9556 100644 (file)
--- a/vg_main.c
+++ b/vg_main.c
@@ -409,6 +409,7 @@ Bool   VG_(clo_leak_check);
 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);
@@ -543,6 +544,7 @@ static void process_cmd_line_options ( void )
    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 */
@@ -757,6 +759,9 @@ static void process_cmd_line_options ( void )
       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"))
@@ -889,6 +894,16 @@ static void process_cmd_line_options ( void )
    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,