question on relocation of drivers and modules
Posted: Tue Feb 17, 2015 4:08 pm
From reading http://wiki.osdev.org/ELF#Relocation tutorial it seems that relocation is useful when loading drivers and modules. According to the tutorial:
Point 4 of this outline seems to imply that the drivers has been loaded into physical memory (RAM) but hasn't been relocated with the kernel's address space. If drivers/modules has already been loaded into RAM what is the point of relocating? Why not just link and relocate all the drivers/module with kernel into one executable image during compile time? How does relocating when needed in this case save time if drivers/modules have to be loaded into ram anyways?The basic outline of things you need to do for relocation:
1. Check the object file header (it has to be ELF, not PE, for example)
2. Get a load address (eg. all drivers start at 0xA0000000, need some method of keeping track of driver locations)
3. Allocate enough space for all program sections (ST_PROGBITS)
4. Copy from the image in RAM to the allocated space
5. Go through all sections resolving external references against the kernel symbol table
If all succeeded, you can use the "e_entry" field of the header as the offset from the load address to call the entry point (if one was specified), or do a symbol lookup, or just return a success error code.