Changeset 3772 in CLRX


Ignore:
Timestamp:
Feb 12, 2018, 8:21:18 PM (17 months ago)
Author:
matszpk
Message:

CLRadeonExtender: Asm: First working AsmROCm with section differences.

Location:
CLRadeonExtender/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • CLRadeonExtender/trunk/CLRX/amdasm/AsmFormats.h

    r3771 r3772  
    533533    cxuint extraSectionCount;
    534534   
     535    bool good;
     536   
    535537    void restoreKcodeCurrentAllocRegs();
    536538    void saveKcodeCurrentAllocRegs();
  • CLRadeonExtender/trunk/CLRX/amdbin/ROCmBinaries.h

    r3763 r3772  
    439439   
    440440    size_t getSectionOffset(cxuint sectionId) const
    441     { return elfBinGen64->getRegionOffset(mainBuiltinSectTable[sectionId]); }
     441    { return elfBinGen64->getRegionOffset(
     442                    mainBuiltinSectTable[sectionId - ELFSECTID_START]); }
    442443   
    443444    /// set input
  • CLRadeonExtender/trunk/amdasm/AsmExpression.cpp

    r3770 r3772  
    453453    else
    454454    {
    455         const bool sectDiffsPrepared = (assembler.formatHandler != nullptr &&
    456              assembler.formatHandler->isSectionDiffsResolvable());
     455        const bool sectDiffsPrepared = assembler.sectionDiffsPrepared;
    457456       
    458457        // structure that contains relatives info: offset value and mult. of sections
     
    880879            const Array<cxuint>& rlSections  = relSpacesSects[
    881880                                sections[sectionId].relSpace];
    882             auto it = std::lower_bound(rlSections.begin(), rlSections.end(), sectionId,
    883                 [&sections](cxuint a, cxuint b)
    884                 { return sections[a].relAddress < sections[b].relAddress; });
    885             cxuint newSectionId =  (it != rlSections.end()) ? *it : rlSections.front();
     881            uint64_t valAddr = sections[sectionId].relAddress + value;
     882            auto it = std::lower_bound(rlSections.begin(), rlSections.end(), ASMSECT_ABS,
     883                [&sections,valAddr](cxuint a, cxuint b)
     884                {
     885                    uint64_t relAddr1 = a!=ASMSECT_ABS ? sections[a].relAddress : valAddr;
     886                    uint64_t relAddr2 = b!=ASMSECT_ABS ? sections[b].relAddress : valAddr;
     887                    return relAddr1 < relAddr2;
     888                });
     889            // if section address higher than current address
     890            if ((it == rlSections.end() || sections[*it].relAddress != valAddr) &&
     891                    it != rlSections.begin())
     892                --it;
     893           
     894            cxuint newSectionId = (it != rlSections.end()) ? *it : rlSections.back();
    886895            value += sections[sectionId].relAddress - sections[newSectionId].relAddress;
     896            sectionId = newSectionId;
    887897        }
    888898    }
  • CLRadeonExtender/trunk/amdasm/AsmROCmFormat.cpp

    r3771 r3772  
    118118AsmROCmHandler::AsmROCmHandler(Assembler& assembler): AsmFormatHandler(assembler),
    119119             output{}, codeSection(0), commentSection(ASMSECT_NONE),
    120              metadataSection(ASMSECT_NONE), dataSection(ASMSECT_NONE), extraSectionCount(0)
    121 {
     120             metadataSection(ASMSECT_NONE), dataSection(ASMSECT_NONE), extraSectionCount(0),
     121             good(true)
     122{
     123    sectionDiffsResolvable = true;
    122124    output.metadataInfo.initialize();
    123125    output.archMinor = output.archStepping = UINT32_MAX;
     
    273275    info.flags = 0;
    274276    // code is addressable and writeable
    275     if (info.type == AsmSectionType::CODE)
     277    if (info.type == AsmSectionType::CODE || info.type == AsmSectionType::DATA)
    276278        info.flags = ASMSECT_ADDRESSABLE | ASMSECT_WRITEABLE;
    277279    // any other section (except config) are absolute addressable and writeable
     
    22252227bool AsmROCmHandler::prepareSectionDiffsResolving()
    22262228{
    2227     return false;
    2228 }
    2229 
    2230 bool AsmROCmHandler::prepareBinary()
    2231 {
    2232     bool good = true;
     2229    good = true;
    22332230    size_t sectionsNum = sections.size();
    22342231    output.deviceType = assembler.getDeviceType();
     
    25772574    output.symbols = std::move(dataSymbols);
    25782575    if (good)
     2576    {
    25792577        binGen.reset(new ROCmBinGenerator(&output));
     2578        binGen->prepareBinaryGen();
     2579       
     2580        // add relSpacesSections
     2581        assembler.sections[codeSection].relAddress =
     2582                    binGen->getSectionOffset(ELFSECTID_TEXT);
     2583       
     2584        Array<cxuint> relSections(1 + (dataSection != ASMSECT_ABS));
     2585        cxuint relSectionId = 0;
     2586        if (dataSection != ASMSECT_ABS)
     2587        {
     2588            assembler.sections[dataSection].relAddress =
     2589                    binGen->getSectionOffset(ELFSECTID_RODATA);
     2590            relSections[relSectionId++] = dataSection;
     2591        }
     2592        relSections[relSectionId++] = codeSection;
     2593        assembler.relSpacesSections.push_back(std::move(relSections));
     2594    }
    25802595    return good;
    25812596}
    25822597
     2598bool AsmROCmHandler::prepareBinary()
     2599{
     2600    return good;
     2601}
     2602
    25832603void AsmROCmHandler::writeBinary(std::ostream& os) const
    25842604{
  • CLRadeonExtender/trunk/amdasm/Assembler.cpp

    r3766 r3772  
    6161    size = section.size;
    6262    content = section.content;
     63    relSpace = section.relSpace;
     64    relAddress = section.relAddress;
    6365   
    6466    if (section.usageHandler!=nullptr)
     
    7779    size = section.size;
    7880    content = section.content;
     81    relSpace = section.relSpace;
     82    relAddress = section.relAddress;
    7983   
    8084    if (section.usageHandler!=nullptr)
     
    16381642    {
    16391643        expr->setTarget(AsmExprTarget::symbolTarget(&symEntry));
     1644        if (expr->getSymOccursNum() == 0)
     1645            unevalExpressions.push_back(expr.get());
    16401646        symEntry.second.expression = expr.release();
    16411647        symEntry.second.regRange = symEntry.second.hasValue = false;
     
    23762382        kernels.push_back({ it->first.c_str(),  getSourcePos(pseudoOpPlace) });
    23772383        auto info = formatHandler->getSectionInfo(currentSection);
    2378         sections.push_back({ info.name, currentKernel, info.type, info.flags, 0 });
     2384        sections.push_back({ info.name, currentKernel, info.type, info.flags, 0,
     2385                    0, info.relSpace });
    23792386        currentOutPos = 0;
    23802387    }
     
    24582465            printWarning(pseudoOpPlace,
    24592466                     "Section type and flags was ignored for builtin section");
    2460         sections.push_back({ info.name, currentKernel, info.type, info.flags, align });
     2467        sections.push_back({ info.name, currentKernel, info.type, info.flags, align,
     2468                    0, info.relSpace });
    24612469        currentOutPos = 0;
    24622470    }
     
    25212529    // add first section
    25222530    auto info = formatHandler->getSectionInfo(currentSection);
    2523     sections.push_back({ info.name, currentKernel, info.type, info.flags, 0 });
     2531    sections.push_back({ info.name, currentKernel, info.type, info.flags, 0,
     2532                0, info.relSpace });
    25242533    currentOutPos = 0;
    25252534}
     
    28842893   
    28852894    if (withSectionDiffs())
     2895    {
    28862896        formatHandler->prepareSectionDiffsResolving();
     2897        sectionDiffsPrepared = true;
     2898    }
    28872899   
    28882900    resolvingRelocs = true;
     
    28902902   
    28912903    if (withSectionDiffs())
    2892         for (AsmExpression* expr: unevalExpressions)
     2904    {
     2905        resolvingRelocs = false;
     2906        for (AsmExpression*& expr: unevalExpressions)
    28932907        {
    28942908            // try to resolve unevaluated expressions
     
    28982912                resolveExprTarget(expr, value, sectionId);
    28992913            delete expr;
    2900         }
     2914            expr = nullptr;
     2915        }
     2916        resolvingRelocs = true;
     2917    }
    29012918   
    29022919    printUnresolvedSymbols(&globalScope);
  • CLRadeonExtender/trunk/amdbin/ROCmBinaries.cpp

    r3763 r3772  
    22292229             Array<cxbyte>* aPtr)
    22302230{
    2231     prepareBinaryGen();
     2231    if (elfBinGen64 == nullptr)
     2232        prepareBinaryGen();
    22322233    /****
    22332234     * prepare for write binary to output
Note: See TracChangeset for help on using the changeset viewer.