toolsandutils/e32tools/elftools/inc/elfdll.h
changeset 0 83f4b4db085c
child 1 d4b442d23379
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #if !defined(__ELFDLL_H__)
       
    17 #define __ELFDLL_H__
       
    18 //#include <e32rom.h>
       
    19 #include "e32ldfmt.h"
       
    20 #include <tools/elfdefs.h>
       
    21 #include "elffile.h"
       
    22 
       
    23 #define DLLSYMPREFIX "#<DLL>"
       
    24 #define DLLSYMPREFIX0 "#"
       
    25 #define DLLSYMSUFFIX "#<\\DLL>"
       
    26 #define ORDBASE 16
       
    27 #define EXPORTTABLENAME "DLL##ExportTable"
       
    28 #define EXPORTTABLESIZENAME "DLL##ExportTableSize"
       
    29 
       
    30 class NamedExportSymbol;
       
    31 class OrdZeroRecord;
       
    32 struct NeededDLLsList;
       
    33 
       
    34 const TUint		KNameLookupOffsetFlag32 = 0x0001;
       
    35 
       
    36 class ELFFile::ELFDllData
       
    37         {
       
    38 public:
       
    39 	ELFFile * iElfFile;
       
    40 
       
    41 	char * iDynStrTab;
       
    42 	// bytesize of the dynamic string table
       
    43 	TInt iDynStrTabSize; 
       
    44 	Elf32_Sym * iDynSymTab;
       
    45 	// size of an entry in the dynamic symbol table
       
    46 	TInt iSymSize;
       
    47 	// the rela relocation table
       
    48 	Elf32_Rela * iRela;
       
    49 	// size of rela relocation table in bytes
       
    50 	TInt iRelaSz;
       
    51 	// size of a rela entry in bytes
       
    52 	TInt iRelaEnt;
       
    53 	// the rel relocation table
       
    54 	Elf32_Rel * iRel;
       
    55 	// size of rel relocation table in bytes
       
    56 	TInt iRelSz;
       
    57 	// size of a rel entry in bytes
       
    58 	TInt iRelEnt;
       
    59 
       
    60 	Elf32_HashTable * iHashTable;
       
    61 
       
    62 	// Exported symbols required for lookup via names.
       
    63 	NamedExportSymbol			*iNamedExportSymbolHead;
       
    64 	// Number of exported symbols - this doesn't nclude the absent symbols.
       
    65 	TInt					iNamedExportCount;
       
    66 	// header of the export symbol info table
       
    67 	E32EpocExpSymInfoHdr	iSymInfoHdr;
       
    68 	// String table size for the symbol names.
       
    69 	TUint					iSymStringTableSize;
       
    70 	TUint					iStringNameOffset;
       
    71 	
       
    72 	// Dependency list
       
    73 	// Static Dependencies - An 'import relocation' entry is required to be created 
       
    74 	// for each such record.
       
    75 	OrdZeroRecord		*iDepRecords;
       
    76 	OrdZeroRecord		*iDepRecordsTail;
       
    77 
       
    78 	// List of names obtained from DT_NEEDED entries in ELF.
       
    79 	// The order in which they appear is the order in which symbol
       
    80 	// lookup shall be followed.
       
    81 	NeededDLLsList		*iNeededDllNames;
       
    82 	NeededDLLsList		*iNeededDllNamesTail;
       
    83 	// Ordinal 0 of this binary. - A local relocation needs to be created for this
       
    84 	// record.
       
    85 
       
    86 	OrdZeroRecord		*iOrdZeroRec;		
       
    87 	TInt			iNamedLookupEnabled;
       
    88 	
       
    89 	ELFDllData(ELFFile * f);
       
    90 	~ELFDllData();
       
    91     TBool Init();
       
    92 
       
    93 	TBool ParseDllSymbol(Elf32_Sym * s, char*& dll, TUint& len, TInt& ord);
       
    94 	class DllSymbol
       
    95 		{
       
    96 	public:
       
    97 		char * iDll;
       
    98 		TUint iLen;
       
    99 		TInt iOrd;
       
   100 		Elf32_Phdr * iSegment;
       
   101 		Elf32_Rel * iRel;
       
   102 		DllSymbol * iNext;
       
   103 
       
   104 		DllSymbol(char * n, TUint l, TInt o) 
       
   105 		        : iDll(n), iLen(l), iOrd(o), iSegment(0),iRel(0),iNext(0) 
       
   106 			{}
       
   107 		~DllSymbol()
       
   108 			{ 
       
   109 			delete iNext; 
       
   110 			}
       
   111 		};
       
   112 	DllSymbol * DllSymbolP(Elf32_Sym * s);
       
   113 	TBool AddSymbol(DllSymbol * s);
       
   114 
       
   115 	class DllRec
       
   116 		{
       
   117 	public:
       
   118 	    char * iName;
       
   119 	    TUint iLen;
       
   120 	    TInt nImports;
       
   121 	    DllSymbol * iHead;
       
   122 	    DllSymbol * iTail;
       
   123 	    DllRec * iNext;
       
   124 
       
   125 		DllRec(char * n, TInt l, DllSymbol * s) :
       
   126 			iName(n), iLen(l), nImports(1), iHead(s), iTail(s), iNext(0)
       
   127 		    {}
       
   128 	    ~DllRec() 
       
   129 		    { 
       
   130 		    delete iHead; 
       
   131 		    delete iNext; 
       
   132 		    }
       
   133 	    void AddSymbol(DllSymbol * s);
       
   134 	    };
       
   135 
       
   136 	DllRec * iDllHead;
       
   137 	DllRec * iDllTail;
       
   138 
       
   139 	Elf32_Word iExportTableSymIdx;
       
   140 	Elf32_Word iExportTableSizeSymIdx;
       
   141 
       
   142 	TBool InitExportInfo();
       
   143 	TBool iImageIsDll;
       
   144 	TBool ImageIsDll() { return iImageIsDll; }
       
   145 
       
   146 	Elf32_Word FindSymbolIndex(TText * s);
       
   147 
       
   148 	TInt iNumberOfImports;
       
   149 	TInt iNumberOfExports;
       
   150 	TInt iNumberOfImportDlls;
       
   151 
       
   152 	TInt iStringTableSize;
       
   153 
       
   154 	TInt iNumberOfRelocs;
       
   155 	TInt iNumberOfCodeRelocs;
       
   156 	TInt iNumberOfDataRelocs;
       
   157 
       
   158 	TInt NumberOfImports(void);
       
   159 	TInt NumberOfExports(void);
       
   160 	TInt NumberOfImportDlls(void);
       
   161 
       
   162 	TInt NumberOfRelocs(void);
       
   163 
       
   164 	TInt NumberOfCodeRelocs() { return iNumberOfCodeRelocs; }
       
   165 	TInt NumberOfDataRelocs() { return iNumberOfDataRelocs; }
       
   166 	
       
   167 	TBool GetRelocs(Elf32_Rel **aCodeRelocs, Elf32_Rel **aDataRelocs);
       
   168 
       
   169 	TUint GetExportTableOffset(void);
       
   170 	char * CreateImportSection(TInt &aSize);
       
   171 	TBool CreateSymLookupTable();
       
   172 	TBool SetupSymbolValues();
       
   173 	TBool SetupSymbolNames();
       
   174 	void Sort(NamedExportSymbol** aDstList, NamedExportSymbol* aSrcList);
       
   175 	void MergeSort(NamedExportSymbol** aDstList, NamedExportSymbol** aSrcList);
       
   176 	void MergeSort(NamedExportSymbol** aDstList, NamedExportSymbol** aSrcList, \
       
   177 									TUint aLeft, TUint aRight);
       
   178 	TBool AddToDependency(TUint aOff);
       
   179 	TBool CreateDependency();
       
   180 	OrdZeroRecord* FindDependency(char* aName, TUint aLen);
       
   181 	DllRec * SearchImports(char *aName);
       
   182 	TInt GetLookupTblSize(){ return iSymInfoHdr.iSize;}
       
   183 	void SetLookupTblBase(TInt);
       
   184 	void GetExportSymInfoHeader(E32EpocExpSymInfoHdr& aSymInfoHdr);
       
   185 	void SetExportSymInfo();
       
   186 	TUint GetSymLookupSection(char* aBuff);
       
   187 	};
       
   188 
       
   189 // This class is used to create symbols to support named lookups.
       
   190 // 
       
   191 	class NamedExportSymbol
       
   192 	{
       
   193 	public:
       
   194 		NamedExportSymbol(char* aName, Elf32_Addr aValue);
       
   195 		~NamedExportSymbol()
       
   196 		{
       
   197 			delete iNext;
       
   198 		}
       
   199 		
       
   200 		char* Name() { return iSymbolName;}
       
   201 		void Name(char* aName) {iSymbolName = aName;}
       
   202 		
       
   203 		TUint NameOffset() {return iSymbolNameOffset;}
       
   204 		void  NameOffset(TUint aOffset) {iSymbolNameOffset = aOffset;}
       
   205 		
       
   206 		Elf32_Addr Value() { return iValue;}
       
   207 		void Value(Elf32_Addr aValue) { iValue = aValue;}
       
   208 	
       
   209 		NamedExportSymbol* Next() { return iNext;}
       
   210 		void Next(NamedExportSymbol* aNext) { iNext = aNext;}
       
   211 
       
   212 		Elf32_Rel	iReloc;	// relocation entry for the symbol address
       
   213 		TUint		iSymRelocType;  // Whether it is a code or data relocation for this symbol
       
   214 	private:
       
   215 		char*		iSymbolName;	// Symbol name
       
   216 		TInt		iSymIdx;
       
   217 		TUint		iSymbolNameOffset;// offset of name in string table.
       
   218 		Elf32_Addr	iValue;			// symbol value - this is the address of the symbol
       
   219 		NamedExportSymbol *iNext;		// next symbol
       
   220 	};
       
   221 
       
   222 // This class is used to support symbol lookup of the static dependencies by linking in their 
       
   223 // 0th ordinal.
       
   224 	class OrdZeroRecord
       
   225 	{
       
   226 	public:
       
   227 		OrdZeroRecord(char* aName): 
       
   228 			iName(aName), iNext(0){}
       
   229 		~OrdZeroRecord()
       
   230 		{
       
   231 			delete iNext;
       
   232 		}
       
   233 		char				*iName; // (linkas) name of the dependency
       
   234 		Elf32_Rel			iReloc;	// a relocation entry for the 0th ordinal of each dependency
       
   235 		OrdZeroRecord		*iNext; // next dependency
       
   236 		TUint				iOffset;
       
   237 	};
       
   238 	struct NeededDLLsList
       
   239 	{
       
   240 		NeededDLLsList(TUint aOff) : iOffset(aOff), iNext(0)
       
   241 		{}
       
   242 		~NeededDLLsList()
       
   243 		{
       
   244 			delete iNext;
       
   245 		}
       
   246 		TUint iOffset;
       
   247 		NeededDLLsList *iNext;
       
   248 	};
       
   249 
       
   250 #endif
       
   251