[BUG x2] getPointerToGlobal is broken

Hi,

Yes, I know getPointerToGlobal is deprecated, but it's the only
interface we have in the OCaml world. So this is an investigation to
see if the newer interfaces, specifically getGlobalValueAddress,
suffers from the same problems. The first bug is fun; if you have emit
two anonymous functions, and pass gptg their function objects to get
the value via Ctypes, the second gtpg grabs the value of the first
function:

diff --git a/test/Bindings/OCaml/executionengine.ml
b/test/Bindings/OCaml/executionengine.ml
index 893f988..6e4a5ad 100644
--- a/test/Bindings/OCaml/executionengine.ml
+++ b/test/Bindings/OCaml/executionengine.ml
@@ -42,6 +42,22 @@ let define_plus m =
   ignore (build_ret add b);
   fn

+let define_anon1 m =
+ let fn = define_function "" (function_type i32_type [| i32_type;
+ i32_type |]) m in
+ let b = builder_at_end (global_context ()) (entry_block fn) in
+ let add = build_add (param fn 0) (param fn 1) "sum" b in
+ ignore (build_ret add b);
+ fn

Never mind; I'm just rediscovering bugs, it seems. From
unittests/ExecutionEngine/MCJIT/MCJITTest.cpp:

// FIXME: This case fails due to a bug with getPointerToGlobal().
// The bug is due to MCJIT not having an implementation of getPointerToGlobal()
// which results in falling back on the ExecutionEngine implementation that
// allocates a new memory block for the global instead of using the same
// global variable that is emitted by MCJIT. Hence, the pointer (gvPtr below)
// has the correct initial value, but updates to the real global (accessed by
// JITted code) are not propagated. Instead, getPointerToGlobal() should return
// a pointer into the loaded ObjectImage to reference the emitted global.

The OCaml bindings need to chuck gptg and replace it with a wrapper to
a more suitable function.