Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
353 views
in Technique[技术] by (71.8m points)

c - Use another ELF file's symbol table for symbol resolution when linking

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...