0

I wrote the following code:

#include "llvm/IR/Instructions.h"
#include "llvm/IR/Metadata.h"

using namespace llvm;

int main() {

     int a=0,b=0,c=0;
     Instruction *I;
     LLVMContext& C = I->getContext();
     MDNode* N = MDNode::get(C, MDString::get(C, "my md string content"));
     I->setMetadata("my.md.name", N);

    if(a>b){
       c=a;
       cast<MDString>(I->getMetadata("my.md.name")->getOperand(0))->getString();
    }
    else
       c=b;

    return c;
}

When I try to run this code with lli, it generates the following error:

"LLVM ERROR: unable to find external function '___ZXXcONTEXT4LS' that can't be resolved!"

Can you help me solve this problem? I'm aware about the LIBFFI project. Unfortunately, LIBFFI still has problems in running on windows platform. Is there any other solution to this?

1 Answer 1

1

There are at least two serious problems here:

  1. I is not allocated before you redirect it (this can result in a segmentation fault).
  2. What do you mean you "run this with lli"? lli should be used to interpret/JIT LLVM IR. What you have shown above is likely a C++ program that has to be linked with LLVM, and these are completely different things.

Did you try to go through the LLVM tutorial? It's highly recommended.

Sign up to request clarification or add additional context in comments.

2 Comments

I'll go through this tutorial. Thank you. But do you know the reason for the external function error?
@ConsistentProgrammer: you'll need to provide more details first - what does it mean that you run that code with lli? That code was not meant to be run with lli. It's C++ code that's supposed to be linked with LLVM and use it as a library.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.