Hello,
I have implemented a simple 2-stage bootloader. My second stage bootloader is loaded at 0x500 and loads an executable ELF-file from there. This worked fine at the start, but now my kernel got bigger and I've reached the point where it overwrites my stage 2 bootloader (the code that is loading the ELF-file). When I inspect the elf binary with readelf -S, I can see the sections:
For clarity's sake: the problem is the .symtab, as it wants to be loaded at 0x0 to 0x5c0 (while my bootloader is at 0x500), but the sections .strtab, .symtab and .shstrtab are all potential problems, as they might grow into the memory > 0x500 that I need for my second stage bootloader.
The behaviour of my second stage bootloader is correct. However, I was convinced the linker should only allocate sections in the memory > 1MB. I've grabbed the linker script from here(without really understanding it in the first place, so maybe this will finally teach me that those things always backfire ).
How can I make sure the .strtab, .symtab and .shstrtab sections aren't loaded to the memory where my bootloader is?
Loading an ELF-executable
Re: Loading an ELF-executable
Only those sections with the SHF_ALLOC flag ('A' in the readelf output) should actually be loaded. As you can see, these all have sensible load addresses (> 1MiB).
However, the best way to load executables is to use the program headers instead (readelf -l will list these).
Regards,
John.
However, the best way to load executables is to use the program headers instead (readelf -l will list these).
Regards,
John.
Re: Loading an ELF-executable
Makes a lot of sense! Thank you sir.
Edit: I'm experiencing some odd troubles (my interrupt handler is executed but, for example, my clearscreen routine doesn't work and clears only the first character of the screen) when I load only the memory specified in the program headers. Loading only the sections where the allocation flag is set works fine.
Edit: I'm experiencing some odd troubles (my interrupt handler is executed but, for example, my clearscreen routine doesn't work and clears only the first character of the screen) when I load only the memory specified in the program headers. Loading only the sections where the allocation flag is set works fine.
Re: Loading an ELF-executable
Sections become segments after the linking process has been performed. *Never* look at the sections for program loading purposes. Use the program headers and look at the LOAD segment entries instead.
Re: Loading an ELF-executable
Thank you again, sortie! Everything finally works again. My code that reads the program headers was bugged (I used the header size for section headers instead of the size for program headers) so that the .data segment wasn't loaded correctly.