function failing to run in Jit

Is there any reason this generated code won't run in the Jit?
I've pretty much got everything else working for my front end
which all runs fin in the Jit but I can't get global arrays to work.

; ModuleID = 'test'
target datalayout =
"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
target triple = "i686-pc-linux-gnu"

@MyArray = external global [1000 x i32]

define i32 @foo(i32 %a, i32 %b) {
Entry:
  %mul = mul i32 %b, %a
  %ptr = getelementptr inbounds [1000 x i32]* @MyArray, i32 0, i32 %a
  store i32 %mul, i32* %ptr, align 4
  ret i32 %a
}

Comparing it to the web compiled c equivalent I can't see any relevant
difference.

; ModuleID = '/tmp/webcompile/_925_0.bc'
target datalayout =
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
target triple = "x86_64-linux-gnu"

@array = common global [1000 x i32] zeroinitializer, align 32 ; <[1000 x
i32]*> [#uses=1]

define i32 @foo(i32 %a, i32 %b) nounwind {
entry:
  %0 = mul nsw i32 %b, %a ; <i32> [#uses=1]
  %1 = sext i32 %a to i64 ; <i64> [#uses=1]
  %2 = getelementptr inbounds [1000 x i32]* @array, i64 0, i64 %1 ;
<i32*> [#uses=1]
  store i32 %0, i32* %2, align 4
  ret i32 %a
}

Try using i64 indices with GEP

That doesn't work either.

%1 = sext i32 %a to i64
%2 = getelementptr inbounds [1000 x i32]* @array, i64 0, i64 %1 ;

Hi Andrew,

@MyArray = external global [1000 x i32]

since MyArray is declared as being defined somewhere else (extern) you need to
link with something that actually defines @MyArray.

@array = common global [1000 x i32] zeroinitializer, align 32 ;<[1000 x
i32]*> [#uses=1]

Here MyArray is being defined, with an initial value that is all zero. Thus
there is no need to link with something that provides a definition.

Ciao, Duncan.