Changeset 3791 in CLRX


Ignore:
Timestamp:
Feb 14, 2018, 2:45:24 PM (14 months ago)
Author:
matszpk
Message:

CLRadeonExtender: Asm: Resolve relocations for replaced symbols but previously with unresolvable sections.
Update AmdCL2 relocation's testcase.

Location:
CLRadeonExtender/trunk
Files:
3 edited

Legend:

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

    r3788 r3791  
    439439    bool good;
    440440    bool resolvingRelocs;
     441    bool doNotRemoveFromSymbolClones;
    441442    ISAAssembler* isaAssembler;
    442443    std::vector<DefSym> defSyms;
     
    445446    std::vector<Array<cxuint> > relSpacesSections;
    446447    std::unordered_set<AsmSymbolEntry*> symbolSnapshots;
     448    std::unordered_set<AsmSymbolEntry*> symbolClones;
    447449    std::vector<AsmExpression*> unevalExpressions;
    448450    std::vector<AsmRelocation> relocations;
     
    650652                const std::vector<cxuint>& oldKernels, cxuint codeSection);
    651653   
     654    void tryToResolveSymbol(AsmSymbolEntry& symEntry);
    652655    void tryToResolveSymbols(AsmScope* scope);
    653656    void printUnresolvedSymbols(AsmScope* scope);
  • CLRadeonExtender/trunk/amdasm/Assembler.cpp

    r3789 r3791  
    784784   
    785785    for (auto& entry: symbolSnapshots)
     786        delete entry;
     787   
     788    /// remove expressions before symbol clones
     789    for (auto& entry: symbolClones)
     790        entry->second.clearOccurrencesInExpr();
     791   
     792    for (auto& entry: symbolClones)
    786793        delete entry;
    787794   
     
    14021409{
    14031410    if (!symEntry.second.base && !symEntry.second.regRange &&
    1404         symEntry.second.expression != nullptr && (
    1405         // if symbol have unevaluated expression but we clone symbol only if
    1406         // before section diffs preparation
    1407         (symEntry.second.withUnevalExpr && !sectionDiffsPrepared) ||
    1408         // or expression have unresolved symbols
    1409                 symEntry.second.expression->getSymOccursNum()!=0) &&
     1411        ((symEntry.second.expression != nullptr && (
     1412          // if symbol have unevaluated expression but we clone symbol only if
     1413          // before section diffs preparation
     1414          (symEntry.second.withUnevalExpr && !sectionDiffsPrepared) ||
     1415          // or expression have unresolved symbols
     1416                  symEntry.second.expression->getSymOccursNum()!=0)) ||
     1417          // to resolve relocations (no expression but no have hasValue
     1418         (!resolvingRelocs &&
     1419             symEntry.second.expression == nullptr && !symEntry.second.hasValue &&
     1420             !isResolvableSection(symEntry.second.sectionId))) &&
    14101421        !symEntry.second.occurrencesInExprs.empty())
    14111422    {   // create new symbol with this expression
    1412         std::unique_ptr<AsmSymbolEntry> newSymEntry(new AsmSymbolEntry(symEntry.first,
    1413                 AsmSymbol(symEntry.second.expression, symEntry.second.onceDefined,
    1414                           symEntry.second.base)));
    1415         symEntry.second.expression->setTarget(
    1416                     AsmExprTarget::symbolTarget(newSymEntry.get()));
     1423        std::unique_ptr<AsmSymbolEntry> newSymEntry;
     1424        if (symEntry.second.expression!=nullptr)
     1425        {
     1426            newSymEntry.reset(new AsmSymbolEntry(symEntry.first,
     1427                    AsmSymbol(symEntry.second.expression, symEntry.second.onceDefined,
     1428                            symEntry.second.base)));
     1429            symEntry.second.expression->setTarget(
     1430                        AsmExprTarget::symbolTarget(newSymEntry.get()));
     1431        }
     1432        else
     1433        {
     1434            // if have unresolvable section
     1435            newSymEntry.reset(new AsmSymbolEntry(symEntry.first,
     1436                    AsmSymbol(symEntry.second.sectionId, symEntry.second.value,
     1437                              symEntry.second.onceDefined)));
     1438            newSymEntry->second.resolving = symEntry.second.resolving;
     1439            newSymEntry->second.hasValue = symEntry.second.hasValue;
     1440        }
    14171441        // replace in expression occurrences
    14181442        for (const AsmExprSymbolOccurrence& occur: symEntry.second.occurrencesInExprs)
     
    14211445        symEntry.second.occurrencesInExprs.clear();
    14221446        newSymEntry->second.detached = true;
    1423         symbolSnapshots.insert(newSymEntry.release());
     1447        symbolClones.insert(newSymEntry.release());
    14241448       
    14251449        symEntry.second.expression = nullptr;
     
    15401564            }
    15411565            // if detached (cloned symbol) while replacing value by unevaluated expression
    1542             if (entry.first!=nullptr && entry.first->second.detached)
     1566            if (!doNotRemoveFromSymbolClones &&
     1567                entry.first!=nullptr && entry.first->second.detached)
    15431568            {
    1544                 symbolSnapshots.erase(entry.first);
     1569                symbolClones.erase(entry.first);
    15451570                delete entry.first; // delete this symbol snapshot
    15461571            }
     
    26592684};
    26602685
     2686void Assembler::tryToResolveSymbol(AsmSymbolEntry& symEntry)
     2687{
     2688    if (!symEntry.second.occurrencesInExprs.empty() ||
     2689        (symEntry.first!="." &&
     2690                !isResolvableSection(symEntry.second.sectionId)))
     2691    {
     2692        // try to resolve symbols
     2693        uint64_t value;
     2694        cxuint sectionId;
     2695        if (formatHandler!=nullptr &&
     2696            formatHandler->resolveSymbol(symEntry.second, value, sectionId))
     2697            setSymbol(symEntry, value, sectionId);
     2698    }
     2699}
     2700
    26612701// try to resolve symbols in scope (after closing temporary scope or
    26622702// ending assembly for global scope)
     
    26752715            AsmScope* curScope = elem.scope.second;
    26762716            for (AsmSymbolEntry& symEntry: curScope->symbolMap)
    2677                 if (!symEntry.second.occurrencesInExprs.empty() ||
    2678                     (symEntry.first!="." &&
    2679                             !isResolvableSection(symEntry.second.sectionId)))
    2680                 {
    2681                     // try to resolve symbols
    2682                     uint64_t value;
    2683                     cxuint sectionId;
    2684                     if (formatHandler!=nullptr &&
    2685                         formatHandler->resolveSymbol(symEntry.second, value, sectionId))
    2686                         setSymbol(symEntry, value, sectionId);
    2687                 }
     2717                tryToResolveSymbol(symEntry);
    26882718        }
    26892719        // next, we travere on children
     
    27512781{
    27522782    resolvingRelocs = false;
     2783    doNotRemoveFromSymbolClones = false;
    27532784    sectionDiffsPrepared = false;
    27542785   
     
    29763007    resolvingRelocs = true;
    29773008    tryToResolveSymbols(&globalScope);
     3009    doNotRemoveFromSymbolClones = true;
     3010    for (AsmSymbolEntry* symEntry: symbolClones)
     3011        tryToResolveSymbol(*symEntry);
     3012    doNotRemoveFromSymbolClones = false;
    29783013   
    29793014    if (withSectionDiffs())
  • CLRadeonExtender/trunk/tests/amdasm/AsmAmdCL2Format.cpp

    r3755 r3791  
    594594        .int 1,2,3,4,5,6
    595595gstart2:
     596gstartx = .   # replaced later after reloc
    596597.rwdata
    597598        .int 4,5
     
    635636        .byte 12
    636637        .int (gstart+22)>>32
     638        .int (gstartx+22)>>32
    637639        s_endpgm
    638640aa = gstart2 + 100
    639641bb = aa + 3
    640 x=3*6)ffDXD",
     642x=3*6
     643gstartx = 11)ffDXD",
    641644        R"ffDXD(AmdCL2BinDump:
    642645  devType=Bonaire, aclVersion=, drvVersion=191205, compileOptions=""
     
    648651    ff0381be55555555ff0381be55555555ff0381be55555555ff0381be55555555
    649652    ff0381be55555555ff0381be55555555ff0381be55555555ff0381be55555555
    650     ff0381be555555550c55555555000081bf
     653    ff0381be555555550c5555555555555555000081bf
    651654    Config:
    652655      Arg: "_.global_offset_0", "size_t", long, void, none, 0, 0, 0, 0, 0
     
    684687    Rel: offset=164, type=1, symbol=2, addend=43
    685688    Rel: offset=169, type=2, symbol=0, addend=22
     689    Rel: offset=173, type=2, symbol=0, addend=46
    686690  GlobalData:
    687691  010000000200000003000000040000000500000006000000
Note: See TracChangeset for help on using the changeset viewer.