Karthik Bhat
2012-Nov-15 07:44 UTC
[LLVMdev] Unable to call a function in GDB when build with -fPIE
Hi All, I compiled the following code on my linux PC using clang with PIE option- struct struct4 {char a; char b; char c; char d; }; struct struct4 foo4 = {'a','2','c','4'}; struct struct4 fun4() { return foo4; } int main() { fun4(); return 0; }> clang -g -fPIE structs.cIn GDB session when i call p/c fun4() i get something like below- (gdb) p/c fun4() Cannot access memory at address 0x34633261 Disassemble of the code is as follows - (gdb) disassemble Dump of assembler code for function fun4: 0x080483e0 <+0>: call 0x80483e5 <fun4+5> 0x080483e5 <+5>: pop %eax 0x080483e6 <+6>: add $0x1c0f,%eax 0x080483ec <+12>: mov 0x4(%esp),%ecx 0x080483f0 <+16>: mov -0x8(%eax),%eax 0x080483f6 <+22>: mov (%eax),%eax => 0x080483f8 <+24>: mov %eax,(%ecx) 0x080483fa <+26>: ret $0x4 End of assembler dump. (gdb) i r eax 0x34633261 878916193 ecx 0xbffff128 -1073745624 edx 0xbffff164 -1073745564 ebx 0x8049ff4 134520820 esp 0xbffff11c 0xbffff11c ebp 0xbffff138 0xbffff138 esi 0x0 0 edi 0x0 0 eip 0x80483f8 0x80483f8 <fun4+24> eflags 0x212 [ AF IF ] cs 0x73 115 ss 0x7b 123 ds 0x7b 123 es 0x7b 123 fs 0x0 0 gs 0x33 51 Seems value in EAX register is getting corrupted in this case. Could anyone guide me how i can fix this issue. Regards Karthik