On ppc32/64 we don't have a reliable way to detect function entries
and exits at the moment.  So disable stack array bounds checking for
ppc32/64 platforms.  Also (unnecessarily) disables global array bounds
checking on those platforms.

Add a flag --enable-sg-checks=no|yes [yes] so that stack and global
checking can be optionally disabled on any platform.  This is useful
because stack and global checking is much more expensive than heap
checking, and so it may be desirable to disable it.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@8686 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/exp-ptrcheck/h_main.c b/exp-ptrcheck/h_main.c
index 426bdbf..db25fc7 100644
--- a/exp-ptrcheck/h_main.c
+++ b/exp-ptrcheck/h_main.c
@@ -2654,9 +2654,9 @@
 static inline
 void check_load_or_store(Bool is_write, Addr m, UWord sz, Seg* mptr_vseg)
 {
-   if (h_clo_lossage_check) {
-     tl_assert(0);
 #if 0
+   tl_assert(0);
+   if (h_clo_lossage_check) {
       Seg* seg;
       stats__tot_mem_refs++;
       if (ISList__findI0( seglist, (Addr)m, &seg )) {
@@ -2693,8 +2693,8 @@
             }
          }
       }
-#endif
    } /* clo_lossage_check */
+#endif
 
 #  if SC_SEGS
    checkSeg(mptr_vseg);
@@ -4732,6 +4732,7 @@
                    stats__segs_allocd, stats__segs_recycled);
    }
 
+#if 0
    if (h_clo_lossage_check) {
       VG_(message)(Vg_UserMsg, "");
       VG_(message)(Vg_UserMsg, "%12lld total memory references",
@@ -4746,6 +4747,7 @@
    } else {
       tl_assert( 0 == VG_(OSetGen_Size)(lossage) );
    }
+#endif
 }
 
 
diff --git a/exp-ptrcheck/pc_common.c b/exp-ptrcheck/pc_common.c
index a08f0f1..26c8127 100644
--- a/exp-ptrcheck/pc_common.c
+++ b/exp-ptrcheck/pc_common.c
@@ -58,13 +58,15 @@
 //                                                          //
 //////////////////////////////////////////////////////////////
 
-Bool h_clo_partial_loads_ok = True;   /* user visible */
-Bool h_clo_lossage_check    = False;  /* dev flag only */
+Bool h_clo_partial_loads_ok  = True;   /* user visible */
+/* Bool h_clo_lossage_check     = False; */ /* dev flag only */
+Bool sg_clo_enable_sg_checks = True;   /* user visible */
 
 Bool pc_process_cmd_line_options(Char* arg)
 {
         VG_BOOL_CLO(arg, "--partial-loads-ok", h_clo_partial_loads_ok)
-   else VG_BOOL_CLO(arg, "--lossage-check",    h_clo_lossage_check)
+   /* else VG_BOOL_CLO(arg, "--lossage-check",    h_clo_lossage_check) */
+   else VG_BOOL_CLO(arg, "--enable-sg-checks", sg_clo_enable_sg_checks)
    else
       return VG_(replacement_malloc_process_cmd_line_option)(arg);
 
@@ -74,16 +76,19 @@
 void pc_print_usage(void)
 {
    VG_(printf)(
-   "    --partial-loads-ok=no|yes same as for Memcheck [yes]\n"
+   "    --partial-loads-ok=no|yes  same as for Memcheck [yes]\n"
+   "    --enable-sg-checks=no|yes  enable stack & global array checking? [yes]\n"
    );
    VG_(replacement_malloc_print_usage)();
 }
 
 void pc_print_debug_usage(void)
 {
+  /*
    VG_(printf)(
-   "    --lossage-check=no|yes gather stats for quality control [no]\n"
+   "    --lossage-check=no|yes    gather stats for quality control [no]\n"
    );
+  */
    VG_(replacement_malloc_print_debug_usage)();
 }
 
diff --git a/exp-ptrcheck/pc_common.h b/exp-ptrcheck/pc_common.h
index ac4e4d4..77bab6e 100644
--- a/exp-ptrcheck/pc_common.h
+++ b/exp-ptrcheck/pc_common.h
@@ -58,7 +58,8 @@
 void pc_print_extra_suppression_info ( Error* err );
 
 extern Bool h_clo_partial_loads_ok;
-extern Bool h_clo_lossage_check;
+/* extern Bool h_clo_lossage_check; */
+extern Bool sg_clo_enable_sg_checks;
 
 Bool pc_process_cmd_line_options(Char* arg);
 void pc_print_usage(void);
diff --git a/exp-ptrcheck/pc_main.c b/exp-ptrcheck/pc_main.c
index 1492de3..3183f99 100644
--- a/exp-ptrcheck/pc_main.c
+++ b/exp-ptrcheck/pc_main.c
@@ -37,11 +37,11 @@
 
 #include "pub_tool_basics.h"
 #include "pub_tool_libcassert.h"
+#include "pub_tool_libcprint.h"
 #include "pub_tool_execontext.h"
 #include "pub_tool_tooliface.h"
 #include "pub_tool_options.h"
 
-//#include "h_list.h"      // Seg
 #include "sg_main.h"
 #include "pc_common.h"
 #include "h_main.h"
@@ -125,6 +125,21 @@
 {
    h_post_clo_init();
    sg_post_clo_init();
+#  if defined(VGA_x86) || defined(VGA_amd64)
+   /* nothing */
+#  elif defined(VGA_ppc32) || defined(VGA_ppc64)
+   if (VG_(clo_verbosity) >= 1 && sg_clo_enable_sg_checks) {
+      VG_(message)(Vg_UserMsg, 
+         "WARNING: exp-ptrcheck on ppc32/ppc64 platforms: stack and global array");
+      VG_(message)(Vg_UserMsg, 
+         "WARNING: checking is not currently supported.  Only heap checking is");
+      VG_(message)(Vg_UserMsg, 
+         "WARNING: supported.  Disabling s/g checks (like --enable-sg-checks=no).");
+   }
+   sg_clo_enable_sg_checks = False;
+#  else
+#    error "Unsupported architecture"
+#  endif
 }
 
 static void pc_pre_clo_init(void)
diff --git a/exp-ptrcheck/sg_main.c b/exp-ptrcheck/sg_main.c
index 27a703e..e5c82bd 100644
--- a/exp-ptrcheck/sg_main.c
+++ b/exp-ptrcheck/sg_main.c
@@ -2107,6 +2107,9 @@
                             VexGuestLayout* layout,
                             IRType gWordTy, IRType hWordTy )
 {
+   if (!sg_clo_enable_sg_checks)
+      return;
+
    tl_assert(st);
    tl_assert(isFlatIRStmt(st));
    switch (st->tag) {
@@ -2212,6 +2215,9 @@
                                 VexGuestLayout* layout,
                                 IRType gWordTy, IRType hWordTy )
 {
+   if (!sg_clo_enable_sg_checks)
+      return;
+
    if (jumpkind == Ijk_Call) {
       // Assumes x86 or amd64
       IRTemp   sp_post_call_insn, fp_post_call_insn;