[cfe-dev] Call external (non-JIT) function from JIT

Frank Fuchs fk.fuchs at googlemail.com
Tue Jul 13 13:56:28 PDT 2010

> On Tue, Jul 13, 2010 at 12:46 PM, Frank Fuchs <fk.fuchs at googlemail.com> wrote:
>> Here's the error message:
>> main.cpp:5:4: error: use of undeclared identifier 'known'
>>       i=known(i);
>>         ^
>> 1 error generated.
> Right... the frontend has no clue what mapping you're doing in the backend.
>> also defining "known" as: extern "C" int known(int);    does not solve the issue, the error is then:
>> LLVM ERROR: Program used external function 'known' which could not be resolved!
> I have a feeling you're not actually adding a mapping for "known"; try
> dumping the module.
> -Eli

Ok here is the output of Mod->dump() called right before runAsFunctionMain(...). I am referring to the example with the extern "C" int known(int) declaration!  

; ModuleID = 'test.cpp'
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-apple-darwin10.0.0"

@.str = private constant [16 x i8] c"Ext. CALL %d \0A\0A\00" ; <[16 x i8]*> [#uses=1]

define i32 @main() ssp {
 %retval = alloca i32, align 4                   ; <i32*> [#uses=1]
 %i = alloca i32, align 4                        ; <i32*> [#uses=4]
 store i32 0, i32* %retval
 store i32 1, i32* %i
 %tmp = load i32* %i                             ; <i32> [#uses=1]
 %call = call i32 @known(i32 %tmp)               ; <i32> [#uses=1]
 store i32 %call, i32* %i
 %tmp1 = load i32* %i                            ; <i32> [#uses=1]
 %call2 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([16 x i8]* @.str, i32 0, i32 0), i32 %tmp1) ; <i32> [#uses=0]
 ret i32 0

declare i32 @known(i32)

declare i32 @printf(i8*, ...)

declare i32 @known1(i32)

I'm not sure how to interpret this ... but the "known1" seems to be the mapped function, while "known" is the extern "C" declared one (checked that by renaming "known" in test.cpp). ... End of knowledge :)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100713/094b033f/attachment.html>

More information about the cfe-dev mailing list