Changeset 2552 in CLRX


Ignore:
Timestamp:
Nov 10, 2016, 4:16:22 PM (3 years ago)
Author:
matszpk
Message:

CLRadeonExtender: Add dynamic table support to ElfBinary?.

Location:
CLRadeonExtender/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • CLRadeonExtender/trunk/CLRX/amdbin/Elf.h

    r2536 r2552  
    623623} Elf64_Dyn;
    624624
     625#define DT_NULL     0       /* Marks end of dynamic section */
     626#define DT_NEEDED   1       /* Name of needed library */
     627#define DT_PLTRELSZ 2       /* Size in bytes of PLT relocs */
     628#define DT_PLTGOT   3       /* Processor defined value */
     629#define DT_HASH     4       /* Address of symbol hash table */
     630#define DT_STRTAB   5       /* Address of string table */
     631#define DT_SYMTAB   6       /* Address of symbol table */
     632#define DT_RELA     7       /* Address of Rela relocs */
     633#define DT_RELASZ   8       /* Total size of Rela relocs */
     634#define DT_RELAENT  9       /* Size of one Rela reloc */
     635#define DT_STRSZ    10      /* Size of string table */
     636#define DT_SYMENT   11      /* Size of one symbol table entry */
     637#define DT_INIT     12      /* Address of init function */
     638#define DT_FINI     13      /* Address of termination function */
     639#define DT_SONAME   14      /* Name of shared object */
     640#define DT_RPATH    15      /* Library search path (deprecated) */
     641#define DT_SYMBOLIC 16      /* Start symbol search here */
     642#define DT_REL      17      /* Address of Rel relocs */
     643#define DT_RELSZ    18      /* Total size of Rel relocs */
     644#define DT_RELENT   19      /* Size of one Rel reloc */
     645#define DT_PLTREL   20      /* Type of reloc in PLT */
     646#define DT_DEBUG    21      /* For debugging; unspecified */
     647#define DT_TEXTREL  22      /* Reloc might modify .text */
     648#define DT_JMPREL   23      /* Address of PLT relocs */
     649#define DT_BIND_NOW 24      /* Process relocations of object */
     650#define DT_INIT_ARRAY   25      /* Array with addresses of init fct */
     651#define DT_FINI_ARRAY   26      /* Array with addresses of fini fct */
     652#define DT_INIT_ARRAYSZ 27      /* Size in bytes of DT_INIT_ARRAY */
     653#define DT_FINI_ARRAYSZ 28      /* Size in bytes of DT_FINI_ARRAY */
     654#define DT_RUNPATH  29      /* Library search path */
     655#define DT_FLAGS    30      /* Flags for the object being loaded */
     656#define DT_ENCODING 32      /* Start of encoded range */
     657#define DT_PREINIT_ARRAY 32     /* Array with addresses of preinit fct*/
     658#define DT_PREINIT_ARRAYSZ 33       /* size in bytes of DT_PREINIT_ARRAY */
     659#define DT_NUM      34      /* Number used */
     660#define DT_LOOS     0x6000000d  /* Start of OS-specific */
     661#define DT_HIOS     0x6ffff000  /* End of OS-specific */
     662#define DT_LOPROC   0x70000000  /* Start of processor-specific */
     663#define DT_HIPROC   0x7fffffff  /* End of processor-specific */
     664#define DT_PROCNUM  DT_MIPS_NUM /* Most used by any processor */
     665
    625666/* NOTE: Further definitions has been deleted from this file, because was obsolete */
    626667
  • CLRadeonExtender/trunk/CLRX/amdbin/ElfBinaries.h

    r2551 r2552  
    7171    typedef Elf32_Sym Sym;      ///< symbol header
    7272    typedef Elf32_Nhdr Nhdr;    ///< note header
     73    typedef Elf32_Dyn Dyn;      ///< dynamic entry
    7374    static const cxbyte ELFCLASS;   ///< ELF class
    7475    static const cxuint bitness;    ///< ELF bitness
     
    8889    typedef Elf64_Sym Sym;      ///< symbol header
    8990    typedef Elf64_Nhdr Nhdr;    ///< note header
     91    typedef Elf64_Dyn Dyn;      ///< dynamic entry
    9092    static const cxbyte ELFCLASS;   ///< ELF class
    9193    static const cxuint bitness;    ///< ELF bitness
     
    116118    cxbyte* dynSymTable;          ///< pointer to dynamic symbol table
    117119    cxbyte* noteTable;            ///< pointer to note table
    118     typename Types::Size noteTableSize;        ///< size of note table
     120    cxbyte* dynamicTable;         ///< pointer to dynamic table
    119121    SectionIndexMap sectionIndexMap;    ///< section's index map
    120122    SymbolIndexMap symbolIndexMap;      ///< symbol's index map
     
    123125    typename Types::Size symbolsNum;    ///< symbols number
    124126    typename Types::Size dynSymbolsNum; ///< dynamic symbols number
     127    typename Types::Size noteTableSize;        ///< size of note table
     128    typename Types::Size dynamicsNum;   ///< get dynamic entries number
    125129    uint16_t symbolEntSize; ///< symbol entry size in a symbol's table
    126130    uint16_t dynSymEntSize; ///< dynamic symbol entry size in a dynamic symbol's table
     131    typename Types::Size dynamicEntSize; ///< get dynamic entry size
    127132   
    128133public:
     
    362367    typename Types::Size getNotesSize() const
    363368    { return noteTableSize; }
     369   
     370    /// get dynamic entries number
     371    const typename Types::Size getDynamicsNum() const
     372    { return dynamicsNum; }
     373   
     374    /// get dynamic entries size
     375    const typename Types::Size getDynamicEntrySize() const
     376    { return dynamicEntSize; }
     377   
     378    /// get dynamic table
     379    const typename Types::Dyn* getDynamicTable() const
     380    { return reinterpret_cast<const typename Types::Dyn*>(dynamicTable); }
     381   
     382    /// get dynamic table
     383    typename Types::Dyn* getDynamicTable()
     384    { return reinterpret_cast<typename Types::Dyn*>(dynamicTable); }
    364385   
    365386    /// get section content pointer
  • CLRadeonExtender/trunk/amdbin/ElfBinaries.cpp

    r2551 r2552  
    7070        sectionStringTable(nullptr), symbolStringTable(nullptr),
    7171        symbolTable(nullptr), dynSymStringTable(nullptr), dynSymTable(nullptr),
    72         noteTable(nullptr), noteTableSize(0), symbolsNum(0), dynSymbolsNum(0),
    73         symbolEntSize(0), dynSymEntSize(0)
     72        noteTable(nullptr), symbolsNum(0), dynSymbolsNum(0),
     73        noteTableSize(0), dynamicsNum(0), symbolEntSize(0), dynSymEntSize(0),
     74        dynamicEntSize(0)
    7475{ }
    7576
     
    8485        sectionStringTable(nullptr), symbolStringTable(nullptr),
    8586        symbolTable(nullptr), dynSymStringTable(nullptr), dynSymTable(nullptr),
    86         noteTable(nullptr), noteTableSize(0),
    87         symbolsNum(0), dynSymbolsNum(0), symbolEntSize(0), dynSymEntSize(0)       
     87        noteTable(nullptr), symbolsNum(0), dynSymbolsNum(0),
     88        noteTableSize(0), dynamicsNum(0), symbolEntSize(0), dynSymEntSize(0),
     89        dynamicEntSize(0)     
    8890{
    8991    if (binaryCodeSize < sizeof(typename Types::Ehdr))
     
    144146        const typename Types::Shdr* dynSymTableHdr = nullptr;
    145147        const typename Types::Shdr* noteTableHdr = nullptr;
     148        const typename Types::Shdr* dynamicTableHdr = nullptr;
    146149       
    147150        cxuint shnum = ULEV(ehdr->e_shnum);
     
    179182            if (ULEV(shdr.sh_type) == SHT_NOTE)
    180183                noteTableHdr = &shdr;
     184            if (ULEV(shdr.sh_type) == SHT_DYNAMIC)
     185                dynamicTableHdr = &shdr;
    181186        }
    182187        if ((creationFlags & ELF_CREATE_SECTIONMAP) != 0)
     
    265270            noteTable = binaryCode + ULEV(noteTableHdr->sh_offset);
    266271            noteTableSize = ULEV(noteTableHdr->sh_size);
     272        }
     273        if (dynamicTableHdr != nullptr)
     274        {
     275            dynamicTable = binaryCode + ULEV(dynamicTableHdr->sh_offset);
     276            const typename Types::Size entSize = ULEV(dynamicTableHdr->sh_entsize);
     277            const typename Types::Size size = ULEV(dynamicTableHdr->sh_size);
     278            if (entSize < sizeof(typename Types::Dyn))
     279                throw Exception("Size of dynamic entry is too small!");
     280            if (size % entSize != 0)
     281                throw Exception("Size of dynamic section is not match!");
     282            dynamicsNum = entSize / size;
     283            dynamicEntSize = entSize;
    267284        }
    268285    }
Note: See TracChangeset for help on using the changeset viewer.