-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lli fails pointer comparison test #3415
Comments
Hrm. This has to do with lazy compilation. The generated assembly looks like this with -relocation-model=pic: _main: _test: Looking at -debug-only=jit dump with -relocation-model=pic JIT: Stub emitted at [0x207fff8] for function 'test' The disassembled code looks like this: After the lea, %ecx contains 0x02080050 which is the address of test. After the load, %edx is 0x2080044. However, the value in 0x2080044 is 0x0207fff8 which is the address of test's stub. |
The problem is at the time the address of "test" is taken, it has not been compiled. So it stored the address of its stub instead. |
I think the current solution would be something like this:
|
Alternatively, you could emit all function pointers as pointers to the function's stub. The disadvantage of compiling a function whenever its address is taken is that in a C++ program all the entries all vtable would have to be compiled before execution began. Some C programs also contain statically initialized lists of functions that may or may not be called at runtime. The disadvantage of emitting function pointers as pointers to stubs is that it increases the overhead per function call. |
Right. That's an acceptable solution for now. Thanks. |
Thanks! |
Remove redundant ternary operator (NFC)
Extended Description
From Prakash Prabhu:
#include<stdio.h>
#include<stdlib.h>
void test();
void (*funcPtr)();
int main(int argc, char **argv) {
funcPtr = test;
test();
}
void test() {
if(funcPtr == test) {
printf("OK!\n");
} else {
fprintf(stderr, "Bad!\n");
exit(1);
}
}
$ llvm-gcc -emit-llvm -o FPtrEqTest.bc -c FPtrEqTest.c
$ llc -f FPtrEqTest.bc
$ gcc -o FPtrEqTest FPtrEqTest.s
$ ./FPtrEqTest
OK!
$ lli FPtrEqTest.bc
Bad!
The text was updated successfully, but these errors were encountered: