Ignore:
Timestamp:
Nov 11, 2016, 10:07:43 AM (3 years ago)
Author:
matszpk
Message:

CLRadeonExtender: ROCmBinGen: Add programheaders and elfheader. Add PHREGION_FILESTART (not supported yet).
Cosmetic changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • CLRadeonExtender/trunk/amdbin/ROCmBinaries.cpp

    r2557 r2561  
    186186  'A', 'M', 'D', 0, 'A', 'M', 'D', 'G', 'P', 'U', 0 };
    187187
     188struct AMDGPUArchValues
     189{
     190    uint32_t major;
     191    uint32_t minor;
     192    uint32_t stepping;
     193};
     194
     195static const AMDGPUArchValues amdGpuArchValuesTbl[] =
     196{
     197    { 0, 0, 0 }, // GPUDeviceType::CAPE_VERDE
     198    { 0, 0, 0 }, // GPUDeviceType::PITCAIRN
     199    { 0, 0, 0 }, // GPUDeviceType::TAHITI
     200    { 0, 0, 0 }, // GPUDeviceType::OLAND
     201    { 7, 0, 0 }, // GPUDeviceType::BONAIRE
     202    { 7, 0, 0 }, // GPUDeviceType::SPECTRE
     203    { 7, 0, 0 }, // GPUDeviceType::SPOOKY
     204    { 7, 0, 0 }, // GPUDeviceType::KALINDI
     205    { 0, 0, 0 }, // GPUDeviceType::HAINAN
     206    { 7, 0, 1 }, // GPUDeviceType::HAWAII
     207    { 8, 0, 0 }, // GPUDeviceType::ICELAND
     208    { 8, 0, 0 }, // GPUDeviceType::TONGA
     209    { 7, 0, 0 }, // GPUDeviceType::MULLINS
     210    { 8, 0, 3 }, // GPUDeviceType::FIJI
     211    { 8, 0, 1 }, // GPUDeviceType::CARRIZO
     212    { 0, 0, 0 }, // GPUDeviceType::DUMMY
     213    { 0, 0, 0 }, // GPUDeviceType::GOOSE
     214    { 0, 0, 0 }, // GPUDeviceType::HORSE
     215    { 8, 0, 1 }, // GPUDeviceType::STONEY
     216    { 8, 0, 4 }, // GPUDeviceType::ELLESMERE
     217    { 8, 0, 4 } // GPUDeviceType::BAFFIN
     218};
     219
     220
    188221void ROCmBinGenerator::generateInternal(std::ostream* osPtr, std::vector<char>* vPtr,
    189222             Array<cxbyte>* aPtr) const
    190223{
     224    const GPUArchitecture arch = getGPUArchitectureFromDeviceType(input->deviceType);
     225    if (arch == GPUArchitecture::GCN1_0)
     226        throw Exception("OpenCL 2.0 supported only for GCN1.1 or later");
     227   
     228    AMDGPUArchValues amdGpuArchValues = amdGpuArchValuesTbl[cxuint(input->deviceType)];
     229    if (input->archMinor!=UINT32_MAX)
     230        amdGpuArchValues.minor = input->archMinor;
     231    if (input->archStepping!=UINT32_MAX)
     232        amdGpuArchValues.stepping = input->archStepping;
     233   
    191234    const char* comment = "CLRX ROCmBinGenerator " CLRX_VERSION;
    192235    uint32_t commentSize = ::strlen(comment);
     
    199242    }
    200243   
    201     ElfBinaryGen64 elfBinGen64;
     244    ElfBinaryGen64 elfBinGen64({ 0U, 0U, 0x40, EV_CURRENT, ET_DYN,
     245        0xe0, EV_CURRENT, 0, 0, 0 });
    202246    // add symbols
    203247    elfBinGen64.addDynSymbol(ElfSymbol64("_DYNAMIC", 5,
     
    221265        DT_SYMTAB, DT_SYMENT, DT_STRTAB, DT_STRSZ, DT_HASH };
    222266    elfBinGen64.addDynamics(sizeof(dynTags)/sizeof(int32_t), dynTags);
    223    
    224     elfBinGen64.addNote(ElfNote{"AMD", sizeof noteDescType1, noteDescType1, 1U});
     267    // elf program headers
     268    elfBinGen64.addProgramHeader({ PT_PHDR, PF_R, 0, 1, true, 0, 0, 0 });
     269    elfBinGen64.addProgramHeader({ PT_LOAD, PF_R, PHREGION_FILESTART, 4,
     270                    true, 0, 0, 0, 0x1000 });
     271    elfBinGen64.addProgramHeader({ PT_LOAD, PF_R|PF_X, 4, 1, true, 0, 0, 0 });
     272    elfBinGen64.addProgramHeader({ PT_LOAD, PF_R|PF_W, 5, 1, true, 0, 0, 0 });
     273    elfBinGen64.addProgramHeader({ PT_DYNAMIC, PF_R|PF_W, 5, 1, true, 0, 0, 0, 8 });
     274    elfBinGen64.addProgramHeader({ PT_GNU_RELRO, PF_R, 5, 1, true, 0, 0, 0, 1 });
     275    elfBinGen64.addProgramHeader({ PT_GNU_STACK, PF_R|PF_W, 0, 0, true, 0, 0, 0 });
     276   
     277    // elf notes
     278    elfBinGen64.addNote({"AMD", sizeof noteDescType1, noteDescType1, 1U});
    225279    std::unique_ptr<cxbyte[]> noteBuf(new cxbyte[0x1b]);
    226280    ::memcpy(noteBuf.get(), noteDescType3, 0x1b);
    227     //SULEV(*(uint32_t*)(noteBuf.get()+4), amdGpuArchValues.major);
    228     //SULEV(*(uint32_t*)(noteBuf.get()+8), amdGpuArchValues.minor);
    229     //SULEV(*(uint32_t*)(noteBuf.get()+12), amdGpuArchValues.stepping);
    230     elfBinGen64.addNote(ElfNote{"AMD", 0x1b, noteBuf.get(), 3U});
    231    
     281    SULEV(*(uint32_t*)(noteBuf.get()+4), amdGpuArchValues.major);
     282    SULEV(*(uint32_t*)(noteBuf.get()+8), amdGpuArchValues.minor);
     283    SULEV(*(uint32_t*)(noteBuf.get()+12), amdGpuArchValues.stepping);
     284    elfBinGen64.addNote({"AMD", 0x1b, noteBuf.get(), 3U});
     285   
     286    /// region and sections
    232287    elfBinGen64.addRegion(ElfRegion64::programHeaderTable());
    233288    elfBinGen64.addRegion(ElfRegion64::dynsymSection());
Note: See TracChangeset for help on using the changeset viewer.