[llvm-dev] Calling virtual "ELF" functions - BC code

via llvm-dev llvm-dev at lists.llvm.org
Mon Feb 5 13:19:17 PST 2018


Hello everyone,

I encountered a strange behaviour which I can't explain.

I'm developing an application under Windows 7 64bit. This application is using the LLVM library to load and resolve BC files generated with clang. Then the program picks some functions from the module and executes them. That's the theory - but now it's getting strange.

The BC files are compiled for 64bit windows but have the ELF abi (the application has PECOFF). When I now pick a normal function and call them, everything is fine. But then I decided to call a function which is virtual - the program and the ELF file are both sharing the same interface for this with pure virtual functions. When I now call a virtual function, then I will reach the correct function - but the return value will be faulty, which then corruptes the stack and it crashes. But the this pointer - when the function was called - is correct.
What's more stranger: I casted the address of the virtual function "down" to a normal function, but with the same return value. When I call this construct, then the return value is correct!

So wow! Isn't it possible to call virtual ELF functions from a "PECOFF code"?

Kind regards
fenir50 (Sorry for hiding my name)


More information about the llvm-dev mailing list