At startup, now tests if program is statically linked.  Bails with a useful
message if so.  If anyone thinks this will break anything, please yell.

Updated FAQ #5 correspondingly, added info on how to combine static and dynamic
libraries.

MERGE TO STABLE(?)


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1831 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/FAQ.txt b/FAQ.txt
index 3469afc..b4d9517 100644
--- a/FAQ.txt
+++ b/FAQ.txt
@@ -87,18 +87,17 @@
 Q5. I try running "valgrind my_program", but my_program runs normally,
     and Valgrind doesn't emit any output at all.
 
-A5. Is my_program statically linked?  Valgrind doesn't work with
-    statically linked binaries.  my_program must rely on at least one 
-    shared object.  To determine if a my_program is statically linked, 
-    run:
+A5. This should no longer happen, as a check for this takes place
+    when Valgrind starts up.
 
-      ldd my_program
+    However, Valgrind still doesn't work with programs that are entirely
+    statically linked.  If you still want static linking, you can ask 
+    gcc to link certain libraries statically.  Try the following options:
 
-    It will show what shared objects my_program relies on, or say:
+        -Wl,-Bstatic -lmyLibrary1 -lotherLibrary -Wl,-Bdynamic
 
-      not a dynamic executable
-
-    if my_program is statically linked.
+    Just make sure you end with -Wl,-Bdynamic so that libc is dynamically
+    linked.
 
 -----------------------------------------------------------------
 
diff --git a/coregrind/valgrind.in b/coregrind/valgrind.in
index bd1b8da..d8edc05 100755
--- a/coregrind/valgrind.in
+++ b/coregrind/valgrind.in
@@ -110,6 +110,19 @@
    export LD_ASSUME_KERNEL 
 fi
 
+# Ensure the program isn't statically linked.
+if [ $# != 0 ] ; then
+   which_prog="`which $1`"
+   case `ldd "$which_prog"` in
+   *"not a dynamic executable"*)
+     echo "\`$which_prog' is statically linked"
+     echo "Valgrind only works on dynamically linked executables;  your"
+     echo "program must rely on at least one shared object for Valgrind"
+     echo "to work with it.  Read FAQ #5 for more information."
+     exit 1 ;;
+   esac
+fi
+   
 # A bit subtle.  The LD_PRELOAD added entry must be absolute
 # and not depend on LD_LIBRARY_PATH.  This is so that we can
 # mess with LD_LIBRARY_PATH for child processes, which makes