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. 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. Thanks -- Abhinav Karhu MS Computer Science Georgia Institute of Technology
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. 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.First of all, you also sent this to me personally. Rest assured I'm (obviously) on this list and if I see a problem I think I can help with I will reply here. No need to mail me personally. Now then, I think a problem like this is probably not easy to solve from just a stack trace. Try reducing your program to the minimum that will still produce the crash[1] and (assuming you still can't see any obvious problems in it by yourself at that point) then putting it (in .ll or .bc form) in a problem report[2] (through http://llvm.org/bugs/) or (if it's small) pasting it (in .ll form) into a post to LLVM-Dev. [1]: I gather "bugpoint" may be of use in these situations. [2]: If you go the problem report route, try using the search functionality first to see if there's already a report by someone else on the same issue.
I bet this is due to one of the followings: 1) a bug in your code, 2) mismatched llvm-gcc and lli, 3) none of the above. :-) You ought to build a debug llvm and run lli under gdb to understand why LoadValueFromMemory is crashing. Evan On Oct 29, 2008, at 7:21 PM, 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. 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. > > Thanks > > > -- > Abhinav Karhu > MS Computer Science > Georgia Institute of Technology > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
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