elf64 calling loaded function
Posted: Sat Mar 05, 2022 1:58 am
Hi. I'm currently working on my elf loader for .o files.
in testfile.c
objdump -d testfile.o
Then, in my program, I load testfile.o.
Then, I find entry_func's address (lookup the symbol).
then the output ->
which matches the disassembly.
finally ->
Then I get a segfault without 'called' being printed.
Should this not work? seems the .o file is parsed and loaded correctly as of the memory dump.
Do I need to do something prior to calling fp() (set up certain registers or somesuch)?
in testfile.c
Code: Select all
void entry_func()
{
return;
}
Code: Select all
testfile.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <entry_func>:
0: 55 push %rbp
1: 48 89 e5 mov %rsp,%rbp
4: 90 nop
5: 5d pop %rbp
6: c3 retq
Then, I find entry_func's address (lookup the symbol).
Code: Select all
char *store = find_symbol("entry_func");
for (int x = 0; x < 7; ++x) printf("%x ", store[x]);
printf("\n");
Code: Select all
55 48 89 e5 90 5d c3
finally ->
Code: Select all
void (*fp)();
fp = store;
printf("calling\n");
fp();
printf("called\n");
Should this not work? seems the .o file is parsed and loaded correctly as of the memory dump.
Do I need to do something prior to calling fp() (set up certain registers or somesuch)?