Exemple #1
0
void Linker::LoadFile(string inputFile)
{



    ObjectFile objectFile;

    objectFile.LoadFromFile(inputFile);

    unordered_map<string, int> sectionOffsets;

//    for (auto &section: objectFile.sections)
//    {
//        sections.insert({section.first, section.second});
//    }

    for (auto &symbol: objectFile.symbols)
    {
        if (symbol.second.symbolType == TokenType::SECTION)
        {
            //TODO: kobasica
            auto section = objectFile.sections.find(symbol.second.name);
            sections.insert({section->first, section->second});

            logFile << "Adding section symbol " << symbol.second.name << endl;
            sectionOffsets[symbol.second.name] = AddSection(symbol.second, objectFile.sections.find(symbol.second.name)->second);
        }
    }

    for (auto &symbol: objectFile.symbols)
    {
        if (symbol.second.symbolType == TokenType::LABEL)
        {
            logFile << "Adding label symbol " << symbol.second.name << endl;
            symbol.second.offset += sectionOffsets[symbol.second.sectionName];
            AddSymbol(symbol.second);
        }
    }

    for (auto &relocation: objectFile.relocations)
    {
        //TODO: error ?
        relocation.offset += sectionOffsets[relocation.section];
        relocations.push_back(relocation);
    }

}