I am writing an operating system. I currently compile my kernel to a file called kernel.elf
, and it's symbol table contains functions such as tty_printf
and it's address in memory.
I wrote an ELF loader to load a separate program from disk, and I want to be able to call kernel functions from this program.
The only way I've been able to do this is declaring a function pointer with the function address that I get from reading the symbol table from my kernel:
void (*tty_printf)(const char*, ...) = 0x9E80;
void main() {
tty_printf("Hello, World!
");
asm ("cli; hlt");
}
I know this entire idea is not ideal, and I should just be using system calls, but because it is just a small hobby project and some other reasons, I don't want to bother with entering ring 3 right now.
So, I want to know if there's a way that I can just declare the function, like this
void tty_printf(const char*, ...);
and have the linker resolve it's address based on my kernel.elf
symbol table, so I don't have to manually replace this and every other function's address every time I make a change to my kernel.
Thank you.
question from:
https://stackoverflow.com/questions/65913717/use-another-elf-files-symbol-table-for-symbol-resolution-when-linking 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…