Show
Ignore:
Timestamp:
05/05/08 16:09:04 (7 months ago)
Author:
mwhitworth
Message:

Make detection and resolving of relocation sections more flexible.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Whitix/branches/hybrid/kernel/module.c

    r421 r425  
    7474} 
    7575 
    76 int ModuleSymbolResolve(struct Module* module) 
     76int ModuleSymbolResolve(struct Module* module, int sec) 
    7777{ 
    7878        int i; 
    7979        struct ElfReloc* reloc; 
     80        struct ElfReloc* relTable=(struct ElfReloc*)(module->loadAddr+module->sectionHeaders[sec].shOffset); 
     81        DWORD relSize=module->sectionHeaders[sec].shSize/sizeof(struct ElfReloc); 
    8082 
    81         for (i=0; i<module->relSize/(sizeof(struct ElfReloc)); i++) 
     83        for (i=0; i<relSize; i++) 
    8284        { 
    83                 reloc=&module->relTable[i]; 
     85                reloc=&relTable[i]; 
    8486 
    85                 unsigned long* relAddr=(unsigned long*)(module->loadAddr+module->sectionHeaders[ module->sectionHeaders[module->relSection].shInfo ].shOffset+reloc->addr); 
     87                unsigned long* relAddr=(unsigned long*)(module->loadAddr+module->sectionHeaders[ module->sectionHeaders[sec].shInfo ].shOffset+reloc->addr); 
    8688                int symTabIdx=ELF_R_SYM(reloc->info); 
    8789                struct ElfSymbol* symbol=&module->symTable[symTabIdx]; 
     
    146148                        module->textAddr=loadAddr+sectionHeaders[i].shOffset; 
    147149 
    148                 if (sectionHeaders[i].shType == SEC_TYPE_REL) 
    149                 { 
    150                         if (!module->relTable) 
    151                                 module->relTable=(struct ElfReloc*)(loadAddr+sectionHeaders[i].shOffset); 
    152                         module->relSize+=sectionHeaders[i].shSize; 
    153  
    154                         if (!module->relSection) 
    155                                 module->relSection=i; 
    156                 } 
    157  
    158150                /* Save the symbol table off for resolving later. */ 
    159151                if (sectionHeaders[i].shType == SEC_TYPE_SYMTAB) 
     152 
    160153                { 
    161154                        module->symTable=loadAddr+sectionHeaders[i].shOffset; 
     
    167160        } 
    168161 
    169         /* Resolve entries in the module file. */ 
    170         if (ModuleSymbolResolve(module) < 0) 
    171                 return -EINVAL; 
     162        for (i=0; i<elfHeader->shEntries; i++) 
     163        { 
     164                if (sectionHeaders[i].shType == SEC_TYPE_REL) 
     165                        /* Resolve entries in the module file. */ 
     166                        if (ModuleSymbolResolve(module, i) < 0) 
     167                                return -EINVAL; 
     168        } 
    172169 
    173170        /* Find the init and exit functions, using the symbol and string table addresses. */