{"id":1549,"date":"2014-08-07T16:35:55","date_gmt":"2014-08-07T23:35:55","guid":{"rendered":"http:\/\/joelinoff.com\/blog\/?p=1549"},"modified":"2014-08-09T11:28:37","modified_gmt":"2014-08-09T18:28:37","slug":"bash-script-to-build-and-install-valgrind-3-9-0-with-memory-limits-of-128gb-256gb-and-512gb-on-linux-x86_64","status":"publish","type":"post","link":"https:\/\/joelinoff.com\/blog\/?p=1549","title":{"rendered":"Bash script to build and install valgrind 3.9.0 with memory limits of 128GB, 256GB and 512GB on linux-x86_64"},"content":{"rendered":"<p>Valgrind must have fixed memory limits so that it can accurately track the memory allocations of the program under test. On 64 bit architectures it is limited to 64GB. This <a href=\"http:\/\/projects.joelinoff.com\/valgrind\/valgrind-3.9.0-setup.sh.txt\" title=\"http:\/\/projects.joelinoff.com\/valgrind\/valgrind-3.9.0-setup.sh\">script<\/a> will download, modify and build valgrind for larger memory configurations.<br \/>\n<!--more--><\/p>\n<p>Here is an example of how you might download and use it to create a 128GB version.<\/p>\n<pre class=\"theme:vs2012-black font-size:14 line-height:17 lang:default decode:true \" >$ # Example - 128GB\r\n$ mkdir -p work\/valgrind\/3.9.0\r\n$ cd work\/valgrind\/3.9.0\r\n$ wget http:\/\/projects.joelinoff.com\/valgrind\/valgrind-3.9.0-setup.sh\r\n$ .\/valgrind-3.9.0-setup.sh 128 2>&1|tee log  # Build a 128GB version.\r\n$ .\/rtf\/bin\/valgrind -h\r\n<\/pre>\n<p>Here is an example of how you might download and use it to create a 256GB version.<\/p>\n<pre class=\"theme:vs2012-black font-size:14 line-height:17 lang:default decode:true \" >$ # Example - 256GB\r\n$ mkdir -p work\/valgrind\/3.9.0\r\n$ cd work\/valgrind\/3.9.0\r\n$ wget http:\/\/projects.joelinoff.com\/valgrind\/valgrind-3.9.0-setup.sh\r\n$ .\/valgrind-3.9.0-setup.sh 256 2>&1|tee log  # Build a 256GB version.\r\n$ .\/rtf\/bin\/valgrind -h\r\n<\/pre>\n<p>Here is a description of how you might use it on an example program.<\/p>\n<h3>Step 1. Compile and link the program<\/h3>\n<p>In this very simple example I am using debug compile flags with extensions that provide more information in valgrind. These compile flags must be used with a newer GNU compiler like 4.7.2. I am using 4.9.1 for this example.<\/p>\n<pre class=\"theme:vs2012-black font-size:14 line-height:17 lang:default decode:true \" >\r\n$ RTFDIR=\"\/opt\/gcc\/4.9.1\"  # g++ 4.9.1 compiler (local installation)\r\n$ export PATH=\"$RTFDIR\/bin:${PATH}\"\r\n$ export LD_LIBRARY_PATH=\"$RTFDIR\/lib64:$RTFDIR\/lib:${LD_LIBRARY_PATH}\"\r\n$ cat test.cc\r\n#include <vector>\r\n#include <string>\r\n#include <iostream>\r\n#include <iomanip>\r\nusing namespace std;\r\n\r\nvoid sub1()\r\n{\r\n  vector<string> strs;\r\n  for(int i=1; i<10; i++) {\r\n    char buf[79];\r\n    for(unsigned i=0; i<sizeof(buf); i++) {\r\n      buf[i] = '0' + i;\r\n    }\r\n    buf[sizeof(buf)-1] = 0;\r\n    strs.push_back(buf);\r\n  }\r\n  unsigned i=0;\r\n  for(auto str : strs) {\r\n    cout << right << setw(4) << ++i << \" \"\r\n         << str.size()\r\n         << \"\\\"\" << str << \"\\\" \"\r\n         << endl;\r\n  }\r\n}\r\n\r\nint main()\r\n{\r\n  cout << \"test\" << endl;\r\n  sub1();\r\n  cout << \"done\" << endl;\r\n  return 0;\r\n}\r\n$ g++ --version\r\ng++ (GCC) 4.9.1\r\nCopyright (C) 2014 Free Software Foundation, Inc.\r\nThis is free software; see the source for copying conditions.  There is NO\r\nwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\r\n\r\n$ g++ -DDEBUG \\\r\n    -std=c++11 \\\r\n    -Wall \\\r\n    -g3 \\\r\n    -gno-strict-dwarf \\\r\n    -gdwarf-3 \\\r\n    -fvar-tracking \\\r\n    --param max-vartrack-size=0 \\\r\n    --param max-vartrack-expr-depth=50 \\\r\n    -o .\/test.exe \\\r\n    test.cc\r\n$ .\/test.exe\r\ntest\r\n   1 78\"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}\" \r\n   2 78\"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}\" \r\n   3 78\"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}\" \r\n   4 78\"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}\" \r\n   5 78\"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}\" \r\n   6 78\"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}\" \r\n   7 78\"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}\" \r\n   8 78\"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}\" \r\n   9 78\"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}\" \r\ndone\r\n<\/pre>\n<h3>Step 2. Run valgrind<\/h3>\n<p>This is how you might run valgrind. It includes a suppression file just to show how it works.<\/p>\n<pre class=\"theme:vs2012-black font-size:14 line-height:17 lang:default decode:true \" >\r\n$ cat test.supp\r\n# This is an example suppression.\r\n# It is not needed for this example.\r\n{\r\n   ipp-suppress-conditional-jump1\r\n   Memcheck:Cond\r\n   fun:index\r\n   fun:expand_dynamic_string_token\r\n   fun:_dl_map_object\r\n   fun:map_doit\r\n}\r\n$ ~\/work\/valgrind\/3.9.0\/rtf\/bin\/valgrind --version\r\nvalgrind-3.9.0\r\n$ RTFDIR=\"\/opt\/gcc\/4.9.1\"  # g++ 4.9.1 compiler (local installation)\r\n$ export PATH=\"$RTFDIR\/bin:${PATH}\"\r\n$ export LD_LIBRARY_PATH=\"$RTFDIR\/lib64:$RTFDIR\/lib:${LD_LIBRARY_PATH}\"\r\n$ ~\/work\/valgrind\/3.9.0\/rtf\/bin\/valgrind \\\r\n    --tool=memcheck \\\r\n    --error-limit=no \\\r\n    --free-fill=0xcd \\\r\n    --keep-stacktraces=alloc-and-free \\\r\n    --leak-check=full \\\r\n    --leak-resolution=med \\\r\n    --main-stacksize=16777216 \\\r\n    --malloc-fill=0xab \\\r\n    --max-stackframe=4194304 \\\r\n    --num-callers=50 \\\r\n    --read-var-info=yes \\\r\n    --show-reachable=yes \\\r\n    --suppressions=.\/test.supp \\\r\n    --trace-children=yes \\\r\n    --track-origins=yes \\\r\n    -v \\\r\n    .\/test.exe\r\n==23754== Memcheck, a memory error detector\r\n==23754== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.\r\n==23754== Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info\r\n==23754== Command: .\/test.exe\r\n==23754== \r\n--23754-- Valgrind options:\r\n--23754--    --tool=memcheck\r\n--23754--    --error-limit=no\r\n--23754--    --free-fill=0xcd\r\n--23754--    --keep-stacktraces=alloc-and-free\r\n--23754--    --leak-check=full\r\n--23754--    --leak-resolution=med\r\n--23754--    --main-stacksize=16777216\r\n--23754--    --malloc-fill=0xab\r\n--23754--    --max-stackframe=4194304\r\n--23754--    --num-callers=50\r\n--23754--    --read-var-info=yes\r\n--23754--    --show-reachable=yes\r\n--23754--    --suppressions=.\/test.supp\r\n--23754--    --trace-children=yes\r\n--23754--    --track-origins=yes\r\n--23754--    -v\r\n--23754-- Contents of \/proc\/version:\r\n--23754--   Linux version 2.6.18-308.16.1.el5xen (mockbuild@builder10.centos.org) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-52)) #1 SMP Tue Oct 2 2\r\n2:50:05 EDT 2012\r\n--23754-- Arch and hwcaps: AMD64, amd64-cx16-rdtscp-sse3\r\n--23754-- Page sizes: currently 4096, max supported 4096\r\n--23754-- Valgrind library directory: \/tools\/sw\/prod\/centos-6.3-x86_64\/opt\/lib\/valgrind\r\n--23754-- Reading syms from \/work\/jlinoff\/work\/valgrind\/work\/cc\/test.exe\r\n--23754-- Reading syms from \/tools\/sw\/prod\/centos-6.3-x86_64\/opt\/lib\/valgrind\/memcheck-amd64-linux\r\n--23754--    object doesn't have a dynamic symbol table\r\n--23754-- warning: addVar: unknown size (ips)\r\n--23754-- warning: addVar: unknown size (kwds)\r\n--23754-- warning: addVar: unknown size (buf)\r\n--23754-- warning: addVar: unknown size (buf)\r\n--23754-- warning: addVar: unknown size (buf)\r\n--23754-- warning: addVar: unknown size (buf)\r\n--23754-- warning: addVar: unknown size (buf)\r\n--23754-- warning: addVar: unknown size (comps)\r\n--23754-- warning: addVar: unknown size (comps)\r\n--23754-- warning: addVar: unknown size (comps)\r\n--23754-- Reading syms from \/lib64\/ld-2.5.so\r\n--23754-- Scheduler: using generic scheduler lock implementation.\r\n--23754-- Reading suppressions file: .\/test.supp\r\n--23754-- Reading suppressions file: \/tools\/sw\/prod\/centos-6.3-x86_64\/opt\/lib\/valgrind\/default.supp\r\n==23754== embedded gdbserver: reading from \/tmp\/vgdb-pipe-from-vgdb-to-23754-by-jlinoff-on-jlinoff-lin\r\n==23754== embedded gdbserver: writing to   \/tmp\/vgdb-pipe-to-vgdb-from-23754-by-jlinoff-on-jlinoff-lin\r\n==23754== embedded gdbserver: shared mem   \/tmp\/vgdb-pipe-shared-mem-vgdb-23754-by-jlinoff-on-jlinoff-lin\r\n==23754== \r\n==23754== TO CONTROL THIS PROCESS USING vgdb (which you probably\r\n==23754== don't want to do, unless you know exactly what you're doing,\r\n==23754== or are doing some strange experiment):\r\n==23754==   \/tools\/sw\/prod\/centos-6.3-x86_64\/opt\/lib\/valgrind\/..\/..\/bin\/vgdb --pid=23754 ...command...\r\n==23754== \r\n==23754== TO DEBUG THIS PROCESS USING GDB: start GDB like this\r\n==23754==   \/path\/to\/gdb .\/test.exe\r\n==23754== and then give GDB the following command\r\n==23754==   target remote | \/tools\/sw\/prod\/centos-6.3-x86_64\/opt\/lib\/valgrind\/..\/..\/bin\/vgdb --pid=23754\r\n==23754== --pid is optional if only one valgrind process is running\r\n==23754== \r\n--23754-- REDIR: 0x3ecf614730 (strlen) redirected to 0x3804d051 (vgPlain_amd64_linux_REDIR_FOR_strlen)\r\n--23754-- Reading syms from \/tools\/sw\/prod\/centos-6.3-x86_64\/opt\/lib\/valgrind\/vgpreload_core-amd64-linux.so\r\n--23754-- Reading syms from \/tools\/sw\/prod\/centos-6.3-x86_64\/opt\/lib\/valgrind\/vgpreload_memcheck-amd64-linux.so\r\n--23754-- REDIR: 0x3ecf614550 (index) redirected to 0x4a08cf0 (index)\r\n--23754-- REDIR: 0x3ecf614700 (strcmp) redirected to 0x4a09630 (strcmp)\r\n--23754-- Reading syms from \/tools\/sw\/prod\/centos-5.5-x86_64\/opt\/gcc-4.9.1\/lib64\/libstdc++.so.6.0.20\r\n--23754-- Reading syms from \/lib64\/libm-2.5.so\r\n--23754-- Reading syms from \/tools\/sw\/prod\/centos-5.5-x86_64\/opt\/gcc-4.9.1\/lib64\/libgcc_s.so.1\r\n--23754-- Reading syms from \/lib64\/libc-2.5.so\r\n--23754-- REDIR: 0x3ecfa78cc0 (rindex) redirected to 0x4a08b40 (rindex)\r\n--23754-- REDIR: 0x3ecfa788d0 (strlen) redirected to 0x4a09050 (strlen)\r\n--23754-- REDIR: 0x3ecfa78350 (strcmp) redirected to 0x4a09590 (strcmp)\r\n--23754-- REDIR: 0x3ecfa79540 (bcmp) redirected to 0x4a0a730 (bcmp)\r\ntest\r\n--23754-- REDIR: 0x4c6d8e0 (operator new(unsigned long)) redirected to 0x4a0861e (operator new(unsigned long))\r\n--23754-- REDIR: 0x3ecfa7afc0 (memcpy) redirected to 0x4a09c20 (memcpy)\r\n--23754-- REDIR: 0x4c6bb40 (operator delete(void*)) redirected to 0x4a06fe3 (operator delete(void*))\r\n--23754-- REDIR: 0x3ecfa79b80 (memset) redirected to 0x4a0ac60 (memset)\r\n--23754-- REDIR: 0x3ecfa7a6b0 (mempcpy) redirected to 0x4a0b240 (mempcpy)\r\n   1 78\"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}\" \r\n   2 78\"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}\" \r\n   3 78\"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}\" \r\n   4 78\"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}\" \r\n   5 78\"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}\" \r\n   6 78\"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}\" \r\n   7 78\"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}\" \r\n   8 78\"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}\" \r\n   9 78\"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}\" \r\ndone\r\n--23754-- REDIR: 0x3ecfa715f0 (free) redirected to 0x4a073fd (free)\r\n==23754== \r\n==23754== HEAP SUMMARY:\r\n==23754==     in use at exit: 0 bytes in 0 blocks\r\n==23754==   total heap usage: 14 allocs, 14 frees, 1,175 bytes allocated\r\n==23754== \r\n==23754== All heap blocks were freed -- no leaks are possible\r\n==23754== \r\n==23754== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 7 from 7)\r\n--23754-- \r\n--23754-- used_suppression:      4 U1004-ARM-_dl_relocate_object \/tools\/sw\/prod\/centos-6.3-x86_64\/opt\/lib\/valgrind\/default.supp:1391\r\n--23754-- used_suppression:      3 ipp-suppress-conditional-jump1 .\/test.supp:4\r\n==23754== \r\n==23754== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 7 from 7)\r\n<\/pre>\n<p>Enjoy!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Valgrind must have fixed memory limits so that it can accurately track the memory allocations of the program under test. On 64 bit architectures it is limited to 64GB. This script will download, modify and build valgrind for larger memory configurations.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[5,16],"tags":[],"_links":{"self":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1549"}],"collection":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1549"}],"version-history":[{"count":6,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1549\/revisions"}],"predecessor-version":[{"id":1556,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1549\/revisions\/1556"}],"wp:attachment":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1549"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1549"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1549"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}