[LLVMdev] LLVM Interpreter & QSort

anghel andreea acnods at yahoo.com
Wed Feb 20 10:08:16 PST 2013


Hi, 

I am trying to run an LLVM analysis on a C++ program that calls 
qsort(), using the LLVM interpreter (lli --force-interpreter). The code 
is the qsort_large.c file in the MiBench benchmark suite. If I comment 
the qsort() call, the execution works fine. If I uncomment the qsort() 
call, I run into a segmentation fault error as follows: 

0  lli             0x0000000000d35c6f 
1  lli             0x0000000000d36199 
2  libpthread.so.0 0x0000000004e41cb0 
3  libpthread.so.0 0x000000000604e4d2 

If I run valgrind, the output is the following: 

vex amd64->IR: unhandled instruction bytes: 0x37 0x1 0x0 0x0 0x0 0x0 0x2 0x0 
==9222== valgrind: Unrecognised instruction at address 0x604e4d2. 
==9222==    at 0x604E4D2: ??? 
==9222==    by 0x5CA781B: msort_with_tmp.part.0 (msort.c:106) 
==9222==    by 0x5CA75A0: msort_with_tmp.part.0 (msort.c:46) 
==9222==    by 0x5CA75A0: msort_with_tmp.part.0 (msort.c:46) 
==9222==    by 0x5CA75A0: msort_with_tmp.part.0 (msort.c:46) 
==9222==    by 0x5CA75A0: msort_with_tmp.part.0 (msort.c:46) 
==9222==    by 0x5CA75A0: msort_with_tmp.part.0 (msort.c:46) 
==9222==    by 0x5CA75A0: msort_with_tmp.part.0 (msort.c:46) 
==9222==    by 0x5CA75A0: msort_with_tmp.part.0 (msort.c:46) 
==9222==    by 0x5CA75A0: msort_with_tmp.part.0 (msort.c:46) 
==9222==    by 0x5CA75A0: msort_with_tmp.part.0 (msort.c:46) 
==9222==    by 0x5CA75A0: msort_with_tmp.part.0 (msort.c:46) 
==9222==    by 0x5CA75A0: msort_with_tmp.part.0 (msort.c:46) 
==9222==    by 0x5CA7ABA: __GI_qsort_r.constprop.1 (msort.c:46) 
==9222==    by 0x5054E87: ffi_call_unix64 (in /usr/local/lib/libffi.so.6.0.1) 
==9222==    by 0x505479C: ffi_call (in /usr/local/lib/libffi.so.6.0.1) 
==9222==    by 0x8604AE: 
llvm::Interpreter::callExternalFunction(llvm::Function*, 
std::vector<llvm::GenericValue, 
std::allocator<llvm::GenericValue> > const&) (in 
/usr/local/bin/lli) 
==9222==    by 0x85B49A: 
llvm::Interpreter::callFunction(llvm::Function*, 
std::vector<llvm::GenericValue, 
std::allocator<llvm::GenericValue> > const&) (in 
/usr/local/bin/lli) 
==9222==    by 0x85B952: llvm::Interpreter::visitCallSite(llvm::CallSite) (in /usr/local/bin/lli) 
==9222==    by 0x85D638: ??? (in /usr/local/bin/lli) 
==9222==    by 0x85BED8: llvm::Interpreter::run() (in /usr/local/bin/lli) 
==9222==    by 0x85045A: 
llvm::Interpreter::runFunction(llvm::Function*, 
std::vector<llvm::GenericValue, 
std::allocator<llvm::GenericValue> > const&) (in 
/usr/local/bin/lli) 
==9222==    by 0xB93781: 
llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, 
std::vector<std::string, std::allocator<std::string> > 
const&, char const* const*) (in /usr/local/bin/lli) 
==9222==    by 0x4FE861: main (in /usr/local/bin/lli) 

This seems to suggest that the problem is the call to the comparator function within qsort(). 

I have the following system configuration: 
  - Ubuntu 12.04 
  - LLVM v.3.2 
  - Clang v.3.2 
  - LibFFI v.3.0.12 
  - Libc v.2.15 

Do you happen to know if this behavior is normal? 
Does LLVM 3.2 have support for function pointers? 

Thank you in advance. 
Simon 




More information about the llvm-dev mailing list