[LLVMdev] Problem executing code with lli...

Nick Lewycky nicholas at mxc.ca
Thu Oct 30 19:38:45 PDT 2008


Karhu, Abhinav R wrote:
> Hi all,
> I am facing new problem with lli now. I am having a sample code in which I am doing malloc for two variables. If I compile the code with normal gcc the program runs without any warning of any sorts. If I compile the program to convert it into a bytecode file and then run it through lli it segfaults and the program aborts.

It works for me:

   $ cat twomalloc.c
   #include <stdio.h>
   #include <stdlib.h>

   int main(void) {
     char *x, *y;
     x = malloc(10);
     y = malloc(11);
     printf("%x\n", x);
     printf("%x\n", y);
   }
   $ llvm-gcc -O2 twomalloc.c -c -o twomalloc.bc -emit-llvm
   $ lli twomalloc.bc
   89e9690
   89e9508

We'll need more detail. What platform are you running on? What source 
code did you put in? Does it only fail in lli or when compiled through 
llc too? Does it compile cleanly with -Wall -pedantic? Is the GCC-built 
version valgrind-clean?

  This is the stack trace after execution.
> lli((anonymous namespace)::PrintStackTrace()+0x1f)[0x67cc7f]
> lli((anonymous namespace)::SignalHandler(int)+0x172)[0x67cf72]
> /lib64/tls/libc.so.6[0x2a95e4b300]
> lli(llvm::ExecutionEngine::LoadValueFromMemory(llvm::GenericValue*, llvm::Type const*)+0x182)[0x4be4f2]
> lli(llvm::InstVisitor<llvm::Interpreter, void>::visit(llvm::Instruction&)+0x1fe)[0x4b648e]
> lli(llvm::Interpreter::run()+0x2b)[0x4b179b]
> lli(llvm::Interpreter::runFunction(llvm::Function*, std::vector<llvm::GenericValue, std::allocator<llvm::GenericValue> > const&)+0xac)[0x4b490c]
> lli(llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, char const* const*)+0xa5)[0x4bf295]
> lli(main+0x170)[0x4aaac0]
> /lib64/tls/libc.so.6(__libc_start_main+0xdb)[0x2a95e3940b]
> lli(__gxx_personality_v0+0xda)[0x4aa87a]
> Segmentation fault
> 
> I am also testing to see if the malloc was successful or not and it shows that malloc was successful. 
> 
> The part where is static memory is allocated runs fine(I am putting a print for that value). Why is the program failing in LoadValueFromMemory?
> 
> Please some light on this issue.

There's one other thing you can try. bugpoint can actually take a .bc 
file and split it into two pieces, run one through the C Backend, 
compile that with GCC, and run the other half through lli while telling 
lli to load the CBE part.

It will then use a binary search to find the smallest .bc it can which 
reproduces a crash. Note that I said a crash, as in any crash, not 
necessarily the crash you wanted it to reduce. If that succeeds, it will 
probably help shed some light on the problem.

Nick Lewycky




More information about the llvm-dev mailing list