Baris Aktemur
2013-Jan-05 14:58 UTC
[LLVMdev] RuntimeDyld bug in resolving addresses with offset?
Hi, I believe I came across a bug in RuntimeDyld. I have the following piece of C code (attached as rtdyldbug.c): double numbers[5] = {33, 34, 35, 36, 37}; void foo(double val, double other[]) { other[2] += val * numbers[4]; } I adapted llvm-rtdyld.cpp to load the .o file of the code above, get a pointer to foo, and invoke it (whole thing is attached as myrtdyld.cpp): typedef void(*myFun)(double, double*); int main() { std::string funName = "_foo"; std::string fileName = "rtdyldbug.o"; myFun fptr = (myFun)getFunctionPointer(funName, fileName); double w[5] = {0, 0, 0, 0, 0}; fptr(4, w); printf("%f \n", w[2]); return 0; } The printed result should be 148, but its 132. The instruction which reads numbers[4] is mulsd _numbers+0x00000020(%rip),%xmm0 When I did debugging at the assembly level, I found that the offset 0x20 is ignored. The resolved address points to numbers[0] instead of numbers[4]. I compiled the attached rtdyldbug.c as "clang -c -o rtdyldbug.o rtdyldbug.c". I compiled myrtdyld.cpp as "clang++ -o myrtdyld myrtdyld.cpp `llvm-config --cxxflags --libs all --ldflags`". I did the test on Mac OS with clang version 3.3 (trunk 170267). Any insights/comments/bug fixes would be appreciated. -Baris Aktemur -------------- next part -------------- A non-text attachment was scrubbed... Name: rtdyldbug.c Type: application/octet-stream Size: 119 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130105/88e547f6/attachment.obj> -------------- next part -------------- A non-text attachment was scrubbed... Name: myrtdyld.cpp Type: application/octet-stream Size: 5657 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130105/88e547f6/attachment-0001.obj>
Possibly Parallel Threads
- [LLVMdev] Dynamically loading native code generated from LLVM IR
- [LLVMdev] Dynamically loading native code generated from LLVM IR
- [LLVMdev] Dynamically loading native code generated from LLVM IR
- [LLVMdev] Dynamically loading native code generated from LLVM IR
- [LLVMdev] Programmatically converting LLVM IR to native code